32 #ifndef VSMC_RNG_LAPLACE_DISTRIBUTION_HPP 33 #define VSMC_RNG_LAPLACE_DISTRIBUTION_HPP 38 #define VSMC_RUNTIME_ASSERT_RNG_LAPLACE_DISTRIBUTION_PARAM_CHECK(b) \ 39 VSMC_RUNTIME_ASSERT((b > 0), "**LaplaceDistribution** CONSTRUCTED " \ 40 "WITH INVALID SCALE PARAMETER VALUE") 48 template <
typename RealType>
58 template <
typename RealType>
66 return std::numeric_limits<result_type>::lowest();
74 template <
typename RNGType>
80 return u > 0 ? param.
a() - param.
b() *
std::log(1 - 2 * u) :
88 template <std::
size_t K,
typename RealType,
typename RNGType>
90 RNGType &rng, std::size_t n, RealType *r, RealType a, RealType b)
94 sub(n, r, static_cast<RealType>(0.5), r);
95 for (std::size_t i = 0; i != n; ++i) {
112 template <
typename RealType,
typename RNGType>
114 RNGType &rng, std::size_t n, RealType *r, RealType a, RealType b)
116 static_assert(std::is_floating_point<RealType>::value,
117 "**laplace_distribution** USED WITH RealType OTHER THAN FLOATING " 120 const std::size_t k = 1024;
121 const std::size_t m = n / k;
122 const std::size_t l = n % k;
123 for (std::size_t i = 0; i != m; ++i, r += k)
124 internal::laplace_distribution_impl<k>(rng, k, r, a, b);
125 internal::laplace_distribution_impl<k>(rng, l, r, a, b);
132 #endif // VSMC_RNG_LAPLACE_DISTRIBUTION_HPP
bool laplace_distribution_check_param(RealType, RealType b)
#define VSMC_DEFINE_RNG_DISTRIBUTION_2(Name, name, p1, v1, p2, v2)
void laplace_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating laplace random variates.
void u01_distribution(RNGType &, std::size_t, RealType *)
Generate standard uniform random variates.
void laplace_distribution_impl(RNGType &rng, std::size_t n, RealType *r, RealType a, RealType b)
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 .
Standard uniform distribution.
#define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_2(Name, name, p1, p2)
void log(std::size_t n, const float *a, float *y)