[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"
|
---|
| 9 | #include "tarray.h"
|
---|
| 10 | #include <math.h>
|
---|
| 11 |
|
---|
| 12 | namespace SOPHYA {
|
---|
| 13 |
|
---|
| 14 | // Class for simple mathematical operation on arrays
|
---|
| 15 | // Instanciated only for real and double (r_4, r_8) type arrays
|
---|
| 16 | // Reza 03/2000
|
---|
| 17 | template <class T>
|
---|
| 18 | class MathArray {
|
---|
| 19 | public:
|
---|
| 20 | // Applying a function
|
---|
| 21 | // Replaces the input array content with the result f(x)
|
---|
| 22 | virtual TArray<T>& ApplyFunctionInPlace(TArray<T> & a, Arr_DoubleFunctionOfX f);
|
---|
| 23 | virtual TArray<T>& ApplyFunctionInPlace(TArray<T> & a, Arr_FloatFunctionOfX f);
|
---|
| 24 | // Creates a new array and fills it with f(x)
|
---|
| 25 | virtual TArray<T> ApplyFunction(TArray<T> const & a, Arr_DoubleFunctionOfX f);
|
---|
| 26 | virtual TArray<T> ApplyFunction(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
|
---|
| 33 | template <class T>
|
---|
| 34 | inline TArray<T> sin(const TArray<T>& a)
|
---|
| 35 | { MathArray<T> ma; return( ma.ApplyFunction(a, sin) ); }
|
---|
| 36 |
|
---|
| 37 | template <class T>
|
---|
| 38 | inline TArray<T> cos(const TArray<T>& a)
|
---|
| 39 | { MathArray<T> ma; return( ma.ApplyFunction(a, cos) ); }
|
---|
| 40 |
|
---|
| 41 | template <class T>
|
---|
| 42 | inline TArray<T> tan(const TArray<T>& a)
|
---|
| 43 | { MathArray<T> ma; return( ma.ApplyFunction(a, tan) ); }
|
---|
| 44 |
|
---|
[804] | 45 | template <class T>
|
---|
| 46 | inline TArray<T> asin(const TArray<T>& a)
|
---|
| 47 | { MathArray<T> ma; return( ma.ApplyFunction(a, asin) ); }
|
---|
| 48 |
|
---|
| 49 | template <class T>
|
---|
| 50 | inline TArray<T> acos(const TArray<T>& a)
|
---|
| 51 | { MathArray<T> ma; return( ma.ApplyFunction(a, acos) ); }
|
---|
| 52 |
|
---|
| 53 | template <class T>
|
---|
| 54 | inline TArray<T> atan(const TArray<T>& a)
|
---|
| 55 | { MathArray<T> ma; return( ma.ApplyFunction(a, atan) ); }
|
---|
| 56 |
|
---|
| 57 | template <class T>
|
---|
| 58 | inline TArray<T> exp(const TArray<T>& a)
|
---|
| 59 | { MathArray<T> ma; return( ma.ApplyFunction(a, exp) ); }
|
---|
| 60 |
|
---|
| 61 | template <class T>
|
---|
| 62 | inline TArray<T> log(const TArray<T>& a)
|
---|
| 63 | { MathArray<T> ma; return( ma.ApplyFunction(a, log) ); }
|
---|
| 64 |
|
---|
| 65 | template <class T>
|
---|
| 66 | inline TArray<T> log10(const TArray<T>& a)
|
---|
| 67 | { MathArray<T> ma; return( ma.ApplyFunction(a, log10) ); }
|
---|
| 68 |
|
---|
| 69 | template <class T>
|
---|
| 70 | inline double MeanSigma(const TArray<T>& a, double & mean, double & sig)
|
---|
| 71 | { MathArray<T> ma; return( ma.MeanSigma(a, mean, sig) ); }
|
---|
| 72 |
|
---|
| 73 | template <class T>
|
---|
| 74 | inline double Mean(const TArray<T>& a)
|
---|
| 75 | { MathArray<T> ma; double mean, sig; return( ma.MeanSigma(a, mean, sig) ); }
|
---|
| 76 |
|
---|
| 77 |
|
---|
[787] | 78 | } // Fin du namespace
|
---|
| 79 |
|
---|
| 80 | #endif
|
---|