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

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

documentation cmv 13/4/00

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