source: Sophya/trunk/SophyaLib/TArray/matharr.h@ 882

Last change on this file since 882 was 882, checked in by ansari, 25 years ago

Pb compil matharr.h sur g++/linux , Reza 11/4/2000

File size: 3.0 KB
Line 
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 <math.h>
10#include "tarray.h"
11
12namespace 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
17template <class T>
18class MathArray {
19public:
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);
27 // Computing Mean-Sigma
28 virtual double MeanSigma(TArray<T> const & a, double & mean, double & sig);
29};
30
31////////////////////////////////////////////////
32// Calcul de fonctions usuelles
33
34#if !defined(OS_LINUX) && !defined (__KCC__)
35// see below for g++ on Linux
36template <class T>
37inline TArray<T> fabs(const TArray<T>& a)
38 { MathArray<T> ma; return( ma.ApplyFunction(a, fabs) ); }
39
40template <class T>
41inline TArray<T> sqrt(const TArray<T>& a)
42 { MathArray<T> ma; return( ma.ApplyFunction(a, sqrt) ); }
43
44template <class T>
45inline TArray<T> sin(const TArray<T>& a)
46 { MathArray<T> ma; return( ma.ApplyFunction(a, sin) ); }
47
48template <class T>
49inline TArray<T> cos(const TArray<T>& a)
50 { MathArray<T> ma; return( ma.ApplyFunction(a, cos) ); }
51
52template <class T>
53inline TArray<T> tan(const TArray<T>& a)
54 { MathArray<T> ma; return( ma.ApplyFunction(a, tan) ); }
55
56template <class T>
57inline TArray<T> asin(const TArray<T>& a)
58 { MathArray<T> ma; return( ma.ApplyFunction(a, asin) ); }
59
60template <class T>
61inline TArray<T> acos(const TArray<T>& a)
62 { MathArray<T> ma; return( ma.ApplyFunction(a, acos) ); }
63
64template <class T>
65inline TArray<T> atan(const TArray<T>& a)
66 { MathArray<T> ma; return( ma.ApplyFunction(a, atan) ); }
67
68template <class T>
69inline TArray<T> exp(const TArray<T>& a)
70 { MathArray<T> ma; return( ma.ApplyFunction(a, exp) ); }
71
72template <class T>
73inline TArray<T> log(const TArray<T>& a)
74 { MathArray<T> ma; return( ma.ApplyFunction(a, log) ); }
75
76template <class T>
77inline TArray<T> log10(const TArray<T>& a)
78 { MathArray<T> ma; return( ma.ApplyFunction(a, log10) ); }
79
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
86template <class T>
87inline double MeanSigma(const TArray<T>& a, double & mean, double & sig)
88 { MathArray<T> ma; return( ma.MeanSigma(a, mean, sig) ); }
89
90template <class T>
91inline double Mean(const TArray<T>& a)
92 { MathArray<T> ma; double mean, sig; return( ma.MeanSigma(a, mean, sig) ); }
93
94} // Fin du namespace
95
96#endif
Note: See TracBrowser for help on using the repository browser.