Changeset 3613 in Sophya


Ignore:
Timestamp:
Apr 30, 2009, 7:07:46 PM (16 years ago)
Author:
ansari
Message:

Adaptation a l'introduction de la suite des classes RandomGeneratorInterface et Cie , Reza 30/04/2009

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/Samba/alm.cc

    r3510 r3613  
    2020
    2121  //alm.ReSize(nlmax);
    22   this->ReSizeRow(nlmax+1);
    23   RandomGenerator rg(1, false);
    24   GenFromCl(clin, fwhm, rg);
     22  this->ReSizeRow(nlmax+1);
     23  GenFromCl(clin, fwhm, *(RandomGeneratorInterface::GetGlobalRandGenP()) );
    2524}
    2625
     
    2928*/
    3029template <class T>
    31 Alm<T>::Alm(const TVector<T>& clin, const r_8 fwhm, RandomGenerator & rg)
     30Alm<T>::Alm(const TVector<T>& clin, const r_8 fwhm, RandomGeneratorInterface & rg)
    3231{
    3332  int_4 nlmax= clin.NElts()-1;
     
    4140
    4241template <class T>
    43 void Alm<T>::GenFromCl(const TVector<T> & clin, const r_8 fwhm, RandomGenerator & rg)
     42void Alm<T>::GenFromCl(const TVector<T> & clin, const r_8 fwhm, RandomGeneratorInterface & rg)
    4443{
    4544  /*=======================================================================
  • trunk/SophyaLib/Samba/alm.h

    r3510 r3613  
    66#define ALM_SEEN
    77
    8 #include "stsrand.h"
     8#include "randinterf.h"
    99#include "nbmath.h"
    1010#include "triangmtx.h"
     
    2626  Alm(const TVector<T> & clin, const r_8 fwhm) ;
    2727//! Constructor, generates alm from a cl vector, using the specified random generator object
    28   Alm(const TVector<T> & clin, const r_8 fwhm, RandomGenerator & rg);
     28  Alm(const TVector<T> & clin, const r_8 fwhm, RandomGeneratorInterface& rg);
    2929
    3030//! Resize with a new lmax
     
    4141
    4242private:
    43   void GenFromCl(const TVector<T> & clin, const r_8 fwhm, RandomGenerator& rg);
     43  void GenFromCl(const TVector<T> & clin, const r_8 fwhm, RandomGeneratorInterface& rg);
    4444};
    4545
  • trunk/SophyaLib/Samba/sphericaltransformserver.cc

    r3572 r3613  
    66#include "sphericaltransformserver.h"
    77#include "tvector.h"
    8 #include "stsrand.h"
    98#include "nbmath.h"
    109#include "timing.h"
     
    156155template<class T>
    157156SphericalTransformServer<T>::SphericalTransformServer()
    158 : rg_(1, false)
     157: rgp_(RandomGeneratorInterface::GetGlobalRandGenP())
    159158{
    160159  fftIntfPtr_=new FFTPackServer(true); // preserveinput = true
     
    164163//!  Constructor with the specification of a RandomGenerator object to be used by GenerateFromCl
    165164template<class T>
    166 SphericalTransformServer<T>::SphericalTransformServer(RandomGenerator const & rg)
    167 : rg_(rg)
     165SphericalTransformServer<T>::SphericalTransformServer(RandomGeneratorInterface& rg)
     166: rgp_(&rg)
    168167{
    169168  fftIntfPtr_=new FFTPackServer(true); // preserveinput = true
     
    13121311  //  Alm<T> a2lme = almFromCl(Cle, fwhm);
    13131312  // Alm<T> a2lmb = almFromCl(Clb, fwhm);
    1314   Alm<T> a2lme(Cle, fwhm, rg_);
    1315   Alm<T> a2lmb(Clb, fwhm, rg_);
     1313  Alm<T> a2lme(Cle, fwhm, *rgp_);
     1314  Alm<T> a2lmb(Clb, fwhm, *rgp_);
    13161315
    13171316  GenerateFromAlm(sphq,sphu,pixelSizeIndex,a2lme,a2lmb);
     
    13301329{
    13311330
    1332   Alm<T> alm(Cl, fwhm, rg_);
     1331  Alm<T> alm(Cl, fwhm, *rgp_);
    13331332  GenerateFromAlm(sph,pixelSizeIndex, alm );
    13341333}
  • trunk/SophyaLib/Samba/sphericaltransformserver.h

    r3510 r3613  
    55#include "fftservintf.h"
    66#include "fftpserver.h"
    7 #include "stsrand.h"
     7#include "randinterf.h"
    88#include "alm.h"
    99#include "lambdaBuilder.h"
     
    1919 public:
    2020
    21   SphericalTransformServer(); 
    22   SphericalTransformServer(RandomGenerator const & rg); 
     21  explicit SphericalTransformServer(); 
     22  explicit SphericalTransformServer(RandomGeneratorInterface& rg); 
    2323  virtual ~SphericalTransformServer();
    2424  void SetFFTServer(FFTServerInterface* srv=NULL);
     
    107107
    108108 FFTServerInterface* fftIntfPtr_;
    109  mutable RandomGenerator rg_;
     109 mutable RandomGeneratorInterface* rgp_;
    110110
    111111};
  • trunk/SophyaLib/TArray/utilarr.cc

    r3572 r3613  
    55#include "machdefs.h"
    66#include "utilarr.h"
    7 #include "stsrand.h"
     7#include "randr48.h"
    88
    99// Classe utilitaires
     
    2020*/
    2121
    22 //! Constructor
    23 /*!
    24   \param typ : generator type
    25   \param m : mean parameter of the generator (if needed)
    26   \param s : sigma parameter of the generator (if needed)
     22/*!
     23  \brief constructor using a global default random generator ( RandomGeneratorInterface::GetGlobalRandGenP() )
     24  \param typ : generated random numbers distribution type: C_RND_Flat,C_RND_Gaussian,C_RND_Poisson,C_RND_Exponential
     25  \param mean : mean value of the distribution
     26  \param sigma : standard deviation of the distribution
    2727 */
    28 static RandomGenerator* uarg_ = NULL;
    29 RandomSequence::RandomSequence(int typ, double m, double s)
    30 {
    31   typ_ = (typ == Flat) ? Flat : Gaussian;
    32   mean_ = m;
    33   sig_ = s;
    34   if (uarg_ == NULL) uarg_ = new RandomGenerator(1024, true);
    35 }
     28RandomSequence::RandomSequence(int typ, double mean, double sigma)
     29{
     30  typ_ = (typ == Flat) ? C_RND_Flat: C_RND_Gaussian ;
     31  mean_ = mean;
     32  sig_ = sigma;
     33  rgp_ = RandomGeneratorInterface::GetGlobalRandGenP();
     34}
     35
     36
     37/*!
     38  \brief constructor with the specification of a RandomGenerator object to be used.
     39  \param rgen : RandomGeneratorInterface object that should stay valid as long as the RandomSequence object exist.
     40  \param typ : generated random numbers distribution type: C_RND_Flat,C_RND_Gaussian,C_RND_Poisson,C_RND_Exponential
     41  \param mean : mean value of the distribution
     42  \param sigma : standard deviation of the distribution
     43 */
     44RandomSequence::RandomSequence(RandomGeneratorInterface& rgen, RNDTypes rtyp, double mean, double sigma)
     45{
     46  typ_ = rtyp;
     47  mean_ = mean;
     48  sig_ = sigma;
     49  rgp_ = &rgen;
     50}
     51
    3652RandomSequence::~RandomSequence()
    3753{
    3854}
    3955
    40 //! Return random sequence values.
    41 /*!
    42   \return If typ = Flat : return [-1,+1]*sig + mean
    43   \return If typ = Gaussian : return gaussian distributed
    44                           with \b mean mean and sigma \b sig
    45  */
    46 double RandomSequence::Rand()
    47 {
    48   if (typ_ == Flat)
    49     return(uarg_->Flatpm1()*sig_ + mean_);
    50   else return(uarg_->Gaussian(sig_, mean_));
    51 }
    52 
     56double RandomSequence::Next() const
     57{
     58  switch (typ_) {
     59    case C_RND_Flat :
     60      return rgp_->Flatpm1()*sig_ + mean_;
     61      break;
     62    case C_RND_Gaussian :
     63      return rgp_->Gaussian(sig_, mean_);
     64      break;
     65    case C_RND_Poisson :
     66      return rgp_->Poisson(mean_);
     67      break;
     68    case C_RND_Exponential :
     69      return rgp_->Exponential();
     70      break;
     71    default :
     72      return rgp_->Flat01();
     73      break;
     74
     75  }
     76}
     77
     78//!  \brief Return the next random number
    5379MuTyV & RandomSequence::Value(sa_size_t k) const
    5480{
    55   if (typ_ == Flat) retv_ = uarg_->Flatpm1()*sig_ + mean_;
    56   else retv_ = uarg_->Gaussian(sig_, mean_);
     81  retv_ = Next();
    5782  return retv_;
    5883}
  • trunk/SophyaLib/TArray/utilarr.h

    r2917 r3613  
    88#include "machdefs.h"
    99#include "mutyv.h"
     10#include "randinterf.h"
    1011
    1112#include <stdlib.h>
     
    5657
    5758  explicit RandomSequence(int typ = RandomSequence::Gaussian, double m=0., double s=1.);
     59  explicit RandomSequence(RandomGeneratorInterface& rgen, RNDTypes rtyp=C_RND_Gaussian, double mean=0., double sigma=1.);
    5860  virtual  ~RandomSequence();
    5961  virtual MuTyV & Value(sa_size_t k) const ;
    60   double   Rand();
     62  double   Next() const ;
    6163
    6264protected:
    63   int typ_;            //!< random generation type
     65  RNDTypes typ_;            //!< random generation type
    6466  double mean_, sig_;  //!< generation parameters mean and sigma (if needed)
    6567  mutable MuTyV retv_;
     68  mutable RandomGeneratorInterface* rgp_;
    6669};
    6770
  • trunk/SophyaProg/PrgMap/cl2map.cc

    r3512 r3613  
    1414#include "fitsspherehealpix.h"
    1515#include "fitstarray.h"
     16
     17#include "randr48.h"
    1618
    1719/*!
     
    115117       << "' msph= " << msph << ") beam=" << beam*minute2rad << " rad" << endl;
    116118  // on cree la carte
    117   RandomGenerator rg;
     119  ThSDR48RandGen rg;
    118120  if (fgair) {
    119121    cout << " Setting random number generator seed (using time) " << endl;
  • trunk/SophyaProg/Tests/tmtrnd.cc

    r3606 r3613  
    2828
    2929#include "srandgen.h"
    30 #include "stsrand.h"
    3130#include "randr48.h"
    3231
    3332
    34 // Choix du nom de la classe thread-safe a tests
     33// Choix du nom de la classe thread-safe a tester
    3534#define TC_RandomGenerator ThSDR48RandGen
    3635
  • trunk/SophyaProg/Tests/tmtrnd3.cc

    r3390 r3613  
    1717#include "timing.h"
    1818
    19 #include "stsrand.h"
     19#include "randr48.h"
    2020
    2121long Check_Redondances(TVector<r_8>& v);
     
    5555  cout<<"MTRndTest::run() - Nom= "<<nom_<<" vv.Size()= "<<vv_.Size()
    5656      <<" with threadsafe="<<thsafe_<<endl;
    57   if(thsafe_) {  // On appele RandomGenerator Thread-Safe
    58     RandomGenerator rgen(nbuff_,true);
     57  if(thsafe_) {  // On appele ThSDR48RandGen Thread-Safe
     58    ThSDR48RandGen rgen(nbuff_,true);
    5959    for(sa_size_t k=0; k<vv_.Size(); k++) vv_(k) = rgen.Flat01();
    60   } else {  // On appele RandomGenerator NO Thread-Safe
     60  } else {  // On appele ThSDR48RandGen NO Thread-Safe
    6161    // ATTENTION: le comportement est different selon qu'un thread
    6262    // se termine avant ou apres que le suivant commence:
     
    6565    // cela donne un comportement "tread_safe" APPARENT mais
    6666    // dans la realite drand48() N'EST PAS thread_safe !!!!
    67     RandomGenerator rgen(0,false);
     67    ThSDR48RandGen rgen(0,false);
    6868    for(sa_size_t k=0; k<vv_.Size(); k++) vv_(k) = rgen.Flat01();
    6969  }
     
    8383  if(NTH<=0) NTH = 1;
    8484  cout<<"tmtrnd/arguments, VSZ= "<<VSZ<<" NTH= "<<NTH<<" NBUFF="<<NBUFF<<endl;
    85   // Il ne faut pas que les buffers de RandomGenerator soient remplis
     85  // Il ne faut pas que les buffers de ThSDR48RandGen soient remplis
    8686  // au dela de ce qui est necessaire si on veut faire
    8787  // la comparaison avec le mono thread
     
    100100    //--- Init et set de l'aleatoire
    101101    //---
    102     RandomGenerator rgen_nothsf(0,false);
     102    ThSDR48RandGen rgen_nothsf(0,false);
    103103    unsigned short seed_16v[3];
    104104    {
    105105    cout<<"\n>>>>>>> Init de l'aleatoire"<<endl;
    106106    rgen_nothsf.AutoInit(5);
    107     rgen_nothsf.GetSeed(seed_16v,5);
     107    rgen_nothsf.GetSeed(seed_16v);
    108108    }
    109109
     
    116116    {
    117117    cout<<"\n>>>>>>> Remplissage en mono-thread avec drand48()"<<endl;
    118     rgen_nothsf.Init(seed_16v,5);
     118    rgen_nothsf.SetSeed(seed_16v);
    119119    for(int i=0;i<VSZ;i++) DATA0(i) = drand48();
    120120    PrtTim(" ");
     
    122122
    123123    //---
    124     //--- Remplissage par threads avec RandomGenerator thread safe
     124    //--- Remplissage par threads avec ThSDR48RandGen thread safe
    125125    //---
    126126    TVector<r_8> DATA1(VSZ);
    127127    {
    128     cout<<"\n>>>>>>> Remplissage par threads avec RandomGenerator thread safe"<<endl;
    129     rgen_nothsf.Init(seed_16v,5);
     128    cout<<"\n>>>>>>> Remplissage par threads avec ThSDR48RandGen thread safe"<<endl;
     129    rgen_nothsf.SetSeed(seed_16v);
    130130    vector<MTRndTest *> vth1;
    131131    cout<<"...tmtrnd/creating threads "<<endl;
     
    147147
    148148    //---
    149     //--- Remplissage par threads avec RandomGenerator SANS thread safe
     149    //--- Remplissage par threads avec ThSDR48RandGen SANS thread safe
    150150    //---
    151151    TVector<r_8> DATA2(VSZ);
    152152    {
    153     cout<<"\n>>>>>>> Remplissage par threads avec RandomGenerator SANS thread safe"<<endl;
    154     rgen_nothsf.Init(seed_16v,5);
     153    cout<<"\n>>>>>>> Remplissage par threads avec ThSDR48RandGen SANS thread safe"<<endl;
     154    rgen_nothsf.SetSeed(seed_16v);
    155155    vector<MTRndTest *> vth2;
    156156    cout << "......tmtrnd/creating threads " << endl;
     
    172172
    173173    //---
    174     //--- remplissage en mono-thread avec RandomGenerator
     174    //--- remplissage en mono-thread avec ThSDR48RandGen
    175175    //---
    176176    TVector<r_8> DATA0R(VSZ);
    177177    {
    178     cout<<"\n>>>>>>> Remplissage en mono-thread avec RandomGenerator"<<endl;
    179     rgen_nothsf.Init(seed_16v,5);
     178    cout<<"\n>>>>>>> Remplissage en mono-thread avec ThSDR48RandGen"<<endl;
     179    rgen_nothsf.SetSeed(seed_16v);
    180180    for(int i=0;i<VSZ;i++) DATA0R(i) = rgen_nothsf.Flat01();
    181181    PrtTim(" ");
Note: See TracChangeset for help on using the changeset viewer.