32 #ifndef MCKL_RANDOM_COLLISION_TEST_HPP 33 #define MCKL_RANDOM_COLLISION_TEST_HPP 52 template <std::
size_t D, std::
size_t T>
55 static_assert(D > 1,
"**CollisionTest** used with D less than two");
57 static_assert(T > 0,
"**CollisionTest** used with T equal to zero");
62 double p =
static_cast<double>(n);
63 mean_ = K_ * (p / K_ - 1 +
std::pow(1 - 1.0 / K_, p));
68 template <
typename RNGType,
typename U01DistributionType>
71 using result_type =
typename U01DistributionType::result_type;
74 const std::size_t m = n_ / k;
75 const std::size_t l = n_ % k;
79 for (std::size_t i = 0; i != m; ++i) {
80 generate(rng, u01, k, r.data(), s, occurs);
82 generate(rng, u01, l, r.data(), s, occurs);
87 double mean()
const {
return mean_; }
92 using occurs_type = std::conditional_t<K_ <= (1U << 27), std::bitset<K_>,
93 std::set<std::size_t>>;
98 template <
typename RNGType,
typename U01DistributionType>
99 void generate(RNGType &rng, U01DistributionType &
u01, std::size_t n,
100 typename U01DistributionType::result_type *r, std::size_t &s,
101 occurs_type &occurs)
const 103 rand(rng, u01, n * T, r);
104 mul(n * T, static_cast<typename U01DistributionType::result_type>(D),
106 for (std::size_t i = 0; i != n; ++i, r += T) {
107 count(internal::serial_index<D, T>(r), s, occurs);
111 void count(std::size_t u, std::size_t &s, std::bitset<K_> &occurs)
const 113 if (occurs.test(u)) {
121 std::size_t u, std::size_t &s, std::set<std::size_t> &occurs)
const 123 if (occurs.count(u)) {
133 #endif // MCKL_RANDOM_COLLISION_TEST_HPP void pow(std::size_t n, const float *a, const float *b, float *y)
void mul(std::size_t n, const float *a, const float *b, float *y)
std::size_t operator()(RNGType &rng, U01DistributionType &u01)
std::vector< T, Alloc > Vector
std::vector with Allocator as the default allocator
CollisionTest(std::size_t n)
RealType u01(UIntType u)
Convert uniform unsigned integers to floating points within [0, 1].
#define MCKL_DEFINE_RANDOM_TEST_OPERATOR(ResultType)
void rand(RNGType &rng, ArcsineDistribution< RealType > &distribution, std::size_t N, RealType *r)
Tests based on the Poisson distribution.