MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / testRandomEngineUniformChi2

Function testRandomEngineUniformChi2

test/rng_quality.cpp:90–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88
89template<typename T>
90void testRandomEngineUniformChi2(randomEngineType type) {
91 dtype ty = (dtype)dtype_traits<T>::af_type;
92
93 int elem = 256 * 1024 * 1024;
94 int steps = 256;
95 int bins = 100;
96
97 array total_hist = constant(0.0, bins, f32);
98 array expected = constant(1.0 / bins, bins, f32);
99
100 randomEngine r(type, 0);
101
102 // R> qchisq(c(5e-6, 1 - 5e-6), 99)
103 // [1] 48.68125 173.87456
104 float lower(48.68125);
105 float upper(173.87456);
106
107 bool prev_step = true;
108 bool prev_total = true;
109 for (int i = 0; i < steps; ++i) {
110 array rn_numbers = randu(elem, ty, r);
111 array step_hist = histogram(rn_numbers, bins, 0.0, 1.0);
112 step_hist = step_hist.as(f32);
113 float step_chi2 = chi2_statistic<float>(step_hist, expected);
114 if (!prev_step) {
115 EXPECT_GT(step_chi2, lower) << "at step: " << i;
116 EXPECT_LT(step_chi2, upper) << "at step: " << i;
117 }
118 prev_step = step_chi2 > lower && step_chi2 < upper;
119
120 total_hist += step_hist;
121 float total_chi2 = chi2_statistic<float>(total_hist, expected);
122 if (!prev_total) {
123 EXPECT_GT(total_chi2, lower) << "at step: " << i;
124 EXPECT_LT(total_chi2, upper) << "at step: " << i;
125 }
126 prev_total = total_chi2 > lower && total_chi2 < upper;
127 }
128}
129
130TYPED_TEST(RandomEngine, philoxRandomEngineUniformChi2) {
131 testRandomEngineUniformChi2<TypeParam>(AF_RANDOM_ENGINE_PHILOX_4X32_10);

Callers

nothing calls this directly

Calls 4

constantFunction · 0.85
randuFunction · 0.85
asMethod · 0.80
histogramFunction · 0.50

Tested by

no test coverage detected