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

Last change on this file since 4018 was 3340, checked in by cmv, 18 years ago

add virtual destructor for g++ >4. cmv 05/10/2007

File size: 6.5 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
[3340]14//! Class for simple mathematical operation on arrays
[787]15template <class T>
16class MathArray {
17public:
[3340]18 virtual ~MathArray(void) {};
19
20// Applying a function
[787]21 // Replaces the input array content with the result f(x)
22 virtual TArray<T>& ApplyFunctionInPlace(TArray<T> & a, Arr_DoubleFunctionOfX f);
[2322]23 virtual TArray<T>& ApplyFunctionInPlaceF(TArray<T> & a, Arr_FloatFunctionOfX f);
[787]24 // Creates a new array and fills it with f(x)
25 virtual TArray<T> ApplyFunction(TArray<T> const & a, Arr_DoubleFunctionOfX f);
[2322]26 virtual TArray<T> ApplyFunctionF(TArray<T> const & a, Arr_FloatFunctionOfX f);
[804]27 // Computing Mean-Sigma
28 virtual double MeanSigma(TArray<T> const & a, double & mean, double & sig);
[787]29};
30
31////////////////////////////////////////////////
32// Calcul de fonctions usuelles
[882]33
[942]34// see below for g++
[1226]35/*! \ingroup TArray \fn Fabs(const TArray<T>& a)
[958]36 \brief computation on TArray */
[787]37template <class T>
[1226]38inline TArray<T> Fabs(const TArray<T>& a)
[882]39 { MathArray<T> ma; return( ma.ApplyFunction(a, fabs) ); }
40
[1226]41/*! \ingroup TArray \fn Sqrt(const TArray<T>& a)
[958]42 \brief computation on TArray */
[882]43template <class T>
[1226]44inline TArray<T> Sqrt(const TArray<T>& a)
[882]45 { MathArray<T> ma; return( ma.ApplyFunction(a, sqrt) ); }
46
[1226]47/*! \ingroup TArray \fn Sin(const TArray<T>& a)
[958]48 \brief computation on TArray */
[882]49template <class T>
[1226]50inline TArray<T> Sin(const TArray<T>& a)
[787]51 { MathArray<T> ma; return( ma.ApplyFunction(a, sin) ); }
52
[1226]53/*! \ingroup TArray \fn Cos(const TArray<T>& a)
[958]54 \brief computation on TArray */
[787]55template <class T>
[1226]56inline TArray<T> Cos(const TArray<T>& a)
[787]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>
[1226]62inline TArray<T> Tan(const TArray<T>& a)
[787]63 { MathArray<T> ma; return( ma.ApplyFunction(a, tan) ); }
64
[1226]65/*! \ingroup TArray \fn Asin(const TArray<T>& a)
[958]66 \brief computation on TArray */
[804]67template <class T>
[1226]68inline TArray<T> Asin(const TArray<T>& a)
[804]69 { MathArray<T> ma; return( ma.ApplyFunction(a, asin) ); }
70
[1226]71/*! \ingroup TArray \fn Acos(const TArray<T>& a)
[958]72 \brief computation on TArray */
[804]73template <class T>
[1226]74inline TArray<T> Acos(const TArray<T>& a)
[804]75 { MathArray<T> ma; return( ma.ApplyFunction(a, acos) ); }
76
[1226]77/*! \ingroup TArray \fn Atan(const TArray<T>& a)
[958]78 \brief computation on TArray */
[804]79template <class T>
[1226]80inline TArray<T> Atan(const TArray<T>& a)
[804]81 { MathArray<T> ma; return( ma.ApplyFunction(a, atan) ); }
82
[1226]83/*! \ingroup TArray \fn Exp(const TArray<T>& a)
[958]84 \brief computation on TArray */
[804]85template <class T>
[1226]86inline TArray<T> Exp(const TArray<T>& a)
[804]87 { MathArray<T> ma; return( ma.ApplyFunction(a, exp) ); }
88
[1226]89/*! \ingroup TArray \fn Log(const TArray<T>& a)
[958]90 \brief computation on TArray */
[804]91template <class T>
[1226]92inline TArray<T> Log(const TArray<T>& a)
[804]93 { MathArray<T> ma; return( ma.ApplyFunction(a, log) ); }
94
[1226]95/*! \ingroup TArray \fn Log10(const TArray<T>& a)
[958]96 \brief computation on TArray */
[804]97template <class T>
[1226]98inline TArray<T> Log10(const TArray<T>& a)
[804]99 { MathArray<T> ma; return( ma.ApplyFunction(a, log10) ); }
100
[882]101
[958]102/*! \ingroup TArray \fn MeanSigma(const TArray<T>&,double&,double&)
103 \brief Return \b mean and \b sigma of elements of array \b a */
[804]104template <class T>
105inline double MeanSigma(const TArray<T>& a, double & mean, double & sig)
106 { MathArray<T> ma; return( ma.MeanSigma(a, mean, sig) ); }
107
[958]108/*! \ingroup TArray \fn Mean(const TArray<T>&)
109 \brief Return \b mean of elements of array \b a */
[804]110template <class T>
111inline double Mean(const TArray<T>& a)
112 { MathArray<T> ma; double mean, sig; return( ma.MeanSigma(a, mean, sig) ); }
113
[1517]114
115//! Class for simple mathematical operation on complex arrays
116template <class T>
117class ComplexMathArray {
118public:
[3340]119 virtual ~ComplexMathArray(void) {};
120
[1517]121// Applying a function
122 // Replaces the input array content with the result f(x)
123 virtual TArray< complex<T> >& ApplyFunctionInPlace(TArray< complex<T> >& a,
124 Arr_ComplexDoubleFunctionOfX f);
125 // Creates a new array and fills it with f(x)
126 virtual TArray< complex<T> > ApplyFunction(TArray< complex<T> > const & a,
127 Arr_ComplexDoubleFunctionOfX f);
128
129 // Creates a new array and fills it with f(x)
130 virtual TArray< complex<T> > FillFrom(TArray<T> const & p_real,
131 TArray<T> const & p_imag);
132
133 // Returns real-imaginary part of the complex array
134 virtual TArray<T> real(TArray< complex<T> > const & a);
135 virtual TArray<T> imag(TArray< complex<T> > const & a);
136
137 // Returns module and phase of the complex input array
138 virtual TArray<T> module2(TArray< complex<T> > const & a);
139 virtual TArray<T> module(TArray< complex<T> > const & a);
140 virtual TArray<T> phase(TArray< complex<T> > const & a);
141};
142
143/*! \ingroup TArray \fn real(const TArray< complex<T> >&)
144 \brief Return the \b real part of the input complex array \b a */
145template <class T>
146inline TArray<T> real(const TArray< complex<T> >& a)
147 { ComplexMathArray<T> cma; return( cma.real(a) ); }
148
149/*! \ingroup TArray \fn imag(const TArray< complex<T> >&)
150 \brief Return the \b imaginary part of the input complex array \b a */
151template <class T>
152inline TArray<T> imag(const TArray< complex<T> >& a)
153 { ComplexMathArray<T> cma; return( cma.imag(a) ); }
154
155/*! \ingroup TArray \fn module2(const TArray< complex<T> >&)
156 \brief Return the \b module squared of the input complex array \b a */
157template <class T>
158inline TArray<T> module2(const TArray< complex<T> >& a)
159 { ComplexMathArray<T> cma; return( cma.module2(a) ); }
160
161/*! \ingroup TArray \fn module(const TArray< complex<T> >&)
162 \brief Return the \b module of the input complex array \b a */
163template <class T>
164inline TArray<T> module(const TArray< complex<T> >& a)
165 { ComplexMathArray<T> cma; return( cma.module(a) ); }
166
167/*! \ingroup TArray \fn phase(const TArray< complex<T> >&)
168 \brief Return the \b phase of the input complex array \b a */
169template <class T>
170inline TArray<T> phase(const TArray< complex<T> >& a)
171 { ComplexMathArray<T> cma; return( cma.phase(a) ); }
172
173/*! \ingroup TArray \fn ComplexArray(const TArray<T> &, const TArray<T> &)
174 \brief Return a complex array, with real and imaginary parts filled from the arguments */
175template <class T>
176inline TArray< complex<T> > ComplexArray(const TArray<T> & p_real,
177 const TArray<T> & p_imag)
178 { ComplexMathArray<T> cma; return( cma.FillFrom(p_real, p_imag) ); }
179
180
[787]181} // Fin du namespace
182
183#endif
Note: See TracBrowser for help on using the repository browser.