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

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

documentation cmv 12/4/00

File size: 2.9 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//! Constructor
12/*!
13 \param typ : generator type
14 \param m : mean parameter of the generator (if needed)
15 \param s : sigma parameter of the generator (if needed)
16 */
17RandomSequence::RandomSequence(int typ, double m, double s)
18{
19 typ_ = (typ == Flat) ? Flat : Gaussian;
20 mean_ = m;
21 sig_ = s;
22}
23
24//! Return random sequence values.
25double RandomSequence::Rand()
26{
27 if (typ_ == Flat)
28 return(drandpm1()*sig_ + mean_);
29 else return(GauRnd(mean_, sig_));
30}
31
32
33//////////////////////////////////////////////////////////
34//! Constructor
35/*!
36 \param start : start value
37 \param step : step value
38 \param f : pointer to the sequence function
39
40 See \ref SequenceOperat "operator()"
41 */
42Sequence::Sequence(double start, double step, Arr_DoubleFunctionOfX f)
43 : rseq_(RandomSequence::Gaussian)
44{
45 start_ = start;
46 step_ = step;
47 myf_ = f;
48 fgrseq_ = false;
49}
50
51//! Constructor
52/*!
53 \param rseq : RandomSequence
54
55 See \ref SequenceOperat "operator()"
56 */
57Sequence::Sequence(RandomSequence rseq)
58{
59 start_ = 0.;
60 step_ = 1.;
61 myf_ = NULL;
62 rseq_ = rseq;
63 fgrseq_ = true;
64}
65
66//! Get the \b k th value
67/*!
68 \param k : index of the value
69 \anchor SequenceOperat
70
71 If the constructor was done with RandomSequence, return a RandomSequence
72 and \b k doesn't matter.
73
74 If the constructor has a NULL Arr_DoubleFunctionOfX, return start+k*step
75
76 If the constructor has a not NULL Arr_DoubleFunctionOfX, return f(start+k*step)
77 \return the \b k th value
78 */
79double Sequence::operator () (uint_4 k)
80{
81 if (fgrseq_) return(rseq_.Rand());
82 else {
83 double x = start_+(double)k*step_;
84 if (myf_) return(myf_(x));
85 else return x;
86 }
87}
88
89//////////////////////////////////////////////////////////
90//! Constructor
91/*!
92 Define a range of indexes
93 \param start : start index
94 \param end : start end
95 \param size : size
96 \param step : step
97
98 \warning If \b end \> \b start, \b size is computed automatically
99 \warning If not \b size is fixed and \b end recomputed
100 */
101Range::Range(uint_4 start, uint_4 end, uint_4 size, uint_4 step)
102{
103 start_ = start;
104 step_ = (step > 0) ? step : 1;
105 if (end > start) { // Taille calcule automatiquement
106 end_ = end;
107 if (step_ > ((end_-start_)+1)) size_ = 1;
108 else size_ = ((end-start)+1)/step_;
109 }
110 else { // Taille fixee
111 size_ = size;
112 end_ = start_+size_*step_;
113 }
114}
115
116/*
117Range & Range::operator = (uint_4 start)
118{
119 start_ = start;
120 size_ = 1;
121 step_ = 1;
122 return (*this);
123}
124*/
125
126
127//////////////////////////////////////////////////////////
128//! Constructor of a (n,n) diagonal matrix with value diag on the diagonal
129IdentityMatrix::IdentityMatrix(double diag, uint_4 n)
130{
131 size_ = n;
132 diag_ = diag;
133}
Note: See TracBrowser for help on using the repository browser.