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>
68 return -std::numeric_limits<result_type>::max
VSMC_MNE();
73 return std::numeric_limits<result_type>::max
VSMC_MNE();
79 template <
typename RNGType>
85 return u > 0 ? param.
a() - param.
b() *
std::log(1 - 2 * u) :
93 template <std::
size_t K,
typename RealType,
typename RNGType>
95 RNGType &rng, std::size_t n, RealType *r, RealType a, RealType b)
99 sub(n, r, static_cast<RealType>(0.5), r);
100 for (std::size_t i = 0; i != n; ++i) {
117 template <
typename RealType,
typename RNGType>
119 RNGType &rng, std::size_t n, RealType *r, RealType a, RealType b)
121 const std::size_t k = 1000;
122 const std::size_t m = n / k;
123 const std::size_t l = n % k;
124 for (std::size_t i = 0; i != m; ++i)
125 internal::laplace_distribution_impl<k>(rng, k, r + i * k, a, b);
126 internal::laplace_distribution_impl<k>(rng, l, r + m * k, a, b);
129 template <
typename RealType,
typename RNGType>
131 std::size_t n, RealType *r)
138 #endif // VSMC_RNG_LAPLACE_DISTRIBUTION_HPP
Standard uniform distribution with open/closed variants.
bool laplace_distribution_check_param(RealType, RealType b)
void laplace_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating laplace random variates.
void rng_rand(RNGType &rng, BernoulliDistribution< IntType > &dist, std::size_t n, IntType *r)
#define VSMC_DEFINE_RNG_DISTRIBUTION_OPERATORS
#define VSMC_DEFINE_RNG_DISTRIBUTION_2(Name, name, T, T1, p1, v1, T2, p2, v2)
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 .
void u01_oc_distribution(RNGType &rng, std::size_t n, RealType *r)
Generate standard uniform random variates on open-closed interval.
void log(std::size_t n, const float *a, float *y)