Changeset 3838 in Sophya
- Timestamp:
- Aug 9, 2010, 7:31:12 PM (15 years ago)
- Location:
- trunk/SophyaLib
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/randinterf.cc
r3791 r3838 7 7 #include <time.h> 8 8 #include <iostream> 9 #include <typeinfo> 10 9 11 #include "pexceptions.h" 10 12 … … 65 67 void RandomGeneratorInterface::ShowRandom() 66 68 { 67 cout<<"RandomGenerator is RandomGeneratorInterface i.e. UNDEFINED"<<endl; 68 } 69 70 ///////////////////////////////////////////////////////////////////////// 71 ///////////////////////////////////////////////////////////////////////// 72 ///////////////////////////////////////////////////////////////////////// 73 69 cout << " RandomGeneratorInterface::ShowRandom() typeid(this)=" << typeid(*this).name() << " @ " 70 << hex << (unsigned long)(this) << dec << endl; 71 return; 72 } 73 74 ///////////////////////////////////////////////////////////////////////// 75 ///////////////////////////////////////////////////////////////////////// 76 ///////////////////////////////////////////////////////////////////////// 77 78 /* 74 79 r_8 RandomGeneratorInterface::Next() 75 80 { … … 77 82 throw MathExc("RandomGeneratorInterface::Next(): undefined code !!!"); 78 83 } 84 */ 79 85 80 86 ///////////////////////////////////////////////////////////////////////// -
trunk/SophyaLib/BaseTools/randinterf.h
r3615 r3838 137 137 138 138 protected: 139 //! Return a random number in [0,1] 140 virtual r_8 Next(); 139 /*! \brief Should return a random number in the range [0,1] with flat distribution 140 141 This pure virtual method should be implemented by inheriting classes */ 142 virtual r_8 Next() = 0; 141 143 142 144 // Selection de type d'algo pour les aleatoires autres que plates -
trunk/SophyaLib/BaseTools/randr48.cc
r3739 r3838 10 10 namespace SOPHYA { 11 11 12 /*! 13 \class DR48RandGen 14 \ingroup BaseTools 15 \brief Implementation of the RandomGeneratorInterface class using drand48() functions 16 17 Its PPF handler can be used to save the complete state of the class and the underlying 18 random number generator used. 19 20 \sa SOPHYA::ObjFileIO<ThSDR48RandGen> 21 22 */ 23 12 24 static bool dr48_first = true; 13 25 DR48RandGen::DR48RandGen() … … 70 82 \class ThSDR48RandGen 71 83 \ingroup BaseTools 72 \brief Random number generator 73 74 This class is a thread-safe random number generator. 84 \brief Thread-safe version of DR48RandGen random number generator using drand48() functions. 85 86 87 Several instances of this class can be used in different threads without the risk of 88 corrupting the internal state of the drand48() generator. However, in multi-thread applications, 89 there is no guarantee to obtain the same sequence of numbers in each thread. 75 90 Its PPF handler can be used to save the complete state of the class and the underlying 76 random number generator used.91 random number generator (drand48() which is used. 77 92 78 93 \sa SOPHYA::ObjFileIO<ThSDR48RandGen> 79 94 95 \code 96 // A.1- Create a thread safe generator based on drand48() 97 ThSDR48RandGen rg; 98 // A.2- Auto initilize its state (using the system time) 99 rg.AutoInit(); 100 // A.3- compute and print a smal sequence of random numbers 101 int N = 10; 102 for(int i=0; i<N; i++) 103 cout << " I=" << i << " rand_flat01= " << rg.Flat01() << " rand.gaussian= " << rg.Gaussian() << endl; 104 // A.4- Save the generator state for subsequent use 105 POutPersist po("rg.ppf"); 106 po << rg; 107 // A.5- compute and print a second sequence of random numbers 108 for(int i=0; i<N; i++) 109 cout << "++ I=" << i+N << " rand_flat01= " << rg.Flat01() << " rand.gaussian= " << rg.Gaussian() << endl; 110 111 ... In another program : 112 113 // B.1- Create and initialize the generator from the previously saved state 114 ThSDR48RandGen rgr; 115 PInPersist pin("rg.ppf"); 116 pin >> rgr; 117 int N = 10; 118 // B.2- Compute and print a sequence of random number, should be compared to the sequance A.5 119 for(int i=0; i<N; i++) 120 cout << "-- I=" << i << " rand_flat01= " << rgr.Flat01() << " rand.gaussian= " << rgr.Gaussian() << endl; 121 122 123 \endcode 80 124 */ 81 125 82 126 // Objet statique global pour gestion de lock entre threads 83 127 static ThSafeOp* ths_rand = NULL; 128 129 /*! 130 \brief Constructor with optional specification of the internal buffer size and thread-safety flag 131 132 The behaviour of the base class DR48RandGen can be reproduced by specifying tsafe=false 133 \param n : an internal buffer of size n is created and filled through block calls to drand48() 134 \param tsafe : if false, creates a non thread-safe generator 135 */ 84 136 85 137 ThSDR48RandGen::ThSDR48RandGen(size_t n, bool tsafe) -
trunk/SophyaLib/BaseTools/randr48.h
r3739 r3838 15 15 16 16 17 /* ------- SPECIFIQUE Mac Darwin OSX <= 10.2 (gcc < 3.x) -------- */18 #if defined(Darwin) && defined(__GNUC__) && (__GNUC__ < 3)19 #include "osx_values.h"20 /* Declaration de drand48 et srand48 etc , mis ds SysSpec, Reza 11/02/2003 */21 #ifdef __cplusplus22 extern "C" {23 #endif24 unsigned short int * seed48(unsigned short int seed16v[3]);25 void srand48(long seedval);26 #ifdef __cplusplus27 }28 #endif29 #define drand48() ((double)(random())/LONG_MAX)30 #endif31 /* ------- FIN SPECIFIQUE Mac OSX / Darwin V <= 10.2 --------- */32 33 34 17 namespace SOPHYA { 35 18 36 // ! Implementation of the RandomGeneratorInterface class using drand48() functions19 // Implementation de RandomGeneratorInterface avec drand48() 37 20 class DR48RandGen : public RandomGeneratorInterface { 38 21 … … 60 43 //-------------------------------------------------------------------------------- 61 44 62 // ! Version thread-safe de RandomGeneratorInterface avec drand48() functions45 // Version thread-safe de DR48RandGen 63 46 class ThSDR48RandGen : public DR48RandGen { 64 47 -
trunk/SophyaLib/TArray/spesqmtx.cc
r3831 r3838 9 9 #include "tmatrix.h" 10 10 11 // doit etre mis en dehors du namespace 11 namespace SOPHYA { 12 12 /*! 13 \class S OPHYA::SpecialSquareMatrix13 \class SpecialSquareMatrix 14 14 \ingroup TArray 15 15 \brief The base class for representing and manipulating special square matrices 16 16 Diagonal matrix, Symmetric matrix, Triangular matrix 17 18 17 This class implements the common operations for special square matrices. Only objects 18 19 19 from the sub-classes (DiagonalMatrix<T>, LowerTriangularMatrix<T>, SymmetricMatrix<T>) 20 20 can be instanciated. Theses classes offer similar functionalities to the TArray<T> / TMatrix<T> 21 21 classes, like reference sharing and arithmetic operations. However, no sub-matrix extraction 22 22 method is provided. 23 sub matrix extraction method. 23 24 \code 25 // Create and initialize a diagonal matrix 26 DiagonalMatrix<double> diag(3); 27 diag(0,0)=1.; diag(1,1)=2.; diag(2,2)=3.; 28 // use of multiplication by a constant operator 29 diag *= 10.; 30 // check the diagonal matrix 31 cout << diag << diag.ConvertToStdMatrix() << endl; 32 // define and initialize a general matrix 33 TMatrix<double> mx(3,3); 34 mx=RegularSequence(); 35 cout << mx; 36 // check the result of a matrix mutiplication 37 cout << mx*diag; 38 \endcode 24 39 */ 25 26 namespace SOPHYA {27 40 28 41 //! Default constructor - SpecialSquareMatrix of size 0, SetSize() should be called before the object is used
Note:
See TracChangeset
for help on using the changeset viewer.