32 #ifndef MCKL_RANDOM_SERIAL_TEST_HPP 33 #define MCKL_RANDOM_SERIAL_TEST_HPP 41 template <std::
size_t, std::
size_t,
bool>
44 template <std::
size_t D, std::
size_t T>
48 static_assert(D > 1,
"**SerialTest** used with D less than 2");
50 static_assert(T > 0,
"**SerialTest** used with T equal to zero");
54 : n_(n), np_(static_cast<double>(n) / M_), count_(M_)
60 template <
typename RNGType,
typename U01DistributionType>
63 using result_type =
typename U01DistributionType::result_type;
65 std::fill(count_.begin(), count_.end(), 0);
68 const std::size_t m = n_ / k;
69 const std::size_t l = n_ % k;
71 for (std::size_t i = 0; i != m; ++i) {
72 generate(rng, u01, k, r.data());
74 generate(rng, u01, l, r.data());
76 return this->stat(M_, count_.data(), np_);
88 template <
typename RNGType,
typename U01DistributionType>
89 void generate(RNGType &rng, U01DistributionType &
u01, std::size_t n,
90 typename U01DistributionType::result_type *r)
92 rand(rng, u01, n * T, r);
93 mul(n * T, static_cast<typename U01DistributionType::result_type>(D),
95 for (std::size_t i = 0; i != n; ++i, r += T) {
96 count_[serial_index<D, T>(r)] += 1;
101 template <std::
size_t D, std::
size_t T>
105 static_assert(D > 1,
"**SerialOverTest** used with D less than 2");
107 static_assert(T > 1,
"**SerialOverTest** used with T less than 2");
112 , np1_(static_cast<double>(n) / M1_)
113 , np2_(static_cast<double>(n) / M2_)
118 n >= T,
"**SerialTest** constructed with n less then T");
123 template <
typename RNGType,
typename U01DistributionType>
126 using result_type =
typename U01DistributionType::result_type;
128 std::fill(count1_.begin(), count1_.end(), 0);
129 std::fill(count2_.begin(), count2_.end(), 0);
133 std::array<result_type, T> rhead;
134 std::array<result_type, T> rtail;
137 rand(rng, u01, k, r.data());
138 mul(k, static_cast<result_type>(D), r.data(), r.data());
139 std::memcpy(rhead.data(), r.data(),
sizeof(
result_type) * T);
140 std::memcpy(rtail.data(), r.data(),
sizeof(
result_type) * T);
143 cidx_ = serial_index<D, T>(rhead.data());
146 std::size_t uidx = T;
147 for (std::size_t i = 0; i != n_ - T + 1; ++i) {
149 rand(rng, u01, k, r.data());
150 mul(k, static_cast<result_type>(D), r.data(), r.data());
154 generate(u, rtail.data());
159 for (std::size_t i = n_ - T + 1; i != n_; ++i) {
161 generate(u, rtail.data());
164 double s1 = this->stat(M1_, count1_.data(), np1_);
165 double s2 = this->stat(M2_, count2_.data(), np2_);
174 static constexpr std::size_t M2_ =
Pow<std::size_t, D, T - 1>::value;
185 template <
typename ResultType>
186 void generate(ResultType u, ResultType *rtail)
188 cidx_ -=
Pow<std::size_t, D, T - 1>::value *
189 static_cast<std::size_t
>(rtail[head_]);
191 head_ = (head_ + 1) % T;
192 tail_ = (tail_ + 1) % T;
194 cidx_ = cidx_ * D +
static_cast<std::size_t
>(u);
207 template <std::
size_t D, std::
size_t T,
bool Overlap>
212 #endif // MCKL_RANDOM_SERIAL_TEST_HPP void mul(std::size_t n, const float *a, const float *b, float *y)
double degree_of_freedom() const
double degree_of_freedom() const
std::vector< T, Alloc > Vector
std::vector with Allocator as the default allocator
SerialTestImpl(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)
double operator()(RNGType &rng, U01DistributionType &u01)
double operator()(RNGType &rng, U01DistributionType &u01)
SerialTestImpl(std::size_t n)
void rand(RNGType &rng, ArcsineDistribution< RealType > &distribution, std::size_t N, RealType *r)
Tests based on the -distribution.
void runtime_assert(bool cond, const char *msg, bool soft=false)