Skip to content

Commit d2327d5

Browse files
committed
QPR-12140 updates from quantlib PR
1 parent 2363393 commit d2327d5

4 files changed

Lines changed: 26 additions & 15 deletions

File tree

ql/math/randomnumbers/burley2020sobolrsg.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ namespace QuantLib {
7474
119u, 247u, 15u, 143u, 79u, 207u, 47u, 175u, 111u, 239u, 31u, 159u, 95u, 223u,
7575
63u, 191u, 127u, 255u};
7676

77-
std::uint32_t reverseBits(std::uint32_t x) {
77+
inline std::uint32_t reverseBits(std::uint32_t x) {
7878
return (bitReverseTable[x & 0xff] << 24) | (bitReverseTable[(x >> 8) & 0xff] << 16) |
7979
(bitReverseTable[(x >> 16) & 0xff] << 8) | (bitReverseTable[(x >> 24) & 0xff]);
8080
}
8181

82-
std::uint32_t laine_karras_permutation(std::uint32_t x, std::uint32_t seed) {
82+
inline std::uint32_t laine_karras_permutation(std::uint32_t x, std::uint32_t seed) {
8383
x += seed;
8484
x ^= x * 0x6c50b47cu;
8585
x ^= x * 0xb82f1e52u;
@@ -88,26 +88,38 @@ namespace QuantLib {
8888
return x;
8989
}
9090

91-
std::uint32_t nested_uniform_scramble(std::uint32_t x, std::uint32_t seed) {
91+
inline std::uint32_t nested_uniform_scramble(std::uint32_t x, std::uint32_t seed) {
9292
x = reverseBits(x);
9393
x = laine_karras_permutation(x, seed);
9494
x = reverseBits(x);
9595
return x;
9696
}
9797

9898
// the results depend a lot on the details of the hash_combine() function that is used
99-
// we use the 64bit version of hash_combine() as it is implemented here:
99+
// we use hash_combine() calling hash(), hash_mix() as implemented here:
100100
// https://github.com/boostorg/container_hash/blob/boost-1.83.0/include/boost/container_hash/hash.hpp#L560
101+
// https://github.com/boostorg/container_hash/blob/boost-1.83.0/include/boost/container_hash/hash.hpp#L115
101102
// https://github.com/boostorg/container_hash/blob/boost-1.83.0/include/boost/container_hash/detail/hash_mix.hpp#L67
102103

103-
void local_hash_combine(std::uint64_t& x, const uint64_t v) {
104+
inline std::uint64_t local_hash_mix(std::uint64_t x) {
104105
const std::uint64_t m = 0xe9846af9b1a615d;
105-
x += 0x9e3779b9 + std::hash<std::uint64_t>()(v);
106106
x ^= x >> 32;
107107
x *= m;
108108
x ^= x >> 32;
109109
x *= m;
110110
x ^= x >> 28;
111+
return x;
112+
}
113+
114+
inline std::uint64_t local_hash(const std::uint64_t v) {
115+
std::uint64_t seed = 0;
116+
seed = (v >> 32) + local_hash_mix(seed);
117+
seed = (v & 0xFFFFFFFF) + local_hash_mix(seed);
118+
return seed;
119+
}
120+
121+
inline std::uint64_t local_hash_combine(std::uint64_t x, const uint64_t v) {
122+
return local_hash_mix(x + 0x9e3779b9 + local_hash(v));
111123
}
112124
}
113125

@@ -119,7 +131,7 @@ namespace QuantLib {
119131
do {
120132
std::uint64_t seed = group4Seeds_[group++];
121133
for (Size g = 0; g < 4 && i < dimensionality_; ++g, ++i) {
122-
local_hash_combine(seed, g);
134+
seed = local_hash_combine(seed, g);
123135
integerSequence_[i] =
124136
nested_uniform_scramble(integerSequence_[i], static_cast<std::uint32_t>(seed));
125137
}

ql/math/randomnumbers/burley2020sobolrsg.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
FOR A PARTICULAR PURPOSE. See the license for more details.
1818
*/
1919

20-
/*! \file burley2020scrambling.hpp
20+
/*! \file burley2020sobolrsg.hpp
2121
\brief scrambled Sobol sequence following Burley, 2020
2222
*/
2323

ql/math/randomnumbers/sobolrsg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78793,7 +78793,7 @@ namespace QuantLib {
7879378793
}
7879478794
}
7879578795
} else {
78796-
std::fill(integerSequence_.begin(), integerSequence_.end(), 0.0);
78796+
std::fill(integerSequence_.begin(), integerSequence_.end(), 0u);
7879778797
std::uint_least32_t mask = 1;
7879878798
for (Size index = 0; index < bits_; index++) {
7879978799
if ((N & mask) != 0U) {

ql/models/marketmodels/browniangenerators/sobolbrowniangenerator.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ namespace QuantLib {
9191

9292
class SobolBrownianGeneratorFactory : public BrownianGeneratorFactory {
9393
public:
94-
SobolBrownianGeneratorFactory(
95-
SobolBrownianGenerator::Ordering ordering,
96-
unsigned long seed = 0,
97-
SobolRsg::DirectionIntegers directionIntegers
98-
= SobolRsg::Jaeckel);
94+
explicit SobolBrownianGeneratorFactory(
95+
SobolBrownianGenerator::Ordering ordering,
96+
unsigned long seed = 0,
97+
SobolRsg::DirectionIntegers directionIntegers = SobolRsg::Jaeckel);
9998
ext::shared_ptr<BrownianGenerator> create(Size factors, Size steps) const override;
10099

101100
private:
@@ -121,7 +120,7 @@ namespace QuantLib {
121120

122121
class Burley2020SobolBrownianGeneratorFactory : public BrownianGeneratorFactory {
123122
public:
124-
Burley2020SobolBrownianGeneratorFactory(
123+
explicit Burley2020SobolBrownianGeneratorFactory(
125124
SobolBrownianGenerator::Ordering ordering,
126125
unsigned long seed = 42,
127126
SobolRsg::DirectionIntegers directionIntegers = SobolRsg::Jaeckel,

0 commit comments

Comments
 (0)