LdsGen 1.2.6
Loading...
Searching...
No Matches
ilds.hpp
Go to the documentation of this file.
1#pragma once
2
7#include <array>
8#include <atomic>
9
10#include "lds.hpp"
11
12namespace ildsgen {
13
14 using std::array;
15
16 // Constants for magic numbers
23 constexpr unsigned int DEFAULT_SCALE = 10;
24 constexpr unsigned int MAX_REVERSE_BITS = 64;
25
32 class VdCorput : public ldsgen::GeneratorBase<VdCorput, unsigned long> {
33 unsigned long _base;
34 std::array<unsigned long, MAX_REVERSE_BITS>
35 factor_lst{};
36 static_assert(MAX_REVERSE_BITS >= sizeof(unsigned long) * 8,
37 "MAX_REVERSE_BITS must be at least the number of bits in unsigned long");
38
39 public:
46 explicit VdCorput(unsigned long base = 2, unsigned int scale = DEFAULT_SCALE)
47 : _base{base} {
48 unsigned long factor = 1;
49 unsigned int n = scale < MAX_REVERSE_BITS ? scale : MAX_REVERSE_BITS;
50 for (unsigned int i = 0; i < n; ++i) {
51 factor_lst[n - 1 - i] = factor;
52 factor *= _base;
53 }
54 }
55
68 [[nodiscard]] auto value_at(unsigned long n) const -> unsigned long {
69 return ldsgen::detail::vdc_digit_sum<unsigned long>(n, this->_base, this->factor_lst);
70 }
71 };
72
83 class Halton : public ldsgen::GeneratorBase<Halton, array<unsigned long, 2>> {
84 VdCorput vdc0;
85 VdCorput vdc1;
86
87 public:
98 explicit Halton(const std::array<unsigned long, 2>& base,
99 const std::array<unsigned int, 2>& scale)
100 : vdc0(base[0], scale[0]), vdc1(base[1], scale[1]) {}
101
112 [[nodiscard]] auto value_at(unsigned long n) const -> array<unsigned long, 2> {
113 return {this->vdc0.value_at(n), this->vdc1.value_at(n)};
114 }
115 };
116
117 // Compile-time contract checks: the integer generators satisfy the protocol concept.
120
121} // namespace ildsgen
Halton sequence generator.
Definition ilds.hpp:83
auto value_at(unsigned long n) const -> array< unsigned long, 2 >
Evaluate the integer 2D Halton point at a given index (pure, no state change)
Definition ilds.hpp:112
Halton(const std::array< unsigned long, 2 > &base, const std::array< unsigned int, 2 > &scale)
Construct a new Halton object.
Definition ilds.hpp:98
Van der Corput sequence generator.
Definition ilds.hpp:32
auto value_at(unsigned long n) const -> unsigned long
Evaluate the integer sequence value at a given index (pure, no state change)
Definition ilds.hpp:68
VdCorput(unsigned long base=2, unsigned int scale=DEFAULT_SCALE)
Construct a new VdCorput object.
Definition ilds.hpp:46
CRTP base implementing the sequence generator protocol.
Definition lds.hpp:182
Concept for the sequence generator protocol.
Definition lds.hpp:155
Low-discrepancy sequence generators with thread-safe runtime polymorphism (ldsgen).
Definition ilds.hpp:12
constexpr unsigned int DEFAULT_SCALE
Default number of digits for the Van der Corput sequence.
Definition ilds.hpp:23
constexpr unsigned int MAX_REVERSE_BITS
Definition ilds.hpp:24