[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 |
|
---|
[3340] | 14 | //! Class for simple mathematical operation on arrays
|
---|
[787] | 15 | template <class T>
|
---|
| 16 | class MathArray {
|
---|
| 17 | public:
|
---|
[3340] | 18 | virtual ~MathArray(void) {};
|
---|
| 19 |
|
---|
| 20 | // Applying a function
|
---|
[787] | 21 | // Replaces the input array content with the result f(x)
|
---|
| 22 | virtual TArray<T>& ApplyFunctionInPlace(TArray<T> & a, Arr_DoubleFunctionOfX f);
|
---|
[2322] | 23 | virtual TArray<T>& ApplyFunctionInPlaceF(TArray<T> & a, Arr_FloatFunctionOfX f);
|
---|
[787] | 24 | // Creates a new array and fills it with f(x)
|
---|
| 25 | virtual TArray<T> ApplyFunction(TArray<T> const & a, Arr_DoubleFunctionOfX f);
|
---|
[2322] | 26 | virtual TArray<T> ApplyFunctionF(TArray<T> const & a, Arr_FloatFunctionOfX f);
|
---|
[804] | 27 | // Computing Mean-Sigma
|
---|
| 28 | virtual double MeanSigma(TArray<T> const & a, double & mean, double & sig);
|
---|
[787] | 29 | };
|
---|
| 30 |
|
---|
| 31 | ////////////////////////////////////////////////
|
---|
| 32 | // Calcul de fonctions usuelles
|
---|
[882] | 33 |
|
---|
[942] | 34 | // see below for g++
|
---|
[1226] | 35 | /*! \ingroup TArray \fn Fabs(const TArray<T>& a)
|
---|
[958] | 36 | \brief computation on TArray */
|
---|
[787] | 37 | template <class T>
|
---|
[1226] | 38 | inline TArray<T> Fabs(const TArray<T>& a)
|
---|
[882] | 39 | { MathArray<T> ma; return( ma.ApplyFunction(a, fabs) ); }
|
---|
| 40 |
|
---|
[1226] | 41 | /*! \ingroup TArray \fn Sqrt(const TArray<T>& a)
|
---|
[958] | 42 | \brief computation on TArray */
|
---|
[882] | 43 | template <class T>
|
---|
[1226] | 44 | inline TArray<T> Sqrt(const TArray<T>& a)
|
---|
[882] | 45 | { MathArray<T> ma; return( ma.ApplyFunction(a, sqrt) ); }
|
---|
| 46 |
|
---|
[1226] | 47 | /*! \ingroup TArray \fn Sin(const TArray<T>& a)
|
---|
[958] | 48 | \brief computation on TArray */
|
---|
[882] | 49 | template <class T>
|
---|
[1226] | 50 | inline TArray<T> Sin(const TArray<T>& a)
|
---|
[787] | 51 | { MathArray<T> ma; return( ma.ApplyFunction(a, sin) ); }
|
---|
| 52 |
|
---|
[1226] | 53 | /*! \ingroup TArray \fn Cos(const TArray<T>& a)
|
---|
[958] | 54 | \brief computation on TArray */
|
---|
[787] | 55 | template <class T>
|
---|
[1226] | 56 | inline TArray<T> Cos(const TArray<T>& a)
|
---|
[787] | 57 | { MathArray<T> ma; return( ma.ApplyFunction(a, cos) ); }
|
---|
| 58 |
|
---|
[958] | 59 | /*! \ingroup TArray \fn tan(const TArray<T>& a)
|
---|
| 60 | \brief computation on TArray */
|
---|
[787] | 61 | template <class T>
|
---|
[1226] | 62 | inline TArray<T> Tan(const TArray<T>& a)
|
---|
[787] | 63 | { MathArray<T> ma; return( ma.ApplyFunction(a, tan) ); }
|
---|
| 64 |
|
---|
[1226] | 65 | /*! \ingroup TArray \fn Asin(const TArray<T>& a)
|
---|
[958] | 66 | \brief computation on TArray */
|
---|
[804] | 67 | template <class T>
|
---|
[1226] | 68 | inline TArray<T> Asin(const TArray<T>& a)
|
---|
[804] | 69 | { MathArray<T> ma; return( ma.ApplyFunction(a, asin) ); }
|
---|
| 70 |
|
---|
[1226] | 71 | /*! \ingroup TArray \fn Acos(const TArray<T>& a)
|
---|
[958] | 72 | \brief computation on TArray */
|
---|
[804] | 73 | template <class T>
|
---|
[1226] | 74 | inline TArray<T> Acos(const TArray<T>& a)
|
---|
[804] | 75 | { MathArray<T> ma; return( ma.ApplyFunction(a, acos) ); }
|
---|
| 76 |
|
---|
[1226] | 77 | /*! \ingroup TArray \fn Atan(const TArray<T>& a)
|
---|
[958] | 78 | \brief computation on TArray */
|
---|
[804] | 79 | template <class T>
|
---|
[1226] | 80 | inline TArray<T> Atan(const TArray<T>& a)
|
---|
[804] | 81 | { MathArray<T> ma; return( ma.ApplyFunction(a, atan) ); }
|
---|
| 82 |
|
---|
[1226] | 83 | /*! \ingroup TArray \fn Exp(const TArray<T>& a)
|
---|
[958] | 84 | \brief computation on TArray */
|
---|
[804] | 85 | template <class T>
|
---|
[1226] | 86 | inline TArray<T> Exp(const TArray<T>& a)
|
---|
[804] | 87 | { MathArray<T> ma; return( ma.ApplyFunction(a, exp) ); }
|
---|
| 88 |
|
---|
[1226] | 89 | /*! \ingroup TArray \fn Log(const TArray<T>& a)
|
---|
[958] | 90 | \brief computation on TArray */
|
---|
[804] | 91 | template <class T>
|
---|
[1226] | 92 | inline TArray<T> Log(const TArray<T>& a)
|
---|
[804] | 93 | { MathArray<T> ma; return( ma.ApplyFunction(a, log) ); }
|
---|
| 94 |
|
---|
[1226] | 95 | /*! \ingroup TArray \fn Log10(const TArray<T>& a)
|
---|
[958] | 96 | \brief computation on TArray */
|
---|
[804] | 97 | template <class T>
|
---|
[1226] | 98 | inline TArray<T> Log10(const TArray<T>& a)
|
---|
[804] | 99 | { MathArray<T> ma; return( ma.ApplyFunction(a, log10) ); }
|
---|
| 100 |
|
---|
[882] | 101 |
|
---|
[958] | 102 | /*! \ingroup TArray \fn MeanSigma(const TArray<T>&,double&,double&)
|
---|
| 103 | \brief Return \b mean and \b sigma of elements of array \b a */
|
---|
[804] | 104 | template <class T>
|
---|
| 105 | inline double MeanSigma(const TArray<T>& a, double & mean, double & sig)
|
---|
| 106 | { MathArray<T> ma; return( ma.MeanSigma(a, mean, sig) ); }
|
---|
| 107 |
|
---|
[958] | 108 | /*! \ingroup TArray \fn Mean(const TArray<T>&)
|
---|
| 109 | \brief Return \b mean of elements of array \b a */
|
---|
[804] | 110 | template <class T>
|
---|
| 111 | inline double Mean(const TArray<T>& a)
|
---|
| 112 | { MathArray<T> ma; double mean, sig; return( ma.MeanSigma(a, mean, sig) ); }
|
---|
| 113 |
|
---|
[1517] | 114 |
|
---|
| 115 | //! Class for simple mathematical operation on complex arrays
|
---|
| 116 | template <class T>
|
---|
| 117 | class ComplexMathArray {
|
---|
| 118 | public:
|
---|
[3340] | 119 | virtual ~ComplexMathArray(void) {};
|
---|
| 120 |
|
---|
[1517] | 121 | // Applying a function
|
---|
| 122 | // Replaces the input array content with the result f(x)
|
---|
| 123 | virtual TArray< complex<T> >& ApplyFunctionInPlace(TArray< complex<T> >& a,
|
---|
| 124 | Arr_ComplexDoubleFunctionOfX f);
|
---|
| 125 | // Creates a new array and fills it with f(x)
|
---|
| 126 | virtual TArray< complex<T> > ApplyFunction(TArray< complex<T> > const & a,
|
---|
| 127 | Arr_ComplexDoubleFunctionOfX f);
|
---|
| 128 |
|
---|
| 129 | // Creates a new array and fills it with f(x)
|
---|
| 130 | virtual TArray< complex<T> > FillFrom(TArray<T> const & p_real,
|
---|
| 131 | TArray<T> const & p_imag);
|
---|
| 132 |
|
---|
| 133 | // Returns real-imaginary part of the complex array
|
---|
| 134 | virtual TArray<T> real(TArray< complex<T> > const & a);
|
---|
| 135 | virtual TArray<T> imag(TArray< complex<T> > const & a);
|
---|
| 136 |
|
---|
| 137 | // Returns module and phase of the complex input array
|
---|
| 138 | virtual TArray<T> module2(TArray< complex<T> > const & a);
|
---|
| 139 | virtual TArray<T> module(TArray< complex<T> > const & a);
|
---|
| 140 | virtual TArray<T> phase(TArray< complex<T> > const & a);
|
---|
| 141 | };
|
---|
| 142 |
|
---|
| 143 | /*! \ingroup TArray \fn real(const TArray< complex<T> >&)
|
---|
| 144 | \brief Return the \b real part of the input complex array \b a */
|
---|
| 145 | template <class T>
|
---|
| 146 | inline TArray<T> real(const TArray< complex<T> >& a)
|
---|
| 147 | { ComplexMathArray<T> cma; return( cma.real(a) ); }
|
---|
| 148 |
|
---|
| 149 | /*! \ingroup TArray \fn imag(const TArray< complex<T> >&)
|
---|
| 150 | \brief Return the \b imaginary part of the input complex array \b a */
|
---|
| 151 | template <class T>
|
---|
| 152 | inline TArray<T> imag(const TArray< complex<T> >& a)
|
---|
| 153 | { ComplexMathArray<T> cma; return( cma.imag(a) ); }
|
---|
| 154 |
|
---|
| 155 | /*! \ingroup TArray \fn module2(const TArray< complex<T> >&)
|
---|
| 156 | \brief Return the \b module squared of the input complex array \b a */
|
---|
| 157 | template <class T>
|
---|
| 158 | inline TArray<T> module2(const TArray< complex<T> >& a)
|
---|
| 159 | { ComplexMathArray<T> cma; return( cma.module2(a) ); }
|
---|
| 160 |
|
---|
| 161 | /*! \ingroup TArray \fn module(const TArray< complex<T> >&)
|
---|
| 162 | \brief Return the \b module of the input complex array \b a */
|
---|
| 163 | template <class T>
|
---|
| 164 | inline TArray<T> module(const TArray< complex<T> >& a)
|
---|
| 165 | { ComplexMathArray<T> cma; return( cma.module(a) ); }
|
---|
| 166 |
|
---|
| 167 | /*! \ingroup TArray \fn phase(const TArray< complex<T> >&)
|
---|
| 168 | \brief Return the \b phase of the input complex array \b a */
|
---|
| 169 | template <class T>
|
---|
| 170 | inline TArray<T> phase(const TArray< complex<T> >& a)
|
---|
| 171 | { ComplexMathArray<T> cma; return( cma.phase(a) ); }
|
---|
| 172 |
|
---|
| 173 | /*! \ingroup TArray \fn ComplexArray(const TArray<T> &, const TArray<T> &)
|
---|
| 174 | \brief Return a complex array, with real and imaginary parts filled from the arguments */
|
---|
| 175 | template <class T>
|
---|
| 176 | inline TArray< complex<T> > ComplexArray(const TArray<T> & p_real,
|
---|
| 177 | const TArray<T> & p_imag)
|
---|
| 178 | { ComplexMathArray<T> cma; return( cma.FillFrom(p_real, p_imag) ); }
|
---|
| 179 |
|
---|
| 180 |
|
---|
[787] | 181 | } // Fin du namespace
|
---|
| 182 |
|
---|
| 183 | #endif
|
---|