| 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 "mutyv.h"
|
|---|
| 10 |
|
|---|
| 11 | #include <stdlib.h>
|
|---|
| 12 | #include <vector>
|
|---|
| 13 |
|
|---|
| 14 | namespace SOPHYA {
|
|---|
| 15 |
|
|---|
| 16 | /* Quelques utilitaires pour les tableaux (Array) */
|
|---|
| 17 |
|
|---|
| 18 | /*! \ingroup TArray
|
|---|
| 19 | \typedef Arr_DoubleFunctionOfX
|
|---|
| 20 | \brief define a function of float which returns a double
|
|---|
| 21 | */
|
|---|
| 22 | typedef double (* Arr_DoubleFunctionOfX) (double x);
|
|---|
| 23 | /*! \ingroup TArray
|
|---|
| 24 | \typedef Arr_FloatFunctionOfX
|
|---|
| 25 | \brief define a function of float which returns a double
|
|---|
| 26 | */
|
|---|
| 27 | typedef float (* Arr_FloatFunctionOfX) (float x);
|
|---|
| 28 |
|
|---|
| 29 | //////////////////////////////////////////////////////////
|
|---|
| 30 | //! Class to generate a random sequence of values
|
|---|
| 31 | class Sequence {
|
|---|
| 32 | public:
|
|---|
| 33 | virtual ~Sequence();
|
|---|
| 34 | virtual MuTyV & Value(uint_8 k) const = 0;
|
|---|
| 35 | inline MuTyV & operator () (uint_8 k) const { return(Value(k)) ; }
|
|---|
| 36 | };
|
|---|
| 37 |
|
|---|
| 38 | class RandomSequence : public Sequence {
|
|---|
| 39 | public:
|
|---|
| 40 | //! to define the generator type
|
|---|
| 41 | enum {
|
|---|
| 42 | Gaussian = 0, //!< gaussian generator
|
|---|
| 43 | Flat = 1 //!< Flat generator
|
|---|
| 44 | };
|
|---|
| 45 |
|
|---|
| 46 | explicit RandomSequence(int typ = RandomSequence::Gaussian, double m=0., double s=1.);
|
|---|
| 47 | virtual ~RandomSequence();
|
|---|
| 48 | virtual MuTyV & Value(uint_8 k) const ;
|
|---|
| 49 | double Rand();
|
|---|
| 50 |
|
|---|
| 51 | protected:
|
|---|
| 52 | int typ_; //!< random generation type
|
|---|
| 53 | double mean_, sig_; //!< generation parameters mean and sigma (if needed)
|
|---|
| 54 | mutable MuTyV retv_;
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 | //////////////////////////////////////////////////////////
|
|---|
| 59 | //! Class to generate a sequence of values
|
|---|
| 60 | class RegularSequence : public Sequence {
|
|---|
| 61 | public:
|
|---|
| 62 | explicit RegularSequence (double start=0., double step=1., Arr_DoubleFunctionOfX f=NULL);
|
|---|
| 63 | virtual ~RegularSequence();
|
|---|
| 64 |
|
|---|
| 65 | //! return start value of the sequence
|
|---|
| 66 | inline double & Start() { return start_; }
|
|---|
| 67 | //! return step value of the sequence
|
|---|
| 68 | inline double & Step() { return step_; }
|
|---|
| 69 |
|
|---|
| 70 | virtual MuTyV & Value(uint_8 k) const ;
|
|---|
| 71 |
|
|---|
| 72 | protected:
|
|---|
| 73 | double start_; //!< start value of the sequence
|
|---|
| 74 | double step_; //!< step value of the sequence
|
|---|
| 75 | Arr_DoubleFunctionOfX myf_; //!< pointer to the sequence function
|
|---|
| 76 | mutable MuTyV retv_;
|
|---|
| 77 | };
|
|---|
| 78 |
|
|---|
| 79 | class EnumeratedSequence : public Sequence {
|
|---|
| 80 | public:
|
|---|
| 81 | virtual ~EnumeratedSequence();
|
|---|
| 82 | virtual MuTyV & Value(uint_8 k) const ;
|
|---|
| 83 | EnumeratedSequence & operator , (MuTyV const & v);
|
|---|
| 84 | private:
|
|---|
| 85 | vector<MuTyV> vecv_;
|
|---|
| 86 | mutable MuTyV retv_;
|
|---|
| 87 | };
|
|---|
| 88 |
|
|---|
| 89 | inline EnumeratedSequence operator , (MuTyV const & a, MuTyV const & b)
|
|---|
| 90 | { EnumeratedSequence seq; return ((seq,a),b) ; }
|
|---|
| 91 |
|
|---|
| 92 | //////////////////////////////////////////////////////////
|
|---|
| 93 | //! Class to define a range of indexes
|
|---|
| 94 | class Range {
|
|---|
| 95 | public:
|
|---|
| 96 | explicit Range(uint_4 start=0, uint_4 end=0, uint_4 size=1, uint_4 step=1);
|
|---|
| 97 | //! Return the start index
|
|---|
| 98 | inline uint_4 & Start() { return start_; }
|
|---|
| 99 | //! Return the last index
|
|---|
| 100 | inline uint_4 & End() { return end_; }
|
|---|
| 101 | //! Return the size
|
|---|
| 102 | inline uint_4 & Size() { return size_; }
|
|---|
| 103 | //! Return the step
|
|---|
| 104 | inline uint_4 & Step() { return step_; }
|
|---|
| 105 | protected:
|
|---|
| 106 | uint_4 start_; //!< start index
|
|---|
| 107 | uint_4 end_; //!< end index
|
|---|
| 108 | uint_4 size_; //!< size
|
|---|
| 109 | uint_4 step_; //!< step
|
|---|
| 110 | };
|
|---|
| 111 |
|
|---|
| 112 | //////////////////////////////////////////////////////////
|
|---|
| 113 | //! Class to define an identity matrix
|
|---|
| 114 | class IdentityMatrix {
|
|---|
| 115 | public:
|
|---|
| 116 | explicit IdentityMatrix(double diag=1., uint_4 n=0);
|
|---|
| 117 | //! return the size of the identity matrix
|
|---|
| 118 | inline uint_4 Size() { return size_; }
|
|---|
| 119 | //! return the value of the diagonal elements
|
|---|
| 120 | inline double Diag() { return diag_; }
|
|---|
| 121 | protected:
|
|---|
| 122 | uint_4 size_; //!< size of the matrix
|
|---|
| 123 | double diag_; //!< value of the diagonal elements
|
|---|
| 124 | };
|
|---|
| 125 |
|
|---|
| 126 | } // Fin du namespace
|
|---|
| 127 |
|
|---|
| 128 | #endif
|
|---|