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

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

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