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

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

define module HiStats in Doc cmv 13/4/00

File size: 3.1 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
22/*!
23 \class SOPHYA::RandomSequence
24 \ingroup TArray
25*/
26class RandomSequence {
27public:
28 //! to define the generator type
29 enum {
30 Gaussian = 0, //!< gaussian generator
31 Flat = 1 //!< Flat generator
32 };
33
34 RandomSequence(int typ = RandomSequence::Gaussian, double m=0., double s=1.);
35 double Rand();
36protected:
37 int typ_; //!< random generation type
38 double mean_, sig_; //!< generation parameters mean and sigma (if needed)
39};
40
41
42//////////////////////////////////////////////////////////
43//! Class to generate a sequence of values
44/*!
45 \class SOPHYA::Sequence
46 \ingroup TArray
47*/
48class Sequence {
49public:
50 explicit Sequence (double start=0., double step=1., Arr_DoubleFunctionOfX f=NULL);
51 explicit Sequence (RandomSequence rseq);
52
53 //! return start value of the sequence
54 inline double & Start() { return start_; }
55 //! return step value of the sequence
56 inline double & Step() { return step_; }
57 double operator () (uint_4 k);
58protected:
59 double start_; //!< start value of the sequence
60 double step_; //!< step value of the sequence
61 Arr_DoubleFunctionOfX myf_; //!< pointer to the sequence function
62 bool fgrseq_; //!< true if RandomSequence is used
63 RandomSequence rseq_; //!< RandomSequence
64};
65
66//////////////////////////////////////////////////////////
67//! Class to define a range of indexes
68/*!
69 \class SOPHYA::Range
70 \ingroup TArray
71*/
72class Range {
73public:
74 explicit Range(uint_4 start=0, uint_4 end=0, uint_4 size=1, uint_4 step=1);
75 //! Return the start index
76 inline uint_4 & Start() { return start_; }
77 //! Return the last index
78 inline uint_4 & End() { return end_; }
79 //! Return the size
80 inline uint_4 & Size() { return size_; }
81 //! Return the step
82 inline uint_4 & Step() { return step_; }
83protected:
84 uint_4 start_; //!< start index
85 uint_4 end_; //!< end index
86 uint_4 size_; //!< size
87 uint_4 step_; //!< step
88};
89
90//////////////////////////////////////////////////////////
91//! Class to define an identity matrix
92/*!
93 \class SOPHYA::IdentityMatrix
94 \ingroup TArray
95*/
96class IdentityMatrix {
97public:
98 explicit IdentityMatrix(double diag=1., uint_4 n=0);
99 //! return the size of the identity matrix
100 inline uint_4 Size() { return size_; }
101 //! return the value of the diagonal elements
102 inline double Diag() { return diag_; }
103protected:
104 uint_4 size_; //!< size of the matrix
105 double diag_; //!< value of the diagonal elements
106};
107
108} // Fin du namespace
109
110#endif
Note: See TracBrowser for help on using the repository browser.