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

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

Compil avec g++ sous SunOS - Reza 14/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
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#if !defined(__GNUG__)
34// see below for g++
35template <class T>
36inline TArray<T> fabs(const TArray<T>& a)
37 { MathArray<T> ma; return( ma.ApplyFunction(a, fabs) ); }
38
39template <class T>
40inline TArray<T> sqrt(const TArray<T>& a)
41 { MathArray<T> ma; return( ma.ApplyFunction(a, sqrt) ); }
42
43template <class T>
44inline TArray<T> sin(const TArray<T>& a)
45 { MathArray<T> ma; return( ma.ApplyFunction(a, sin) ); }
46
47template <class T>
48inline TArray<T> cos(const TArray<T>& a)
49 { MathArray<T> ma; return( ma.ApplyFunction(a, cos) ); }
50
51template <class T>
52inline TArray<T> tan(const TArray<T>& a)
53 { MathArray<T> ma; return( ma.ApplyFunction(a, tan) ); }
54
55template <class T>
56inline TArray<T> asin(const TArray<T>& a)
57 { MathArray<T> ma; return( ma.ApplyFunction(a, asin) ); }
58
59template <class T>
60inline TArray<T> acos(const TArray<T>& a)
61 { MathArray<T> ma; return( ma.ApplyFunction(a, acos) ); }
62
63template <class T>
64inline TArray<T> atan(const TArray<T>& a)
65 { MathArray<T> ma; return( ma.ApplyFunction(a, atan) ); }
66
67template <class T>
68inline TArray<T> exp(const TArray<T>& a)
69 { MathArray<T> ma; return( ma.ApplyFunction(a, exp) ); }
70
71template <class T>
72inline TArray<T> log(const TArray<T>& a)
73 { MathArray<T> ma; return( ma.ApplyFunction(a, log) ); }
74
75template <class T>
76inline TArray<T> log10(const TArray<T>& a)
77 { MathArray<T> ma; return( ma.ApplyFunction(a, log10) ); }
78
79#else
80// g++ (up to 2.95.1) doesn't handle these inline template
81// functions correctly - with math functions defined in math.h
82#include "gcc_arrmath_pb.h"
83#endif
84
85//! Return \b mean and \b sigma of elements of array \b a
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
90//! Return \b mean of elements of array \b a
91template <class T>
92inline double Mean(const TArray<T>& a)
93 { MathArray<T> ma; double mean, sig; return( ma.MeanSigma(a, mean, sig) ); }
94
95} // Fin du namespace
96
97#endif
Note: See TracBrowser for help on using the repository browser.