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

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

documentation cmv 12/4/00

File size: 3.1 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/*!
16 \warning Instanciated only for \b real and \b double (r_4, r_8) type arrays
17*/
18template <class T>
19class MathArray {
20public:
21// Applying a function
22 // Replaces the input array content with the result f(x)
23 virtual TArray<T>& ApplyFunctionInPlace(TArray<T> & a, Arr_DoubleFunctionOfX f);
24 virtual TArray<T>& ApplyFunctionInPlace(TArray<T> & a, Arr_FloatFunctionOfX f);
25 // Creates a new array and fills it with f(x)
26 virtual TArray<T> ApplyFunction(TArray<T> const & a, Arr_DoubleFunctionOfX f);
27 virtual TArray<T> ApplyFunction(TArray<T> const & a, Arr_FloatFunctionOfX f);
28 // Computing Mean-Sigma
29 virtual double MeanSigma(TArray<T> const & a, double & mean, double & sig);
30};
31
32////////////////////////////////////////////////
33// Calcul de fonctions usuelles
34
35#if !defined(OS_LINUX) && !defined (__KCC__)
36// see below for g++ on Linux
37template <class T>
38inline TArray<T> fabs(const TArray<T>& a)
39 { MathArray<T> ma; return( ma.ApplyFunction(a, fabs) ); }
40
41template <class T>
42inline TArray<T> sqrt(const TArray<T>& a)
43 { MathArray<T> ma; return( ma.ApplyFunction(a, sqrt) ); }
44
45template <class T>
46inline TArray<T> sin(const TArray<T>& a)
47 { MathArray<T> ma; return( ma.ApplyFunction(a, sin) ); }
48
49template <class T>
50inline TArray<T> cos(const TArray<T>& a)
51 { MathArray<T> ma; return( ma.ApplyFunction(a, cos) ); }
52
53template <class T>
54inline TArray<T> tan(const TArray<T>& a)
55 { MathArray<T> ma; return( ma.ApplyFunction(a, tan) ); }
56
57template <class T>
58inline TArray<T> asin(const TArray<T>& a)
59 { MathArray<T> ma; return( ma.ApplyFunction(a, asin) ); }
60
61template <class T>
62inline TArray<T> acos(const TArray<T>& a)
63 { MathArray<T> ma; return( ma.ApplyFunction(a, acos) ); }
64
65template <class T>
66inline TArray<T> atan(const TArray<T>& a)
67 { MathArray<T> ma; return( ma.ApplyFunction(a, atan) ); }
68
69template <class T>
70inline TArray<T> exp(const TArray<T>& a)
71 { MathArray<T> ma; return( ma.ApplyFunction(a, exp) ); }
72
73template <class T>
74inline TArray<T> log(const TArray<T>& a)
75 { MathArray<T> ma; return( ma.ApplyFunction(a, log) ); }
76
77template <class T>
78inline TArray<T> log10(const TArray<T>& a)
79 { MathArray<T> ma; return( ma.ApplyFunction(a, log10) ); }
80
81#else
82// g++ (up to 2.95.1) doesn't handle these inline template
83// functions correctly - with math functions defined in math.h
84#include "gcc_arrmath_pb.h"
85#endif
86
87//! Return \b mean and \b sigma of elements of array \b a
88template <class T>
89inline double MeanSigma(const TArray<T>& a, double & mean, double & sig)
90 { MathArray<T> ma; return( ma.MeanSigma(a, mean, sig) ); }
91
92//! Return \b mean of elements of array \b a
93template <class T>
94inline double Mean(const TArray<T>& a)
95 { MathArray<T> ma; double mean, sig; return( ma.MeanSigma(a, mean, sig) ); }
96
97} // Fin du namespace
98
99#endif
Note: See TracBrowser for help on using the repository browser.