@@ -35,7 +35,6 @@ namespace QuantLib {
3535 MersenneTwisterUniformRng mt (scrambleSeed);
3636 for (auto & s : group4Seeds_) {
3737 s = static_cast <std::uint32_t >(mt.nextInt32 ());
38- std::cout << " setting group seed " << s << std::endl;
3938 }
4039 }
4140
@@ -80,14 +79,6 @@ namespace QuantLib {
8079 std::uint32_t reverseBits (std::uint32_t x) {
8180 return (bitReverseTable[x & 0xff ] << 24 ) | (bitReverseTable[(x >> 8 ) & 0xff ] << 16 ) |
8281 (bitReverseTable[(x >> 16 ) & 0xff ] << 8 ) | (bitReverseTable[(x >> 24 ) & 0xff ]);
83- // std::uint32_t y;
84- // unsigned char* p = (unsigned char*)(&x);
85- // unsigned char* q = (unsigned char*)(&y);
86- // q[3] = bitReverseTable[p[0]];
87- // q[2] = bitReverseTable[p[1]];
88- // q[1] = bitReverseTable[p[2]];
89- // q[0] = bitReverseTable[p[3]];
90- // return y;
9182 }
9283
9384 std::uint32_t laine_karras_permutation (std::uint32_t x, std::uint32_t seed) {
@@ -106,25 +97,33 @@ namespace QuantLib {
10697 return x;
10798 }
10899
100+ // the results depend a lot on the details of the hash_combine() function that is used
101+ // we use the 64bit version of hash_combine() as it is implemented here:
102+ // https://github.com/boostorg/container_hash/blob/boost-1.83.0/include/boost/container_hash/hash.hpp#L560
103+ // https://github.com/boostorg/container_hash/blob/boost-1.83.0/include/boost/container_hash/detail/hash_mix.hpp#L67
104+
105+ void local_hash_combine (std::uint64_t & x, const uint64_t v) {
106+ const std::uint64_t m = 0xe9846af9b1a615d ;
107+ x += 0x9e3779b9 + std::hash<std::uint64_t >()(v);
108+ x ^= x >> 32 ;
109+ x *= m;
110+ x ^= x >> 32 ;
111+ x *= m;
112+ x ^= x >> 28 ;
113+ }
109114 }
110115
111116 const std::vector<std::uint32_t >& Burley2020SobolRsg::nextInt32Sequence () const {
112117 auto n = nested_uniform_scramble (nextSequenceCounter_, group4Seeds_[0 ]);
113118 const auto & seq = sobolRsg_->skipTo (n);
114- std::cout << " nextInt32Sequence(): nested_uniform_scramble(" << nextSequenceCounter_ << " ," << group4Seeds_[0 ] << " ) = " << n << std::endl;
115- for (auto const & s: seq)
116- std::cout << " nextInt32Sequence(): seq = " << s << std::endl;
117119 std::copy (seq.begin (), seq.end (), integerSequence_.begin ());
118120 Size i = 0 , group = 0 ;
119121 do {
120- Size seed = group4Seeds_[group++];
122+ std:: uint64_t seed = group4Seeds_[group++];
121123 for (Size g = 0 ; g < 4 && i < dimensionality_; ++g, ++i) {
122- std::cout << " nextInt32Sequence(): seed " << seed << " , nested_uniform_scramble("
123- << integerSequence_[i];
124- boost::hash_combine (seed, g);
125- integerSequence_[i] = nested_uniform_scramble (integerSequence_[i], seed);
126- std::cout << " ," << seed
127- << " ) = " << integerSequence_[i] << " (i=" << i << " )" << std::endl;
124+ local_hash_combine (seed, g);
125+ integerSequence_[i] =
126+ nested_uniform_scramble (integerSequence_[i], static_cast <std::uint32_t >(seed));
128127 }
129128 } while (i < dimensionality_);
130129 ++nextSequenceCounter_;
@@ -136,8 +135,6 @@ namespace QuantLib {
136135 // normalize to get a double in (0,1)
137136 for (Size k = 0 ; k < dimensionality_; ++k) {
138137 sequence_.value [k] = static_cast <double >(v[k]) / 4294967296.0 ;
139- std::cout << " nextSequence(): " << v[k] << " / 4294967296.0 = " << sequence_.value [k]
140- << " (k=" << k << " )" << std::endl;
141138 }
142139 return sequence_;
143140 }
0 commit comments