| [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 |
|
|---|
| [894] | 15 | //! define a function of double which returns a double
|
|---|
| [785] | 16 | typedef double (* Arr_DoubleFunctionOfX) (double x);
|
|---|
| [894] | 17 | //! define a function of float which returns a float
|
|---|
| [785] | 18 | typedef float (* Arr_FloatFunctionOfX) (float x);
|
|---|
| 19 |
|
|---|
| [894] | 20 | //////////////////////////////////////////////////////////
|
|---|
| 21 | //! Class to generate a random sequence of values
|
|---|
| [850] | 22 | class RandomSequence {
|
|---|
| 23 | public:
|
|---|
| [894] | 24 | //! to define the generator type
|
|---|
| 25 | enum {
|
|---|
| 26 | Gaussian = 0, //!< gaussian generator
|
|---|
| 27 | Flat = 1 //!< Flat generator
|
|---|
| 28 | };
|
|---|
| 29 |
|
|---|
| [850] | 30 | RandomSequence(int typ = RandomSequence::Gaussian, double m=0., double s=1.);
|
|---|
| 31 | double Rand();
|
|---|
| 32 | protected:
|
|---|
| [894] | 33 | int typ_; //!< random generation type
|
|---|
| 34 | double mean_, sig_; //!< generation parameters mean and sigma (if needed)
|
|---|
| [850] | 35 | };
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| [894] | 38 | //////////////////////////////////////////////////////////
|
|---|
| 39 | //! Class to generate a sequence of values
|
|---|
| [785] | 40 | class Sequence {
|
|---|
| 41 | public:
|
|---|
| [804] | 42 | explicit Sequence (double start=0., double step=1., Arr_DoubleFunctionOfX f=NULL);
|
|---|
| [850] | 43 | explicit Sequence (RandomSequence rseq);
|
|---|
| [894] | 44 |
|
|---|
| 45 | //! return start value of the sequence
|
|---|
| [785] | 46 | inline double & Start() { return start_; }
|
|---|
| [894] | 47 | //! return step value of the sequence
|
|---|
| [785] | 48 | inline double & Step() { return step_; }
|
|---|
| 49 | double operator () (uint_4 k);
|
|---|
| 50 | protected:
|
|---|
| [894] | 51 | double start_; //!< start value of the sequence
|
|---|
| 52 | double step_; //!< step value of the sequence
|
|---|
| 53 | Arr_DoubleFunctionOfX myf_; //!< pointer to the sequence function
|
|---|
| 54 | bool fgrseq_; //!< true if RandomSequence is used
|
|---|
| 55 | RandomSequence rseq_; //!< RandomSequence
|
|---|
| [785] | 56 | };
|
|---|
| 57 |
|
|---|
| [894] | 58 | //////////////////////////////////////////////////////////
|
|---|
| 59 | //! Class to define a range of indexes
|
|---|
| [785] | 60 | class Range {
|
|---|
| 61 | public:
|
|---|
| [813] | 62 | explicit Range(uint_4 start=0, uint_4 end=0, uint_4 size=1, uint_4 step=1);
|
|---|
| [894] | 63 | //! Return the start index
|
|---|
| [785] | 64 | inline uint_4 & Start() { return start_; }
|
|---|
| [894] | 65 | //! Return the last index
|
|---|
| [813] | 66 | inline uint_4 & End() { return end_; }
|
|---|
| [894] | 67 | //! Return the size
|
|---|
| [813] | 68 | inline uint_4 & Size() { return size_; }
|
|---|
| [894] | 69 | //! Return the step
|
|---|
| [813] | 70 | inline uint_4 & Step() { return step_; }
|
|---|
| [785] | 71 | protected:
|
|---|
| [894] | 72 | uint_4 start_; //!< start index
|
|---|
| 73 | uint_4 end_; //!< end index
|
|---|
| 74 | uint_4 size_; //!< size
|
|---|
| 75 | uint_4 step_; //!< step
|
|---|
| [785] | 76 | };
|
|---|
| 77 |
|
|---|
| [894] | 78 | //////////////////////////////////////////////////////////
|
|---|
| 79 | //! Class to define an identity matrix
|
|---|
| [804] | 80 | class IdentityMatrix {
|
|---|
| 81 | public:
|
|---|
| 82 | explicit IdentityMatrix(double diag=1., uint_4 n=0);
|
|---|
| [894] | 83 | //! return the size of the identity matrix
|
|---|
| [804] | 84 | inline uint_4 Size() { return size_; }
|
|---|
| [894] | 85 | //! return the value of the diagonal elements
|
|---|
| [804] | 86 | inline double Diag() { return diag_; }
|
|---|
| 87 | protected:
|
|---|
| [894] | 88 | uint_4 size_; //!< size of the matrix
|
|---|
| 89 | double diag_; //!< value of the diagonal elements
|
|---|
| [804] | 90 | };
|
|---|
| 91 |
|
|---|
| [785] | 92 | } // Fin du namespace
|
|---|
| 93 |
|
|---|
| 94 | #endif
|
|---|