[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 |
|
---|
| 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
|
---|
[882] | 33 |
|
---|
| 34 | #if !defined(OS_LINUX) && !defined (__KCC__)
|
---|
| 35 | // see below for g++ on Linux
|
---|
[787] | 36 | template <class T>
|
---|
[882] | 37 | inline TArray<T> fabs(const TArray<T>& a)
|
---|
| 38 | { MathArray<T> ma; return( ma.ApplyFunction(a, fabs) ); }
|
---|
| 39 |
|
---|
| 40 | template <class T>
|
---|
| 41 | inline TArray<T> sqrt(const TArray<T>& a)
|
---|
| 42 | { MathArray<T> ma; return( ma.ApplyFunction(a, sqrt) ); }
|
---|
| 43 |
|
---|
| 44 | template <class T>
|
---|
[787] | 45 | inline TArray<T> sin(const TArray<T>& a)
|
---|
| 46 | { MathArray<T> ma; return( ma.ApplyFunction(a, sin) ); }
|
---|
| 47 |
|
---|
| 48 | template <class T>
|
---|
| 49 | inline TArray<T> cos(const TArray<T>& a)
|
---|
| 50 | { MathArray<T> ma; return( ma.ApplyFunction(a, cos) ); }
|
---|
| 51 |
|
---|
| 52 | template <class T>
|
---|
| 53 | inline TArray<T> tan(const TArray<T>& a)
|
---|
| 54 | { MathArray<T> ma; return( ma.ApplyFunction(a, tan) ); }
|
---|
| 55 |
|
---|
[804] | 56 | template <class T>
|
---|
| 57 | inline TArray<T> asin(const TArray<T>& a)
|
---|
| 58 | { MathArray<T> ma; return( ma.ApplyFunction(a, asin) ); }
|
---|
| 59 |
|
---|
| 60 | template <class T>
|
---|
| 61 | inline TArray<T> acos(const TArray<T>& a)
|
---|
| 62 | { MathArray<T> ma; return( ma.ApplyFunction(a, acos) ); }
|
---|
| 63 |
|
---|
| 64 | template <class T>
|
---|
| 65 | inline TArray<T> atan(const TArray<T>& a)
|
---|
| 66 | { MathArray<T> ma; return( ma.ApplyFunction(a, atan) ); }
|
---|
| 67 |
|
---|
| 68 | template <class T>
|
---|
| 69 | inline TArray<T> exp(const TArray<T>& a)
|
---|
| 70 | { MathArray<T> ma; return( ma.ApplyFunction(a, exp) ); }
|
---|
| 71 |
|
---|
| 72 | template <class T>
|
---|
| 73 | inline TArray<T> log(const TArray<T>& a)
|
---|
| 74 | { MathArray<T> ma; return( ma.ApplyFunction(a, log) ); }
|
---|
| 75 |
|
---|
| 76 | template <class T>
|
---|
| 77 | inline TArray<T> log10(const TArray<T>& a)
|
---|
| 78 | { MathArray<T> ma; return( ma.ApplyFunction(a, log10) ); }
|
---|
| 79 |
|
---|
[882] | 80 | #else
|
---|
| 81 | // g++ (up to 2.95.1) doesn't handle these inline template
|
---|
| 82 | // functions correctly - with math functions defined in math.h
|
---|
| 83 | #include "gcc_arrmath_pb.h"
|
---|
| 84 | #endif
|
---|
| 85 |
|
---|
[804] | 86 | template <class T>
|
---|
| 87 | inline double MeanSigma(const TArray<T>& a, double & mean, double & sig)
|
---|
| 88 | { MathArray<T> ma; return( ma.MeanSigma(a, mean, sig) ); }
|
---|
| 89 |
|
---|
| 90 | template <class T>
|
---|
| 91 | inline double Mean(const TArray<T>& a)
|
---|
| 92 | { MathArray<T> ma; double mean, sig; return( ma.MeanSigma(a, mean, sig) ); }
|
---|
| 93 |
|
---|
[787] | 94 | } // Fin du namespace
|
---|
| 95 |
|
---|
| 96 | #endif
|
---|