// This may look like C code, but it is really -*- C++ -*- // Usuall mathematical functions and operations on arrays // R. Ansari, C.Magneville 03/2000 #ifndef MathArray_SEEN #define MathArray_SEEN #include "machdefs.h" #include #include "tarray.h" namespace SOPHYA { //! Class for simple mathematical operation on arrays template class MathArray { public: // Applying a function // Replaces the input array content with the result f(x) virtual TArray& ApplyFunctionInPlace(TArray & a, Arr_DoubleFunctionOfX f); virtual TArray& ApplyFunctionInPlace(TArray & a, Arr_FloatFunctionOfX f); // Creates a new array and fills it with f(x) virtual TArray ApplyFunction(TArray const & a, Arr_DoubleFunctionOfX f); virtual TArray ApplyFunction(TArray const & a, Arr_FloatFunctionOfX f); // Computing Mean-Sigma virtual double MeanSigma(TArray const & a, double & mean, double & sig); }; //////////////////////////////////////////////// // Calcul de fonctions usuelles // see below for g++ /*! \ingroup TArray \fn Fabs(const TArray& a) \brief computation on TArray */ template inline TArray Fabs(const TArray& a) { MathArray ma; return( ma.ApplyFunction(a, fabs) ); } /*! \ingroup TArray \fn Sqrt(const TArray& a) \brief computation on TArray */ template inline TArray Sqrt(const TArray& a) { MathArray ma; return( ma.ApplyFunction(a, sqrt) ); } /*! \ingroup TArray \fn Sin(const TArray& a) \brief computation on TArray */ template inline TArray Sin(const TArray& a) { MathArray ma; return( ma.ApplyFunction(a, sin) ); } /*! \ingroup TArray \fn Cos(const TArray& a) \brief computation on TArray */ template inline TArray Cos(const TArray& a) { MathArray ma; return( ma.ApplyFunction(a, cos) ); } /*! \ingroup TArray \fn tan(const TArray& a) \brief computation on TArray */ template inline TArray Tan(const TArray& a) { MathArray ma; return( ma.ApplyFunction(a, tan) ); } /*! \ingroup TArray \fn Asin(const TArray& a) \brief computation on TArray */ template inline TArray Asin(const TArray& a) { MathArray ma; return( ma.ApplyFunction(a, asin) ); } /*! \ingroup TArray \fn Acos(const TArray& a) \brief computation on TArray */ template inline TArray Acos(const TArray& a) { MathArray ma; return( ma.ApplyFunction(a, acos) ); } /*! \ingroup TArray \fn Atan(const TArray& a) \brief computation on TArray */ template inline TArray Atan(const TArray& a) { MathArray ma; return( ma.ApplyFunction(a, atan) ); } /*! \ingroup TArray \fn Exp(const TArray& a) \brief computation on TArray */ template inline TArray Exp(const TArray& a) { MathArray ma; return( ma.ApplyFunction(a, exp) ); } /*! \ingroup TArray \fn Log(const TArray& a) \brief computation on TArray */ template inline TArray Log(const TArray& a) { MathArray ma; return( ma.ApplyFunction(a, log) ); } /*! \ingroup TArray \fn Log10(const TArray& a) \brief computation on TArray */ template inline TArray Log10(const TArray& a) { MathArray ma; return( ma.ApplyFunction(a, log10) ); } /*! \ingroup TArray \fn MeanSigma(const TArray&,double&,double&) \brief Return \b mean and \b sigma of elements of array \b a */ template inline double MeanSigma(const TArray& a, double & mean, double & sig) { MathArray ma; return( ma.MeanSigma(a, mean, sig) ); } /*! \ingroup TArray \fn Mean(const TArray&) \brief Return \b mean of elements of array \b a */ template inline double Mean(const TArray& a) { MathArray ma; double mean, sig; return( ma.MeanSigma(a, mean, sig) ); } } // Fin du namespace #endif