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

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

documentation cmv 13/4/00

File size: 3.3 KB
Line 
1// Utility classes for template numerical arrays
2// R. Ansari, C.Magneville 03/2000
3
4#include "machdefs.h"
5#include "utilarr.h"
6#include "srandgen.h"
7
8// Classe utilitaires
9
10//////////////////////////////////////////////////////////
11/*!
12 \class SOPHYA::RandomSequence
13 \ingroup TArray
14 Class to generate a random sequence of values
15*/
16
17//! Constructor
18/*!
19 \param typ : generator type
20 \param m : mean parameter of the generator (if needed)
21 \param s : sigma parameter of the generator (if needed)
22 */
23RandomSequence::RandomSequence(int typ, double m, double s)
24{
25 typ_ = (typ == Flat) ? Flat : Gaussian;
26 mean_ = m;
27 sig_ = s;
28}
29
30//! Return random sequence values.
31double RandomSequence::Rand()
32{
33 if (typ_ == Flat)
34 return(drandpm1()*sig_ + mean_);
35 else return(GauRnd(mean_, sig_));
36}
37
38
39//////////////////////////////////////////////////////////
40/*!
41 \class SOPHYA::Sequence
42 \ingroup TArray
43 Class to generate a sequence of values
44*/
45
46//! Constructor
47/*!
48 \param start : start value
49 \param step : step value
50 \param f : pointer to the sequence function
51
52 See \ref SequenceOperat "operator()"
53 */
54Sequence::Sequence(double start, double step, Arr_DoubleFunctionOfX f)
55 : rseq_(RandomSequence::Gaussian)
56{
57 start_ = start;
58 step_ = step;
59 myf_ = f;
60 fgrseq_ = false;
61}
62
63//! Constructor
64/*!
65 \param rseq : RandomSequence
66
67 See \ref SequenceOperat "operator()"
68 */
69Sequence::Sequence(RandomSequence rseq)
70{
71 start_ = 0.;
72 step_ = 1.;
73 myf_ = NULL;
74 rseq_ = rseq;
75 fgrseq_ = true;
76}
77
78//! Get the \b k th value
79/*!
80 \param k : index of the value
81 \anchor SequenceOperat
82
83 If the constructor was done with RandomSequence, return a RandomSequence
84 and \b k doesn't matter.
85
86 If the constructor has a NULL Arr_DoubleFunctionOfX, return start+k*step
87
88 If the constructor has a not NULL Arr_DoubleFunctionOfX, return f(start+k*step)
89 \return the \b k th value
90 */
91double Sequence::operator () (uint_4 k)
92{
93 if (fgrseq_) return(rseq_.Rand());
94 else {
95 double x = start_+(double)k*step_;
96 if (myf_) return(myf_(x));
97 else return x;
98 }
99}
100
101//////////////////////////////////////////////////////////
102/*!
103 \class SOPHYA::Range
104 \ingroup TArray
105 Class to define a range of indexes
106*/
107
108//! Constructor
109/*!
110 Define a range of indexes
111 \param start : start index
112 \param end : start end
113 \param size : size
114 \param step : step
115
116 \warning If \b end \> \b start, \b size is computed automatically
117 \warning If not \b size is fixed and \b end recomputed
118 */
119Range::Range(uint_4 start, uint_4 end, uint_4 size, uint_4 step)
120{
121 start_ = start;
122 step_ = (step > 0) ? step : 1;
123 if (end > start) { // Taille calcule automatiquement
124 end_ = end;
125 if (step_ > ((end_-start_)+1)) size_ = 1;
126 else size_ = ((end-start)+1)/step_;
127 }
128 else { // Taille fixee
129 size_ = size;
130 end_ = start_+size_*step_;
131 }
132}
133
134/*
135Range & Range::operator = (uint_4 start)
136{
137 start_ = start;
138 size_ = 1;
139 step_ = 1;
140 return (*this);
141}
142*/
143
144
145//////////////////////////////////////////////////////////
146/*!
147 \class SOPHYA::IdentityMatrix
148 \ingroup TArray
149 Class to define an identity matrix
150*/
151
152//! Constructor of a (n,n) diagonal matrix with value diag on the diagonal
153IdentityMatrix::IdentityMatrix(double diag, uint_4 n)
154{
155 size_ = n;
156 diag_ = diag;
157}
Note: See TracBrowser for help on using the repository browser.