cMHN 1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
seq.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_RANDOM_SEQ_H
4#define pRC_CORE_RANDOM_SEQ_H
5
7
8namespace pRC
9{
10 template<Size S>
11 requires IsSame<Seed, std::uint32_t>
13 {
14 public:
16
17 static constexpr auto size()
18 {
19 return S;
20 }
21
22 public:
23 template<IsConvertible<Seed>... Xs>
24 constexpr SeedSequence(Xs &&...seeds)
25 : mSeed(forward<Xs>(seeds)...)
26 {
27 }
28
29 template<Size N>
30 constexpr auto generate() const
31 {
33 for(Size i = 0; i < N; ++i)
34 {
35 out[i] = 0x8b8b8b8bU;
36 }
37
38 constexpr Size t = (N >= 623) ? 11
39 : (N >= 68) ? 7
40 : (N >= 39) ? 5
41 : (N >= 7) ? 3
42 : (N - 1) / 2;
43 constexpr Size p = (N - t) / 2;
44 constexpr Size q = p + t;
45 constexpr Size m = max(S + 1, N);
46
47 auto const T = [&out, &p](auto const k)
48 {
49 Seed const arg =
50 out[k % N] ^ out[(k + p) % N] ^ out[(k - 1) % N];
51 return arg ^ (arg >> 27);
52 };
53
54 for(Size k = 0; k < m; ++k)
55 {
56 Seed const r1 = 1664525U * T(k);
57 Seed const r2 = r1 +
58 [&]()
59 {
60 if(k == 0)
61 {
62 return S;
63 }
64 else if(k <= S)
65 {
66 return k % N + mSeed[k - 1];
67 }
68 else
69 {
70 return k % N;
71 }
72 }();
73
74 out[(k + p) % N] += r1;
75 out[(k + q) % N] += r2;
76 out[k % N] = r2;
77 }
78
79 for(Size k = m; k < m + N; ++k)
80 {
81 Seed const r3 = 1566083941U * T(k);
82 Seed const r4 = r3 - k % N;
83
84 out[(k + p) % N] ^= r3;
85 out[(k + q) % N] ^= r4;
86 out[k % N] = r4;
87 }
88
89 return out;
90 }
91
92 constexpr auto &param() const
93 {
94 return mSeed;
95 }
96
97 private:
98 BEGIN_IGNORE_DIAGNOSTIC_GCC("-Wpedantic")
99 StackArray<Seed, S> mSeed;
101 };
102
103 template<class... Ts>
104 SeedSequence(Ts &&...) -> SeedSequence<sizeof...(Ts)>;
105}
106#endif // pRC_CORE_RANDOM_SEQ_H
Definition declarations.hpp:12
Definition value.hpp:12
Definition seq.hpp:13
constexpr auto generate() const
Definition seq.hpp:30
static constexpr auto size()
Definition seq.hpp:17
constexpr SeedSequence(Xs &&...seeds)
Definition seq.hpp:24
Seed result_type
Definition seq.hpp:15
constexpr auto & param() const
Definition seq.hpp:92
TN::Subscripts S
Definition externs_nonTT.hpp:9
pRC::Float<> T
Definition externs_nonTT.hpp:1
int i
Definition gmock-matchers-comparisons_test.cc:603
const char * p
Definition gmock-matchers-containers_test.cc:379
Definition cholesky.hpp:10
std::uint32_t Seed
Definition basics.hpp:33
std::size_t Size
Definition basics.hpp:31
static constexpr auto arg(T const &a)
Definition arg.hpp:11
static constexpr decltype(auto) max(X &&a)
Definition max.hpp:13
#define BEGIN_IGNORE_DIAGNOSTIC_GCC(warning)
Definition pragma.hpp:42
#define END_IGNORE_DIAGNOSTIC_GCC
Definition pragma.hpp:43