| [785] | 1 | // This may look like C code, but it is really -*- C++ -*- | 
|---|
|  | 2 | //     Utility classes for template numerical arrays | 
|---|
|  | 3 | //                     R. Ansari, C.Magneville   03/2000 | 
|---|
|  | 4 |  | 
|---|
|  | 5 | #ifndef UtilArray_SEEN | 
|---|
|  | 6 | #define UtilArray_SEEN | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #include "machdefs.h" | 
|---|
|  | 9 | #include <stdlib.h> | 
|---|
|  | 10 |  | 
|---|
|  | 11 | namespace SOPHYA { | 
|---|
|  | 12 |  | 
|---|
|  | 13 | /* Quelques utilitaires pour les tableaux (Array) */ | 
|---|
|  | 14 |  | 
|---|
| [956] | 15 | /*! \ingroup TArray | 
|---|
|  | 16 | \typedef Arr_DoubleFunctionOfX | 
|---|
|  | 17 | \brief define a function of float which returns a double | 
|---|
|  | 18 | */ | 
|---|
| [785] | 19 | typedef double (* Arr_DoubleFunctionOfX) (double x); | 
|---|
| [956] | 20 | /*! \ingroup TArray | 
|---|
|  | 21 | \typedef Arr_FloatFunctionOfX | 
|---|
|  | 22 | \brief define a function of float which returns a double | 
|---|
|  | 23 | */ | 
|---|
| [785] | 24 | typedef float  (* Arr_FloatFunctionOfX)  (float x); | 
|---|
|  | 25 |  | 
|---|
| [894] | 26 | ////////////////////////////////////////////////////////// | 
|---|
|  | 27 | //! Class to generate a random sequence of values | 
|---|
| [850] | 28 | class RandomSequence { | 
|---|
|  | 29 | public: | 
|---|
| [894] | 30 | //! to define the generator type | 
|---|
|  | 31 | enum { | 
|---|
|  | 32 | Gaussian = 0, //!< gaussian generator | 
|---|
|  | 33 | Flat = 1      //!< Flat generator | 
|---|
|  | 34 | }; | 
|---|
|  | 35 |  | 
|---|
| [850] | 36 | RandomSequence(int typ = RandomSequence::Gaussian, double m=0., double s=1.); | 
|---|
|  | 37 | double Rand(); | 
|---|
|  | 38 | protected: | 
|---|
| [894] | 39 | int typ_;            //!< random generation type | 
|---|
|  | 40 | double mean_, sig_;  //!< generation parameters mean and sigma (if needed) | 
|---|
| [850] | 41 | }; | 
|---|
|  | 42 |  | 
|---|
|  | 43 |  | 
|---|
| [894] | 44 | ////////////////////////////////////////////////////////// | 
|---|
|  | 45 | //! Class to generate a sequence of values | 
|---|
| [785] | 46 | class Sequence { | 
|---|
|  | 47 | public: | 
|---|
| [804] | 48 | explicit Sequence (double start=0., double step=1., Arr_DoubleFunctionOfX f=NULL); | 
|---|
| [850] | 49 | explicit Sequence (RandomSequence rseq); | 
|---|
| [894] | 50 |  | 
|---|
|  | 51 | //! return start value of the sequence | 
|---|
| [785] | 52 | inline double & Start() { return start_; } | 
|---|
| [894] | 53 | //! return step value of the sequence | 
|---|
| [785] | 54 | inline double & Step() { return step_; } | 
|---|
|  | 55 | double operator () (uint_4 k); | 
|---|
|  | 56 | protected: | 
|---|
| [894] | 57 | double start_;              //!< start value of the sequence | 
|---|
|  | 58 | double step_;               //!< step value of the sequence | 
|---|
|  | 59 | Arr_DoubleFunctionOfX myf_; //!< pointer to the sequence function | 
|---|
|  | 60 | bool fgrseq_;               //!< true if RandomSequence is used | 
|---|
|  | 61 | RandomSequence rseq_;       //!< RandomSequence | 
|---|
| [785] | 62 | }; | 
|---|
|  | 63 |  | 
|---|
| [894] | 64 | ////////////////////////////////////////////////////////// | 
|---|
|  | 65 | //! Class to define a range of indexes | 
|---|
| [785] | 66 | class Range { | 
|---|
|  | 67 | public: | 
|---|
| [813] | 68 | explicit Range(uint_4 start=0, uint_4 end=0, uint_4 size=1, uint_4 step=1); | 
|---|
| [894] | 69 | //! Return the start index | 
|---|
| [785] | 70 | inline uint_4 & Start()  {  return start_; } | 
|---|
| [894] | 71 | //! Return the last index | 
|---|
| [813] | 72 | inline uint_4 & End()    {  return end_; } | 
|---|
| [894] | 73 | //! Return the size | 
|---|
| [813] | 74 | inline uint_4 & Size()   {  return size_; } | 
|---|
| [894] | 75 | //! Return the step | 
|---|
| [813] | 76 | inline uint_4 & Step()   {  return step_; } | 
|---|
| [785] | 77 | protected: | 
|---|
| [894] | 78 | uint_4 start_; //!< start index | 
|---|
|  | 79 | uint_4 end_;   //!< end index | 
|---|
|  | 80 | uint_4 size_;  //!< size | 
|---|
|  | 81 | uint_4 step_;  //!< step | 
|---|
| [785] | 82 | }; | 
|---|
|  | 83 |  | 
|---|
| [894] | 84 | ////////////////////////////////////////////////////////// | 
|---|
|  | 85 | //! Class to define an identity matrix | 
|---|
| [804] | 86 | class IdentityMatrix { | 
|---|
|  | 87 | public: | 
|---|
|  | 88 | explicit IdentityMatrix(double diag=1., uint_4 n=0); | 
|---|
| [894] | 89 | //! return the size of the identity matrix | 
|---|
| [804] | 90 | inline uint_4 Size() { return size_; } | 
|---|
| [894] | 91 | //! return the value of the diagonal elements | 
|---|
| [804] | 92 | inline double Diag() { return diag_; } | 
|---|
|  | 93 | protected: | 
|---|
| [894] | 94 | uint_4 size_; //!< size of the matrix | 
|---|
|  | 95 | double diag_; //!< value of the diagonal elements | 
|---|
| [804] | 96 | }; | 
|---|
|  | 97 |  | 
|---|
| [785] | 98 | } // Fin du namespace | 
|---|
|  | 99 |  | 
|---|
|  | 100 | #endif | 
|---|