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