32 #ifndef VSMC_RNG_U01_SEQUENCE_HPP 33 #define VSMC_RNG_U01_SEQUENCE_HPP 38 #define VSMC_RUNTIME_ASSERT_RNG_U01_SEQUENCE(Method) \ 39 VSMC_RUNTIME_ASSERT((n < N_ && (n == n_ || n == n_ + 1 || n_ == N_)), \ 40 "**U01Sequence" #Method "::operator[]** INVALID INDEX") 48 template <std::
size_t K,
typename RealType>
50 const RealType *
u01, RealType *r, std::size_t N, RealType &lmax)
57 std::size_t m = N - n0;
59 for (std::size_t i = n0; i != n; ++i, ++j, --m) {
63 exp(n - n0, s.data(), s.data());
64 sub(n - n0, static_cast<RealType>(1), s.data(), r);
67 template <std::
size_t K,
typename RealType,
typename RNGType>
69 RealType *r, std::size_t N, RealType &lmax)
75 u01_trans_sorted_impl<K>(n0, n, r, r, N, lmax);
78 template <
typename RealType>
80 const RealType *
u01, RealType *r, RealType delta)
86 for (std::size_t i = n0; i != n; ++i, ++j)
87 r[j] = u01[j] + static_cast<RealType>(i);
88 mul(n - n0, delta, r, r);
91 template <
typename RealType,
typename RNGType>
93 RNGType &rng, std::size_t n0, std::size_t n, RealType *r, RealType delta)
102 template <
typename RealType>
104 std::size_t n0, std::size_t n, RealType u, RealType *r, RealType delta)
110 for (std::size_t i = n0; i != n; ++i, ++j)
111 r[j] = static_cast<RealType>(i);
112 fma(n - n0, r, delta, u, r);
120 template <
typename RealType>
123 static_assert(std::is_floating_point<RealType>::value,
124 "**u01_trans_sorted** USED WITH RealType OTHER THAN FLOATING POINT " 133 std::copy_n(u01, N, r);
138 const std::size_t m = N / k;
141 for (std::size_t i = 0; i != m; ++i, n0 += k, u01 += k, r += k)
142 internal::u01_trans_sorted_impl<k>(n0, n0 + k, u01, r, N, lmax);
143 internal::u01_trans_sorted_impl<k>(n0, N,
u01, r, N, lmax);
149 template <
typename RealType>
151 std::size_t N,
const RealType *
u01, RealType *r)
153 static_assert(std::is_floating_point<RealType>::value,
154 "**u01_trans_stratified** USED WITH RealType OTHER THAN FLOATING " 161 const std::size_t m = N / k;
163 const RealType delta = 1 /
static_cast<RealType
>(N);
164 for (std::size_t i = 0; i != m; ++i, n0 += k, u01 += k, r += k)
172 template <
typename RealType>
174 std::size_t N,
const RealType *
u01, RealType *r)
176 static_assert(std::is_floating_point<RealType>::value,
177 "**u01_trans_systematic** USED WITH RealType OTHER THAN FLOATING " 184 const std::size_t m = N / k;
186 const RealType delta = 1 /
static_cast<RealType
>(N);
187 const RealType u = u01[0] * delta;
188 for (std::size_t i = 0; i != m; ++i, n0 += k, r += k)
195 template <
typename RealType,
typename RNGType>
198 static_assert(std::is_floating_point<RealType>::value,
199 "**u01_rand_sorted** USED WITH RealType OTHER THAN FLOATING POINT " 212 const std::size_t m = N / k;
215 for (std::size_t i = 0; i != m; ++i, n0 += k, r += k)
216 internal::u01_rand_sorted_impl<k>(rng, n0, n0 + k, r, N, lmax);
217 internal::u01_rand_sorted_impl<k>(rng, n0, N, r, N, lmax);
222 template <
typename RealType,
typename RNGType>
225 static_assert(std::is_floating_point<RealType>::value,
226 "**u01_rand_stratified** USED WITH RealType OTHER THAN FLOATING POINT " 230 const std::size_t m = N / k;
232 const RealType delta = 1 /
static_cast<RealType
>(N);
233 for (std::size_t i = 0; i != m; ++i, n0 += k, r += k)
240 template <
typename RealType,
typename RNGType>
243 static_assert(std::is_floating_point<RealType>::value,
244 "**u01_rand_systematic** USED WITH RealType OTHER THAN FLOATING POINT " 248 RealType
u01 = ru01(rng);
257 template <
typename RealType>
263 template <
typename RealType,
typename RNG>
275 template <
typename RealType>
281 template <
typename RealType,
typename RNG>
293 template <
typename RealType>
299 template <
typename RealType,
typename RNG>
308 #endif // VSMC_RNG_U01_SEQUENCE_HPP
void mul(std::size_t n, const float *a, const float *b, float *y)
Stratified standard uniform numbers.
void operator()(std::size_t N, const RealType *u01, RealType *r) const
void operator()(RNG &rng, std::size_t N, RealType *r) const
void operator()(RNG &rng, std::size_t N, RealType *r) const
Systematic standard uniform numbers.
Counter based RNG engine.
void u01_trans_systematic(std::size_t N, const RealType *u01, RealType *r)
Transform a single standard uniform random number to a systematic sequence.
void u01_distribution(RNGType &, std::size_t, RealType *)
Generate standard uniform random variates.
void u01_trans_systematic_impl(std::size_t n0, std::size_t n, RealType u, RealType *r, RealType delta)
void u01_trans_stratified_impl(std::size_t n0, std::size_t n, const RealType *u01, RealType *r, RealType delta)
void u01_trans_sorted(std::size_t N, const RealType *u01, RealType *r)
Tranform a sequence of standard uniform random numbers to sorted sequence.
RealType u01(UIntType u) noexcept
Convert uniform unsigned integers to floating points within [0, 1].
void u01_rand_sorted(RNGType &rng, std::size_t N, RealType *r)
Generate sorted standard uniform numbers with cost.
void operator()(std::size_t N, const RealType *u01, RealType *r) const
void exp(std::size_t n, const float *a, float *y)
Sorted of standard uniform numbers.
void u01_rand_stratified(RNGType &rng, std::size_t N, RealType *r)
Generate stratified standard uniform numbers.
void sub(std::size_t n, const float *a, const float *b, float *y)
void fma(std::size_t n, const T *a, const T *b, const T *c, T *y)
For , compute .
void u01_rand_sorted_impl(RNGType &rng, std::size_t n0, std::size_t n, RealType *r, std::size_t N, RealType &lmax)
void u01_trans_stratified(std::size_t N, const RealType *u01, RealType *r)
Transform a sequence of standard uniform random numbers to a stratified sequence. ...
void u01_rand_systematic(RNGType &rng, std::size_t N, RealType *r)
Generate systematic standard uniform numbers.
void operator()(RNG &rng, std::size_t N, RealType *r) const
std::array with proper alignment
void u01_trans_sorted_impl(std::size_t n0, std::size_t n, const RealType *u01, RealType *r, std::size_t N, RealType &lmax)
void operator()(std::size_t N, const RealType *u01, RealType *r) const
void u01_rand_stratified_impl(RNGType &rng, std::size_t n0, std::size_t n, RealType *r, RealType delta)
void log(std::size_t n, const float *a, float *y)