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

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

define module HiStats in Doc cmv 13/4/00

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