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

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

Corrections divers + RansomSequence - Reza 10/4/2000

File size: 1.5 KB
RevLine 
[785]1// Utility classes for template numerical arrays
2// R. Ansari, C.Magneville 03/2000
3
4#include "machdefs.h"
5#include "utilarr.h"
[850]6#include "srandgen.h"
[785]7
8// Classe utilitaires
[850]9
10RandomSequence::RandomSequence(int typ, double m, double s)
11{
12 typ_ = (typ == Flat) ? Flat : Gaussian;
13 mean_ = m;
14 sig_ = s;
15}
16
17double RandomSequence::Rand()
18{
19 if (typ_ == Flat)
20 return(drandpm1()*sig_ + mean_);
21 else return(GauRnd(mean_, sig_));
22}
23
24
[785]25Sequence::Sequence(double start, double step, Arr_DoubleFunctionOfX f)
[850]26 : rseq_(RandomSequence::Gaussian)
[785]27{
28 start_ = start;
29 step_ = step;
30 myf_ = f;
[850]31 fgrseq_ = false;
[785]32}
33
[850]34Sequence::Sequence(RandomSequence rseq)
35{
36 start_ = 0.;
37 step_ = 1.;
38 myf_ = NULL;
39 rseq_ = rseq;
40 fgrseq_ = true;
41}
42
[785]43double Sequence::operator () (uint_4 k)
44{
[850]45 if (fgrseq_) return(rseq_.Rand());
46 else {
47 double x = start_+(double)k*step_;
48 if (myf_) return(myf_(x));
49 else return x;
50 }
[785]51}
52
[813]53Range::Range(uint_4 start, uint_4 end, uint_4 size, uint_4 step)
[785]54{
55 start_ = start;
56 step_ = (step > 0) ? step : 1;
[813]57 if (end > start) { // Taille calcule automatiquement
58 end_ = end;
59 if (step_ > ((end_-start_)+1)) size_ = 1;
60 else size_ = ((end-start)+1)/step_;
61 }
62 else { // Taille fixee
63 size_ = size;
64 end_ = start_+size_*step_;
65 }
[785]66}
67
[804]68/*
[785]69Range & Range::operator = (uint_4 start)
70{
71 start_ = start;
72 size_ = 1;
73 step_ = 1;
74 return (*this);
75}
[804]76*/
77
78
79IdentityMatrix::IdentityMatrix(double diag, uint_4 n)
80{
81 size_ = n;
82 diag_ = diag;
83}
Note: See TracBrowser for help on using the repository browser.