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

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

documentation cmv 13/4/00

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