QMCPACK
RandomForTest< VT > Class Template Reference

Get a known sequence of random numbers for testing. More...

+ Inheritance diagram for RandomForTest< VT >:
+ Collaboration diagram for RandomForTest< VT >:

Public Member Functions

 RandomForTest ()
 
std::vector< VT > getRngVec (int ncount)
 
std::vector< std::complex< VT > > getRngVecComplex (int ncount)
 
void fillVecRng (std::vector< VT > &rng_reals)
 
void fillVecRng (std::vector< std::complex< VT >> &rng_reals)
 
void fillBufferRng (VT *rng_reals, size_t number)
 
void fillBufferRng (std::complex< VT > *rng_reals, size_t number)
 
VT operator() ()
 

Private Attributes

StdRandom< VT > rng
 

Detailed Description

template<typename VT>
class qmcplusplus::testing::RandomForTest< VT >

Get a known sequence of random numbers for testing.

VT is the floating point precision While inelegant to have separate named calls for the cplx types in the same class separate class templates for RandomForTest<double> and RandomForTest<std::complex<double>> turned out to be surprisingly difficult. Someone is welcome to try when we required > c++14

Definition at line 31 of file RandomForTest.h.

Constructor & Destructor Documentation

◆ RandomForTest()

Definition at line 20 of file RandomForTest.cpp.

21 {
22  rng.init(111);
23 }
void init(int iseed_in) override
Definition: StdRandom.h:64

Member Function Documentation

◆ fillBufferRng() [1/2]

void fillBufferRng ( VT *  rng_reals,
size_t  number 
)

Definition at line 63 of file RandomForTest.cpp.

Referenced by TestFillBufferRngReal< T >::operator()(), and TestFillBufferRngComplex< T >::operator()().

64 {
65  for (size_t ir = 0; ir < count; ++ir)
66  {
67  *rng_reals = rng();
68  ++rng_reals;
69  }
70 }

◆ fillBufferRng() [2/2]

void fillBufferRng ( std::complex< VT > *  rng_reals,
size_t  number 
)

Definition at line 73 of file RandomForTest.cpp.

74 {
75  for (size_t i = 0; i < count; ++i)
76  {
77  cplx_nums->real(rng());
78  cplx_nums->imag(rng());
79  ++cplx_nums;
80  }
81 }

◆ fillVecRng() [1/2]

void fillVecRng ( std::vector< VT > &  rng_reals)

Definition at line 45 of file RandomForTest.cpp.

Referenced by TestFillVecRngReal< T >::operator()(), TestFillVecRngComplex< T >::operator()(), and qmcplusplus::randomUpdateAccumulate().

46 {
47  // until c++ std = 17
48  //std::generate(rng_reals.begin(), rng_reals.end(), rng());
49  for (auto& rng_real : rngReals)
50  rng_real = rng();
51 }

◆ fillVecRng() [2/2]

void fillVecRng ( std::vector< std::complex< VT >> &  rng_reals)

Definition at line 54 of file RandomForTest.cpp.

55 {
56  // until c++ std = 17
57  //std::generate(rng_reals.begin(), rng_reals.end(), rng());
58  for (auto& cplx_num : cplx_nums)
59  cplx_num = std::complex<VT>{rng(), rng()};
60 }

◆ getRngVec()

std::vector< VT > getRngVec ( int  ncount)

Definition at line 26 of file RandomForTest.cpp.

Referenced by TestGetVecRngReal< T >::operator()().

27 {
28  std::vector<VT> rng_reals;
29  rng_reals.reserve(ncount);
30  std::generate_n(std::back_inserter(rng_reals), ncount, rng);
31  return rng_reals;
32 }

◆ getRngVecComplex()

std::vector< std::complex< VT > > getRngVecComplex ( int  ncount)

Definition at line 35 of file RandomForTest.cpp.

Referenced by TestGetVecRngComplex< T >::operator()().

36 {
37  std::vector<std::complex<VT>> rngs_cplx(ncount);
38  for( auto& rng_cplx : rngs_cplx)
39  rng_cplx = {rng(), rng()};
40  return rngs_cplx;
41 }

◆ operator()()

VT operator() ( )

Definition at line 84 of file RandomForTest.cpp.

85 {
86  return rng();
87 }

Member Data Documentation

◆ rng

StdRandom<VT> rng
private

Definition at line 43 of file RandomForTest.h.


The documentation for this class was generated from the following files: