[787] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | // Usuall mathematical functions and operations on arrays
|
---|
| 3 | // R. Ansari, C.Magneville 03/2000
|
---|
| 4 |
|
---|
| 5 | #ifndef MathArray_SEEN
|
---|
| 6 | #define MathArray_SEEN
|
---|
| 7 |
|
---|
| 8 | #include "machdefs.h"
|
---|
[882] | 9 | #include <math.h>
|
---|
[787] | 10 | #include "tarray.h"
|
---|
| 11 |
|
---|
| 12 | namespace SOPHYA {
|
---|
| 13 |
|
---|
[894] | 14 | //! Class for simple mathematical operation on arrays
|
---|
[787] | 15 | template <class T>
|
---|
| 16 | class MathArray {
|
---|
| 17 | public:
|
---|
| 18 | // Applying a function
|
---|
| 19 | // Replaces the input array content with the result f(x)
|
---|
| 20 | virtual TArray<T>& ApplyFunctionInPlace(TArray<T> & a, Arr_DoubleFunctionOfX f);
|
---|
| 21 | virtual TArray<T>& ApplyFunctionInPlace(TArray<T> & a, Arr_FloatFunctionOfX f);
|
---|
| 22 | // Creates a new array and fills it with f(x)
|
---|
| 23 | virtual TArray<T> ApplyFunction(TArray<T> const & a, Arr_DoubleFunctionOfX f);
|
---|
| 24 | virtual TArray<T> ApplyFunction(TArray<T> const & a, Arr_FloatFunctionOfX f);
|
---|
[804] | 25 | // Computing Mean-Sigma
|
---|
| 26 | virtual double MeanSigma(TArray<T> const & a, double & mean, double & sig);
|
---|
[787] | 27 | };
|
---|
| 28 |
|
---|
| 29 | ////////////////////////////////////////////////
|
---|
| 30 | // Calcul de fonctions usuelles
|
---|
[882] | 31 |
|
---|
[942] | 32 | // see below for g++
|
---|
[1226] | 33 | /*! \ingroup TArray \fn Fabs(const TArray<T>& a)
|
---|
[958] | 34 | \brief computation on TArray */
|
---|
[787] | 35 | template <class T>
|
---|
[1226] | 36 | inline TArray<T> Fabs(const TArray<T>& a)
|
---|
[882] | 37 | { MathArray<T> ma; return( ma.ApplyFunction(a, fabs) ); }
|
---|
| 38 |
|
---|
[1226] | 39 | /*! \ingroup TArray \fn Sqrt(const TArray<T>& a)
|
---|
[958] | 40 | \brief computation on TArray */
|
---|
[882] | 41 | template <class T>
|
---|
[1226] | 42 | inline TArray<T> Sqrt(const TArray<T>& a)
|
---|
[882] | 43 | { MathArray<T> ma; return( ma.ApplyFunction(a, sqrt) ); }
|
---|
| 44 |
|
---|
[1226] | 45 | /*! \ingroup TArray \fn Sin(const TArray<T>& a)
|
---|
[958] | 46 | \brief computation on TArray */
|
---|
[882] | 47 | template <class T>
|
---|
[1226] | 48 | inline TArray<T> Sin(const TArray<T>& a)
|
---|
[787] | 49 | { MathArray<T> ma; return( ma.ApplyFunction(a, sin) ); }
|
---|
| 50 |
|
---|
[1226] | 51 | /*! \ingroup TArray \fn Cos(const TArray<T>& a)
|
---|
[958] | 52 | \brief computation on TArray */
|
---|
[787] | 53 | template <class T>
|
---|
[1226] | 54 | inline TArray<T> Cos(const TArray<T>& a)
|
---|
[787] | 55 | { MathArray<T> ma; return( ma.ApplyFunction(a, cos) ); }
|
---|
| 56 |
|
---|
[958] | 57 | /*! \ingroup TArray \fn tan(const TArray<T>& a)
|
---|
| 58 | \brief computation on TArray */
|
---|
[787] | 59 | template <class T>
|
---|
[1226] | 60 | inline TArray<T> Tan(const TArray<T>& a)
|
---|
[787] | 61 | { MathArray<T> ma; return( ma.ApplyFunction(a, tan) ); }
|
---|
| 62 |
|
---|
[1226] | 63 | /*! \ingroup TArray \fn Asin(const TArray<T>& a)
|
---|
[958] | 64 | \brief computation on TArray */
|
---|
[804] | 65 | template <class T>
|
---|
[1226] | 66 | inline TArray<T> Asin(const TArray<T>& a)
|
---|
[804] | 67 | { MathArray<T> ma; return( ma.ApplyFunction(a, asin) ); }
|
---|
| 68 |
|
---|
[1226] | 69 | /*! \ingroup TArray \fn Acos(const TArray<T>& a)
|
---|
[958] | 70 | \brief computation on TArray */
|
---|
[804] | 71 | template <class T>
|
---|
[1226] | 72 | inline TArray<T> Acos(const TArray<T>& a)
|
---|
[804] | 73 | { MathArray<T> ma; return( ma.ApplyFunction(a, acos) ); }
|
---|
| 74 |
|
---|
[1226] | 75 | /*! \ingroup TArray \fn Atan(const TArray<T>& a)
|
---|
[958] | 76 | \brief computation on TArray */
|
---|
[804] | 77 | template <class T>
|
---|
[1226] | 78 | inline TArray<T> Atan(const TArray<T>& a)
|
---|
[804] | 79 | { MathArray<T> ma; return( ma.ApplyFunction(a, atan) ); }
|
---|
| 80 |
|
---|
[1226] | 81 | /*! \ingroup TArray \fn Exp(const TArray<T>& a)
|
---|
[958] | 82 | \brief computation on TArray */
|
---|
[804] | 83 | template <class T>
|
---|
[1226] | 84 | inline TArray<T> Exp(const TArray<T>& a)
|
---|
[804] | 85 | { MathArray<T> ma; return( ma.ApplyFunction(a, exp) ); }
|
---|
| 86 |
|
---|
[1226] | 87 | /*! \ingroup TArray \fn Log(const TArray<T>& a)
|
---|
[958] | 88 | \brief computation on TArray */
|
---|
[804] | 89 | template <class T>
|
---|
[1226] | 90 | inline TArray<T> Log(const TArray<T>& a)
|
---|
[804] | 91 | { MathArray<T> ma; return( ma.ApplyFunction(a, log) ); }
|
---|
| 92 |
|
---|
[1226] | 93 | /*! \ingroup TArray \fn Log10(const TArray<T>& a)
|
---|
[958] | 94 | \brief computation on TArray */
|
---|
[804] | 95 | template <class T>
|
---|
[1226] | 96 | inline TArray<T> Log10(const TArray<T>& a)
|
---|
[804] | 97 | { MathArray<T> ma; return( ma.ApplyFunction(a, log10) ); }
|
---|
| 98 |
|
---|
[882] | 99 |
|
---|
[958] | 100 | /*! \ingroup TArray \fn MeanSigma(const TArray<T>&,double&,double&)
|
---|
| 101 | \brief Return \b mean and \b sigma of elements of array \b a */
|
---|
[804] | 102 | template <class T>
|
---|
| 103 | inline double MeanSigma(const TArray<T>& a, double & mean, double & sig)
|
---|
| 104 | { MathArray<T> ma; return( ma.MeanSigma(a, mean, sig) ); }
|
---|
| 105 |
|
---|
[958] | 106 | /*! \ingroup TArray \fn Mean(const TArray<T>&)
|
---|
| 107 | \brief Return \b mean of elements of array \b a */
|
---|
[804] | 108 | template <class T>
|
---|
| 109 | inline double Mean(const TArray<T>& a)
|
---|
| 110 | { MathArray<T> ma; double mean, sig; return( ma.MeanSigma(a, mean, sig) ); }
|
---|
| 111 |
|
---|
[787] | 112 | } // Fin du namespace
|
---|
| 113 |
|
---|
| 114 | #endif
|
---|