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

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

doc + vire warning cmv 18/04/00

File size: 4.1 KB
RevLine 
[787]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"
[882]9#include <math.h>
[787]10#include "tarray.h"
11
12namespace SOPHYA {
13
[894]14//! Class for simple mathematical operation on arrays
[787]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);
[804]25 // Computing Mean-Sigma
26 virtual double MeanSigma(TArray<T> const & a, double & mean, double & sig);
[787]27};
28
29////////////////////////////////////////////////
30// Calcul de fonctions usuelles
[882]31
[942]32 // #if !defined(OS_LINUX) && !defined (__KCC__)
33#if !defined(__GNUG__)
34// see below for g++
[958]35/*! \ingroup TArray \fn fabs(const TArray<T>& a)
36 \brief computation on TArray */
[787]37template <class T>
[882]38inline TArray<T> fabs(const TArray<T>& a)
39 { MathArray<T> ma; return( ma.ApplyFunction(a, fabs) ); }
40
[958]41/*! \ingroup TArray \fn sqrt(const TArray<T>& a)
42 \brief computation on TArray */
[882]43template <class T>
44inline TArray<T> sqrt(const TArray<T>& a)
45 { MathArray<T> ma; return( ma.ApplyFunction(a, sqrt) ); }
46
[958]47/*! \ingroup TArray \fn sin(const TArray<T>& a)
48 \brief computation on TArray */
[882]49template <class T>
[787]50inline TArray<T> sin(const TArray<T>& a)
51 { MathArray<T> ma; return( ma.ApplyFunction(a, sin) ); }
52
[958]53/*! \ingroup TArray \fn cos(const TArray<T>& a)
54 \brief computation on TArray */
[787]55template <class T>
56inline TArray<T> cos(const TArray<T>& a)
57 { MathArray<T> ma; return( ma.ApplyFunction(a, cos) ); }
58
[958]59/*! \ingroup TArray \fn tan(const TArray<T>& a)
60 \brief computation on TArray */
[787]61template <class T>
62inline TArray<T> tan(const TArray<T>& a)
63 { MathArray<T> ma; return( ma.ApplyFunction(a, tan) ); }
64
[958]65/*! \ingroup TArray \fn asin(const TArray<T>& a)
66 \brief computation on TArray */
[804]67template <class T>
68inline TArray<T> asin(const TArray<T>& a)
69 { MathArray<T> ma; return( ma.ApplyFunction(a, asin) ); }
70
[958]71/*! \ingroup TArray \fn acos(const TArray<T>& a)
72 \brief computation on TArray */
[804]73template <class T>
74inline TArray<T> acos(const TArray<T>& a)
75 { MathArray<T> ma; return( ma.ApplyFunction(a, acos) ); }
76
[958]77/*! \ingroup TArray \fn atan(const TArray<T>& a)
78 \brief computation on TArray */
[804]79template <class T>
80inline TArray<T> atan(const TArray<T>& a)
81 { MathArray<T> ma; return( ma.ApplyFunction(a, atan) ); }
82
[958]83/*! \ingroup TArray \fn exp(const TArray<T>& a)
84 \brief computation on TArray */
[804]85template <class T>
86inline TArray<T> exp(const TArray<T>& a)
87 { MathArray<T> ma; return( ma.ApplyFunction(a, exp) ); }
88
[958]89/*! \ingroup TArray \fn lof(const TArray<T>& a)
90 \brief computation on TArray */
[804]91template <class T>
92inline TArray<T> log(const TArray<T>& a)
93 { MathArray<T> ma; return( ma.ApplyFunction(a, log) ); }
94
[958]95/*! \ingroup TArray \fn log10(const TArray<T>& a)
96 \brief computation on TArray */
[804]97template <class T>
98inline TArray<T> log10(const TArray<T>& a)
99 { MathArray<T> ma; return( ma.ApplyFunction(a, log10) ); }
100
[882]101#else
102// g++ (up to 2.95.1) doesn't handle these inline template
103// functions correctly - with math functions defined in math.h
104#include "gcc_arrmath_pb.h"
105#endif
106
[958]107/*! \ingroup TArray \fn MeanSigma(const TArray<T>&,double&,double&)
108 \brief Return \b mean and \b sigma of elements of array \b a */
[804]109template <class T>
110inline double MeanSigma(const TArray<T>& a, double & mean, double & sig)
111 { MathArray<T> ma; return( ma.MeanSigma(a, mean, sig) ); }
112
[958]113/*! \ingroup TArray \fn Mean(const TArray<T>&)
114 \brief Return \b mean of elements of array \b a */
[804]115template <class T>
116inline double Mean(const TArray<T>& a)
117 { MathArray<T> ma; double mean, sig; return( ma.MeanSigma(a, mean, sig) ); }
118
[787]119} // Fin du namespace
120
121#endif
Note: See TracBrowser for help on using the repository browser.