source: Sophya/trunk/SophyaLib/TArray/utilarr.h@ 988

Last change on this file since 988 was 956, checked in by ansari, 25 years ago

encore de la doc cmv 17/04/00

File size: 3.0 KB
Line 
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
11namespace 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*/
19typedef double (* Arr_DoubleFunctionOfX) (double x);
20/*! \ingroup TArray
21 \typedef Arr_FloatFunctionOfX
22 \brief define a function of float which returns a double
23*/
24typedef float (* Arr_FloatFunctionOfX) (float x);
25
26//////////////////////////////////////////////////////////
27//! Class to generate a random sequence of values
28class RandomSequence {
29public:
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();
38protected:
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
46class Sequence {
47public:
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);
56protected:
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
66class Range {
67public:
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_; }
77protected:
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
86class IdentityMatrix {
87public:
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_; }
93protected:
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
Note: See TracBrowser for help on using the repository browser.