32 #ifndef VSMC_RNG_UNIFORM_REAL_DISTRIBUTION_HPP 33 #define VSMC_RNG_UNIFORM_REAL_DISTRIBUTION_HPP 38 #define VSMC_RUNTIME_ASSERT_RNG_UNIFORM_REAL_DISTRIBUTION_PARAM_CHECK(a, b) \ 39 VSMC_RUNTIME_ASSERT((a <= b), "**UniformRealDistribution** CONSTRUCTED " \ 40 "WITH INVALID MINIMUM AND MAXIMUM " \ 52 template <
typename RealType,
typename Left,
typename Right>
53 class UniformRealLRDistribution
87 return !(param1 == param2);
90 template <
typename CharT,
typename Traits>
92 std::basic_ostream<CharT, Traits> &os,
const param_type ¶m)
97 os << param.a_ <<
' ';
103 template <
typename CharT,
typename Traits>
105 std::basic_istream<CharT, Traits> &is,
param_type ¶m)
119 is.setstate(std::ios_base::failbit);
157 template <
typename RNGType>
163 template <
typename RNGType>
168 return param.
a() + (param.
b() - param.
a()) * u01(rng);
171 template <
typename RNGType>
177 template <
typename RNGType>
181 uniform_real_lr_distribution<RealType, Left, Right>(
182 rng, n, r, param.
a(), param.
b());
193 template <
typename RealType =
double>
199 template <
typename RealType =
double>
205 template <
typename RealType =
double>
211 template <
typename RealType =
double>
216 template <
typename RealType =
double>
222 template <
typename RealType,
typename Left,
typename Right,
typename RNGType>
224 RNGType &rng, std::size_t n, RealType *r, RealType
a, RealType
b)
226 u01_lr_distribution<RealType, Left, Right>(rng, n, r);
227 fma(n, (b - a), r, a, r);
234 template <
typename RealType,
typename Left,
typename Right,
typename RNGType>
236 RNGType &rng, std::size_t n, RealType *r, RealType
a, RealType
b)
238 const std::size_t k = 1000;
239 const std::size_t m = n / k;
240 const std::size_t l = n % k;
241 for (std::size_t i = 0; i != m; ++i) {
242 internal::uniform_real_lr_distribution_impl<RealType, Left, Right>(
243 rng, k, r + i * k,
a,
b);
245 internal::uniform_real_lr_distribution_impl<RealType, Left, Right>(
246 rng, l, r + m * k,
a,
b);
251 template <
typename RealType,
typename RNGType>
253 RNGType &rng, std::size_t n, RealType *r, RealType
a, RealType
b)
255 uniform_real_lr_distribution<RealType, Closed, Closed>(rng, n, r,
a,
b);
260 template <
typename RealType,
typename RNGType>
262 RNGType &rng, std::size_t n, RealType *r, RealType
a, RealType
b)
264 uniform_real_lr_distribution<RealType, Closed, Open>(rng, n, r,
a,
b);
269 template <
typename RealType,
typename RNGType>
271 RNGType &rng, std::size_t n, RealType *r, RealType
a, RealType
b)
273 uniform_real_lr_distribution<RealType, Open, Closed>(rng, n, r,
a,
b);
278 template <
typename RealType,
typename RNGType>
280 RNGType &rng, std::size_t n, RealType *r, RealType
a, RealType
b)
282 uniform_real_lr_distribution<RealType, Open, Open>(rng, n, r,
a,
b);
287 template <
typename RealType,
typename RNGType>
289 RNGType &rng, std::size_t n, RealType *r, RealType
a, RealType
b)
294 template <
typename RealType,
typename RNGType,
typename Left,
typename Right>
304 #endif // VSMC_RNG_UNIFORM_REAL_DISTRIBUTION_HPP
Standard uniform distribution with open/closed variants.
bool is_equal(const T &a, const T &b)
void rng_rand(RNGType &rng, BernoulliDistribution< IntType > &dist, std::size_t n, IntType *r)
void uniform_real_lr_distribution_impl(RNGType &rng, std::size_t n, RealType *r, RealType a, RealType b)
#define VSMC_DEFINE_RNG_DISTRIBUTION_OPERATORS
void uniform_real_oo_distribution(RNGType &rng, std::size_t n, RealType *r, RealType a, RealType b)
Generate uniform real random variates on open-open interval.
void uniform_real_cc_distribution(RNGType &rng, std::size_t n, RealType *r, RealType a, RealType b)
Generate uniform real random variates on closed-closed interval.
void uniform_real_oc_distribution(RNGType &rng, std::size_t n, RealType *r, RealType a, RealType b)
Generate uniform real random variates on open-closed interval.
void uniform_real_lr_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generate uniform real random variates with open/closed variants.
void uniform_real_co_distribution(RNGType &rng, std::size_t n, RealType *r, RealType a, RealType b)
Generate uniform real random variates on closed-open interval.
void fma(std::size_t n, const T *a, const T *b, const T *c, T *y)
For , compute .
void uniform_real_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generate uniform real random variates.