| 
            Last change
 on this file since 799 was             787, checked in by ansari, 26 years ago           | 
        
        
          
            
Introduction de BaseArray comme classe parente de TArray<T> 
Separation des operations math (fonctions) ds la classe MathArr<T> 
 
Reza 20/3/2000 
 
 
 
           | 
        
        
          | 
            File size:
            1.4 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 "tarray.h"
 | 
|---|
| 10 | #include <math.h>
 | 
|---|
| 11 | 
 | 
|---|
| 12 | namespace SOPHYA {
 | 
|---|
| 13 | 
 | 
|---|
| 14 | //       Class for simple mathematical operation on arrays 
 | 
|---|
| 15 | //   Instanciated only for real and double (r_4, r_8) type arrays 
 | 
|---|
| 16 | //                                                Reza 03/2000
 | 
|---|
| 17 | template <class T>
 | 
|---|
| 18 | class MathArray {
 | 
|---|
| 19 | public:
 | 
|---|
| 20 | // Applying a function 
 | 
|---|
| 21 |   // Replaces the input array content with the result f(x)
 | 
|---|
| 22 |   virtual TArray<T>&  ApplyFunctionInPlace(TArray<T> & a, Arr_DoubleFunctionOfX f);
 | 
|---|
| 23 |   virtual TArray<T>&  ApplyFunctionInPlace(TArray<T> & a, Arr_FloatFunctionOfX f);
 | 
|---|
| 24 |   // Creates a new array and fills it with f(x)
 | 
|---|
| 25 |   virtual TArray<T>  ApplyFunction(TArray<T> const & a, Arr_DoubleFunctionOfX f);
 | 
|---|
| 26 |   virtual TArray<T>  ApplyFunction(TArray<T> const & a, Arr_FloatFunctionOfX f);
 | 
|---|
| 27 | };
 | 
|---|
| 28 | 
 | 
|---|
| 29 | ////////////////////////////////////////////////
 | 
|---|
| 30 | //  Calcul de fonctions usuelles 
 | 
|---|
| 31 | template <class T>
 | 
|---|
| 32 | inline TArray<T> sin(const TArray<T>& a)
 | 
|---|
| 33 |   { MathArray<T> ma;   return( ma.ApplyFunction(a, sin) ); }
 | 
|---|
| 34 | 
 | 
|---|
| 35 | template <class T>
 | 
|---|
| 36 | inline TArray<T> cos(const TArray<T>& a)
 | 
|---|
| 37 |   { MathArray<T> ma;   return( ma.ApplyFunction(a, cos) ); }
 | 
|---|
| 38 | 
 | 
|---|
| 39 | template <class T>
 | 
|---|
| 40 | inline TArray<T> tan(const TArray<T>& a)
 | 
|---|
| 41 |   { MathArray<T> ma;   return( ma.ApplyFunction(a, tan) ); }
 | 
|---|
| 42 | 
 | 
|---|
| 43 | } // Fin du namespace
 | 
|---|
| 44 | 
 | 
|---|
| 45 | #endif
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.