// 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 // #if !defined(OS_LINUX) && !defined (__KCC__) #if !defined(__GNUG__) // 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 lof(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) ); } #else // g++ (up to 2.95.1) doesn't handle these inline template // functions correctly - with math functions defined in math.h #include "gcc_arrmath_pb.h" #endif /*! \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