// 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& ApplyFunctionInPlaceF(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 ApplyFunctionF(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) ); } //! Class for simple mathematical operation on complex arrays template class ComplexMathArray { public: // Applying a function // Replaces the input array content with the result f(x) virtual TArray< complex >& ApplyFunctionInPlace(TArray< complex >& a, Arr_ComplexDoubleFunctionOfX f); // Creates a new array and fills it with f(x) virtual TArray< complex > ApplyFunction(TArray< complex > const & a, Arr_ComplexDoubleFunctionOfX f); // Creates a new array and fills it with f(x) virtual TArray< complex > FillFrom(TArray const & p_real, TArray const & p_imag); // Returns real-imaginary part of the complex array virtual TArray real(TArray< complex > const & a); virtual TArray imag(TArray< complex > const & a); // Returns module and phase of the complex input array virtual TArray module2(TArray< complex > const & a); virtual TArray module(TArray< complex > const & a); virtual TArray phase(TArray< complex > const & a); }; /*! \ingroup TArray \fn real(const TArray< complex >&) \brief Return the \b real part of the input complex array \b a */ template inline TArray real(const TArray< complex >& a) { ComplexMathArray cma; return( cma.real(a) ); } /*! \ingroup TArray \fn imag(const TArray< complex >&) \brief Return the \b imaginary part of the input complex array \b a */ template inline TArray imag(const TArray< complex >& a) { ComplexMathArray cma; return( cma.imag(a) ); } /*! \ingroup TArray \fn module2(const TArray< complex >&) \brief Return the \b module squared of the input complex array \b a */ template inline TArray module2(const TArray< complex >& a) { ComplexMathArray cma; return( cma.module2(a) ); } /*! \ingroup TArray \fn module(const TArray< complex >&) \brief Return the \b module of the input complex array \b a */ template inline TArray module(const TArray< complex >& a) { ComplexMathArray cma; return( cma.module(a) ); } /*! \ingroup TArray \fn phase(const TArray< complex >&) \brief Return the \b phase of the input complex array \b a */ template inline TArray phase(const TArray< complex >& a) { ComplexMathArray cma; return( cma.phase(a) ); } /*! \ingroup TArray \fn ComplexArray(const TArray &, const TArray &) \brief Return a complex array, with real and imaginary parts filled from the arguments */ template inline TArray< complex > ComplexArray(const TArray & p_real, const TArray & p_imag) { ComplexMathArray cma; return( cma.FillFrom(p_real, p_imag) ); } } // Fin du namespace #endif