QMCPACK
RandomForTest.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2021 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
8 //
9 // File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include "RandomForTest.h"
13 #include <algorithm>
14 
15 namespace qmcplusplus
16 {
17 namespace testing
18 {
19 template<typename VT>
21 {
22  rng.init(111);
23 }
24 
25 template<typename VT>
26 std::vector<VT> RandomForTest<VT>::getRngVec(int ncount)
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 }
33 
34 template<typename VT>
35 std::vector<std::complex<VT>> RandomForTest<VT>::getRngVecComplex(int ncount)
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 }
42 
43 
44 template<typename VT>
45 void RandomForTest<VT>::fillVecRng(std::vector<VT>& rngReals)
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 }
52 
53 template<typename VT>
54 void RandomForTest<VT>::fillVecRng(std::vector<std::complex<VT>>& cplx_nums)
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 }
61 
62 template<typename VT>
63 void RandomForTest<VT>::fillBufferRng(VT* rng_reals, size_t count)
64 {
65  for (size_t ir = 0; ir < count; ++ir)
66  {
67  *rng_reals = rng();
68  ++rng_reals;
69  }
70 }
71 
72 template<typename VT>
73 void RandomForTest<VT>::fillBufferRng(std::complex<VT>* cplx_nums, size_t count)
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 }
82 
83 template<typename VT>
85 {
86  return rng();
87 }
88 
89 template class RandomForTest<double>;
90 template class RandomForTest<float>;
91 } // namespace testing
92 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::vector< std::complex< VT > > getRngVecComplex(int ncount)
void fillBufferRng(VT *rng_reals, size_t number)
Get a known sequence of random numbers for testing.
Definition: RandomForTest.h:31
void fillVecRng(std::vector< VT > &rng_reals)
std::vector< VT > getRngVec(int ncount)