1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418 | // *****************************************************************************
/*!
\file src/RNGTest/TestU01Stack.hpp
\copyright 2012-2015 J. Bakosi,
2016-2018 Los Alamos National Security, LLC.,
2019-2021 Triad National Security, LLC.
All rights reserved. See the LICENSE file for details.
\brief Stack of TestU01 RNG statistical tests
\details Stack of TestU01 RNG statistical tests
*/
// *****************************************************************************
#ifndef TestU01Stack_h
#define TestU01Stack_h
#include <vector>
#include <functional>
#include <iosfwd>
#include <map>
#include <tuple>
#include <type_traits>
#include "NoWarning/value_factory.hpp"
extern "C" {
#include <sres.h>
#include <sstring.h>
#include <sknuth.h>
#include <swalk.h>
#include <smarsa.h>
#include <scomp.h>
#include <sspectral.h>
#include <unif01.h>
#include <snpair.h>
}
#include "StatTest.hpp"
#include "TestU01Util.hpp"
#include "Tags.hpp"
#include "TaggedTuple.hpp"
#include "Options/RNG.hpp"
namespace rngtest {
//! Stack of TestU01 RNG statistical tests
class TestU01Stack {
public:
//! Constructor
explicit TestU01Stack();
//! \brief Add a statistical test to battery
//! \details Note that adding a test to the battery does not invoke the test
//! constructor, it only records the information on how to call the test
//! constructor in the future. That is it binds the constructor arguments
//! to the constructor call and records the the information so only a
//! function call "()" is necessary to instantiate it.
//! \param[in] proxy Charm++ host proxy to which the test calls back to
//! \param[in] tests Vector of test constructors to add tests to
//! \param[in] r RNG ID enum
//! \param[in] gen Raw function pointer to TestU01 statistical test
//! \param[in] names Vector of statisical test names (can be more than one
//! associated with a given test, since a test can contain more than one
//! statistical test evaluation, yielding multiple p-values)
//! \param[in] xargs Extra arguments to test-run
template< class TestType, class Proxy, typename... Ts >
void add( Proxy& proxy,
std::vector< std::function< StatTest() > >& tests,
tk::ctr::RNGType r,
unif01_Gen* const gen,
std::vector< std::string >&& names,
Ts&&... xargs ) const
{
using Model = TestType;
using Host = StatTest;
using Props = typename TestType::Props;
tests.emplace_back(<--- Return value of function std::bind() is not used.
std::bind( boost::value_factory< Host >(),
std::function< Model() >(),
std::forward< Props >(
Props( proxy, r, std::move(names), gen,
std::forward<Ts>(xargs)... ) ) ) );
}
/** @name Stack of TestU01 statistical tests wrappers
* */
///@{
static std::vector< double >
BirthdaySpacings( unif01_Gen* gen, sres_Poisson* res,
const std::tuple<long, long, int, long, int, int>& xargs );
static std::vector< double >
Collision( unif01_Gen* gen, sknuth_Res2* res,
const std::tuple<long, long, int, long, int>& xargs );
static std::vector< double >
Gap( unif01_Gen* gen, sres_Chi2* res,
const std::tuple<long, long, int, double, double>& xargs );
static std::vector< double >
SimplePoker( unif01_Gen* gen, sres_Chi2* res,
const std::tuple<long, long, int, int, int>& xargs );
static std::vector< double >
CouponCollector( unif01_Gen* gen, sres_Chi2* res,
const std::tuple<long, long, int, int>& xargs );
static std::vector< double >
MaxOft( unif01_Gen* gen, sknuth_Res1* res,
const std::tuple<long, long, int, int, int, int, int>& xargs );
static std::vector< double >
WeightDistrib( unif01_Gen* gen, sres_Chi2* res,
const std::tuple<long, long, int, long, double, double>& xargs );
static std::vector< double >
MatrixRank( unif01_Gen* gen, sres_Chi2* res,
const std::tuple<long, long, int, int, int, int>& xargs );
static std::vector< double >
HammingIndep( unif01_Gen* gen, sstring_Res* res,
const std::tuple<long, long, int, int, int, int>& xargs );
static std::vector< double >
RandomWalk1( unif01_Gen* gen, swalk_Res* res,
const std::tuple<long, long, int, int, long, long>& xargs );
static std::vector< double >
SerialOver( unif01_Gen* gen, sres_Basic* res,
const std::tuple<long, long, int, long, int>& xargs );
static std::vector< double >
CollisionOver( unif01_Gen* gen, smarsa_Res* res,
const std::tuple<long, long, int, long, int>& xargs );
static std::vector< double >
ClosePairs( unif01_Gen* gen, snpair_Res* res,
const std::tuple<long, long, int, int, int, int, int>& xargs );
static std::vector< double >
ClosePairsBitMatch( unif01_Gen* gen, snpair_Res* res,
const std::tuple<long, long, int, int>& xargs );
static std::vector< double >
Run( unif01_Gen* gen, sres_Chi2* res,
const std::tuple<long, long, int, int>& xargs );
static std::vector< double >
Permutation( unif01_Gen* gen, sres_Chi2* res,
const std::tuple<long, long, int, int>& xargs );
static std::vector< double >
CollisionPermut( unif01_Gen* gen, sknuth_Res2* res,
const std::tuple<long, long, int, int>& xargs );
static std::vector< double >
SampleProd( unif01_Gen* gen, sres_Basic* res,
const std::tuple<long, long, int, int>& xargs );
static std::vector< double >
SampleMean( unif01_Gen* gen, sres_Basic* res,
const std::tuple<long, long, int>& xargs );
static std::vector< double >
SampleCorr( unif01_Gen* gen, sres_Basic* res,
const std::tuple<long, long, int, int>& xargs );
static std::vector< double >
AppearanceSpacings( unif01_Gen* gen, sres_Basic* res,
const std::tuple<long, long, long, int, int, int>& xargs );
static std::vector< double >
SumCollector( unif01_Gen* gen, sres_Chi2* res,
const std::tuple<long, long, int, double>& xargs );
static std::vector< double >
Savir2( unif01_Gen* gen, sres_Chi2* res,
const std::tuple<long, long, int, long, int>& xargs );
static std::vector< double >
GCD( unif01_Gen* gen, smarsa_Res2* res,
const std::tuple<long, long, int, int>& xargs );
static std::vector< double >
LinearComp( unif01_Gen* gen, scomp_Res* res,
const std::tuple<long, long, int, int>& xargs );
static std::vector< double >
LempelZiv( unif01_Gen* gen, sres_Basic* res,
const std::tuple<long, int, int, int>& xargs );
static std::vector< double >
Fourier3( unif01_Gen* gen, sspectral_Res* res,
const std::tuple<long, int, int, int>& xargs );
static std::vector< double >
LongestHeadRun( unif01_Gen* gen, sstring_Res2* res,
const std::tuple<long, long, int, int, long>& xargs );
static std::vector< double >
PeriodsInStrings( unif01_Gen* gen, sres_Chi2* res,
const std::tuple<long, long, int, int>& xargs );
static std::vector< double >
HammingWeight2( unif01_Gen* gen, sres_Basic* res,
const std::tuple<long, long, int, int, long>& xargs );
static std::vector< double >
HammingCorr( unif01_Gen* gen, sstring_Res* res,
const std::tuple<long, long, int, int, int>& xargs );
static std::vector< double >
StringRun( unif01_Gen* gen, sstring_Res3* res,
const std::tuple<long, long, int, int>& xargs );
static std::vector< double >
AutoCorr( unif01_Gen* gen, sres_Basic* res,
const std::tuple<long, long, int, int, int>& xargs );
///@}
//! Function pointer type to use to define pointers to test runner functions
//! \note Abstracting the function pointer away as this, also pleases
//! doxygen in client code, otherwise doxygen issues warnings, such as
//! `no matching class member found for` as it fails to parse the
//! function pointer correctly and fails to find a function declaration,
//! which, of course, does not exist. Thanks to Vladimír Vondruš,
//! author of m.css (http://mcss.mosra.cz) for the help with this.
template< class... Args > using FnPtr = std::vector<double>(*)( Args... );
//! \brief Compile-time tag-based access to individual test wrappers.
//! \details This tagged tuple is practically a compile-time map that
//! associates tags (empty structs) to test wrappers. This is used to find
//! the test wrapper function pointers after migration over the network.
//! \see See also TestU01Props::pup().
tk::TaggedTuple< brigand::list<
tag::BirthdaySpacings, // tag
FnPtr< unif01_Gen*, sres_Poisson*,
const std::tuple<long, long, int, long, int, int>& >,
tag::Collision,
FnPtr< unif01_Gen*, sknuth_Res2*,
const std::tuple<long, long, int, long, int>& >,
tag::RandomWalk1,
FnPtr< unif01_Gen*, swalk_Res*,
const std::tuple<long, long, int, int, long, long>& >,
tag::Gap,
FnPtr< unif01_Gen*, sres_Chi2*,
const std::tuple<long, long, int, double, double>& >,
tag::SimplePoker,
FnPtr< unif01_Gen*, sres_Chi2*,
const std::tuple<long, long, int, int, int>& >,
tag::CouponCollector,
FnPtr< unif01_Gen*, sres_Chi2*,
const std::tuple<long, long, int, int>& >,
tag::MaxOft,
FnPtr< unif01_Gen*, sknuth_Res1*,
const std::tuple<long, long, int, int, int, int, int>& >,
tag::WeightDistrib,
FnPtr< unif01_Gen*, sres_Chi2*,
const std::tuple<long, long, int, long, double, double>& >,
tag::MatrixRank,
FnPtr< unif01_Gen*, sres_Chi2*,
const std::tuple<long, long, int, int, int, int>& >,
tag::HammingIndep,
FnPtr< unif01_Gen*, sstring_Res*,
const std::tuple<long, long, int, int, int, int>& >,
tag::SerialOver,
FnPtr< unif01_Gen*, sres_Basic*,
const std::tuple<long, long, int, long, int>& >,
tag::CollisionOver,
FnPtr< unif01_Gen*, smarsa_Res*,
const std::tuple<long, long, int, long, int>& >,
tag::ClosePairs,
FnPtr< unif01_Gen*, snpair_Res*,
const std::tuple<long, long, int, int, int, int, int>& >,
tag::ClosePairsBitMatch,
FnPtr< unif01_Gen*, snpair_Res*,
const std::tuple<long, long, int, int>& >,
tag::Run,
FnPtr< unif01_Gen*, sres_Chi2*,
const std::tuple<long, long, int, int>& >,
tag::Permutation,
FnPtr< unif01_Gen*, sres_Chi2*,
const std::tuple<long, long, int, int>& >,
tag::CollisionPermut,
FnPtr< unif01_Gen*, sknuth_Res2*,
const std::tuple<long, long, int, int>& >,
tag::SampleProd,
FnPtr< unif01_Gen*, sres_Basic*,
const std::tuple<long, long, int, int>& >,
tag::SampleMean,
FnPtr< unif01_Gen*, sres_Basic*,
const std::tuple<long, long, int>& >,
tag::SampleCorr,
FnPtr< unif01_Gen*, sres_Basic*,
const std::tuple<long, long, int, int>& >,
tag::AppearanceSpacings,
FnPtr< unif01_Gen*, sres_Basic*,
const std::tuple<long, long, long, int, int, int>& >,
tag::SumCollector,
FnPtr< unif01_Gen*, sres_Chi2*,
const std::tuple<long, long, int, double>& >,
tag::Savir2,
FnPtr< unif01_Gen*, sres_Chi2*,
const std::tuple<long, long, int, long, int>& >,
tag::GCD,
FnPtr< unif01_Gen*, smarsa_Res2*,
const std::tuple<long, long, int, int>& >,
tag::LinearComp,
FnPtr< unif01_Gen*, scomp_Res*,
const std::tuple<long, long, int, int>& >,
tag::LempelZiv,
FnPtr< unif01_Gen*, sres_Basic*,
const std::tuple<long, int, int, int>& >,
tag::Fourier3,
FnPtr< unif01_Gen*, sspectral_Res*,
const std::tuple<long, int, int, int>& >,
tag::LongestHeadRun,
FnPtr< unif01_Gen*, sstring_Res2*,
const std::tuple<long, long, int, int, long>& >,
tag::PeriodsInStrings,
FnPtr< unif01_Gen*, sres_Chi2*,
const std::tuple<long, long, int, int>& >,
tag::HammingWeight2,
FnPtr< unif01_Gen*, sres_Basic*,
const std::tuple<long, long, int, int, long>& >,
tag::HammingCorr,
FnPtr< unif01_Gen*, sstring_Res*,
const std::tuple<long, long, int, int, int>& >,
tag::StringRun,
FnPtr< unif01_Gen*, sstring_Res3*,
const std::tuple<long, long, int, int>& >,
tag::AutoCorr,
FnPtr< unif01_Gen*, sres_Basic*,
const std::tuple<long, long, int, int, int>& >
> > runner {{
BirthdaySpacings, // Initialize by binding to member function wrappers.
Collision, // Obviously the order here is important.
RandomWalk1,
Gap,
SimplePoker,
CouponCollector,
MaxOft,
WeightDistrib,
MatrixRank,
HammingIndep,
SerialOver,
CollisionOver,
ClosePairs,
ClosePairsBitMatch,
Run,
Permutation,
CollisionPermut,
SampleProd,
SampleMean,
SampleCorr,
AppearanceSpacings,
SumCollector,
Savir2,
GCD,
LinearComp,
LempelZiv,
Fourier3,
LongestHeadRun,
PeriodsInStrings,
HammingWeight2,
HammingCorr,
StringRun,
AutoCorr
}};
//! Find RNG properties based on RNG id
unif01_Gen* generator( tk::ctr::RNGType r ) const;
private:
//! Create TestU01 RNG wrapper
template< tk::ctr::RawRNGType id > void addRNG( tk::ctr::RNGType r );
std::map< tk::ctr::RNGType, Gen01Ptr > m_generator; //!< RNG wrappers
};
} // rngtest::
#endif // TestU01Stack_h
|