@@ -13,94 +13,94 @@ module RNGTest
1313 unsafe_store! (swrite[], 0 , 1 )
1414 end
1515
16- # WrappedRNG
16+ # # WrappedRNG
1717
18- # TestU01 expects a standard function as input (created via
19- # cfunction here). When one wants to test the random stream of
20- # an AbstractRNG, a little more work has to be done before
21- # passing it to TestU01. The type WrappedRNG wraps an
22- # AbstractRNG into an object which knows which type of random
23- # numbers to produce, and also whether the scalar or array API
24- # should be used (this is useful when different algorithms are
25- # used for each case, which results in different streams which
26- # should be tested separately). Such an object can then be
27- # passed to the Unif01 constructor.
18+ # # TestU01 expects a standard function as input (created via
19+ # # cfunction here). When one wants to test the random stream of
20+ # # an AbstractRNG, a little more work has to be done before
21+ # # passing it to TestU01. The type WrappedRNG wraps an
22+ # # AbstractRNG into an object which knows which type of random
23+ # # numbers to produce, and also whether the scalar or array API
24+ # # should be used (this is useful when different algorithms are
25+ # # used for each case, which results in different streams which
26+ # # should be tested separately). Such an object can then be
27+ # # passed to the Unif01 constructor.
2828
29- const TestableNumbers = Union{Int8, UInt8, Int16, UInt16, Int32, UInt32,
30- Int64, UInt64, Int128, UInt128, Float16, Float32, Float64}
29+ # const TestableNumbers = Union{Int8, UInt8, Int16, UInt16, Int32, UInt32,
30+ # Int64, UInt64, Int128, UInt128, Float16, Float32, Float64}
3131
32- mutable struct WrappedRNG{T<: TestableNumbers , RNG<: AbstractRNG }
33- rng:: RNG
34- cache:: Vector{T}
35- fillarray:: Bool
36- vals:: Union{Vector{UInt32}, Base.ReinterpretArray{UInt32, 1, T, Vector{T}, false}}
37- idx:: Int
38- end
32+ # mutable struct WrappedRNG{T<:TestableNumbers, RNG<:AbstractRNG}
33+ # rng::RNG
34+ # cache::Vector{T}
35+ # fillarray::Bool
36+ # vals::Union{Vector{UInt32}, Base.ReinterpretArray{UInt32, 1, T, Vector{T}, false}}
37+ # idx::Int
38+ # end
3939
40- function WrappedRNG (rng:: RNG , :: Type{T} , fillarray = true , cache_size = 3 * 2 ^ 11 ÷ sizeof (T)) where {RNG, T}
41- if T <: Integer && cache_size* sizeof (T) % sizeof (UInt32) != 0
42- error (" cache_size must be a multiple of $(Int (4 / sizeof (T))) (for type $T )" )
43- elseif T === Float16 && cache_size % 6 != 0 || T === Float32 && cache_size % 3 != 0
44- error (" cache_size must be a multiple of 3 (resp. 6) for Float32 (resp. Float16)" )
45- end
46- cache = Vector {T} (undef, cache_size)
47- fillcache (WrappedRNG {T, RNG} (rng, cache, fillarray,
48- reinterpret (UInt32, cache),
49- 0 )) # 0 is a dummy value, which will be set correctly by fillcache
50- end
40+ # function WrappedRNG(rng::RNG, ::Type{T}, fillarray = true, cache_size = 3*2^11 ÷ sizeof(T)) where {RNG, T}
41+ # if T <: Integer && cache_size*sizeof(T) % sizeof(UInt32) != 0
42+ # error("cache_size must be a multiple of $(Int(4/sizeof(T))) (for type $T)")
43+ # elseif T === Float16 && cache_size % 6 != 0 || T === Float32 && cache_size % 3 != 0
44+ # error("cache_size must be a multiple of 3 (resp. 6) for Float32 (resp. Float16)")
45+ # end
46+ # cache = Vector{T}(undef, cache_size)
47+ # fillcache(WrappedRNG{T, RNG}(rng, cache, fillarray,
48+ # reinterpret(UInt32, cache),
49+ # 0)) # 0 is a dummy value, which will be set correctly by fillcache
50+ # end
5151
52- # The ability to play with the cache size and the fillarray option is for advanced uses,
53- # when one wants to test different code path of the particular RNG implementations, like
54- # MersenneTwister from Base.
55- # For now let's document only the type parameter in the wrap function:
56- wrap (rng:: AbstractRNG , :: Type{T} ) where {T<: TestableNumbers } = WrappedRNG (rng, T)
52+ # # The ability to play with the cache size and the fillarray option is for advanced uses,
53+ # # when one wants to test different code path of the particular RNG implementations, like
54+ # # MersenneTwister from Base.
55+ # # For now let's document only the type parameter in the wrap function:
56+ # wrap(rng::AbstractRNG, ::Type{T}) where {T<:TestableNumbers} = WrappedRNG(rng, T)
5757
58- function fillcache (g:: WrappedRNG{T} ) where T
59- if g. fillarray
60- rand! (g. rng, g. cache)
61- else
62- for i = 1 : length (g. cache)
63- @inbounds g. cache[i] = rand (g. rng, T)
64- end
65- end
66- g. idx = 0
67- return g
68- end
58+ # function fillcache(g::WrappedRNG{T}) where T
59+ # if g.fillarray
60+ # rand!(g.rng, g.cache)
61+ # else
62+ # for i = 1:length(g.cache)
63+ # @inbounds g.cache[i] = rand(g.rng, T)
64+ # end
65+ # end
66+ # g.idx = 0
67+ # return g
68+ # end
6969
70- function (g:: WrappedRNG{T} )() where T<: Integer
71- g. idx+ 1 > length (g. vals) && fillcache (g)
72- @inbounds return g. vals[g. idx+= 1 ]
73- end
70+ # function (g::WrappedRNG{T})() where T<:Integer
71+ # g.idx+1 > length(g.vals) && fillcache(g)
72+ # @inbounds return g.vals[g.idx+=1]
73+ # end
7474
75- function (g:: WrappedRNG{Float64} )()
76- g. idx+ 1 > length (g. cache) && fillcache (g)
77- @inbounds return g. cache[g. idx+= 1 ]
78- end
75+ # function (g::WrappedRNG{Float64})()
76+ # g.idx+1 > length(g.cache) && fillcache(g)
77+ # @inbounds return g.cache[g.idx+=1]
78+ # end
7979
80- function (g:: WrappedRNG{Float32} )()
81- g. idx+ 3 > length (g. cache) && fillcache (g)
82- @inbounds begin
83- f = Float64 (g. cache[g. idx+ 1 ])
84- # a Float32 has 24 bits of precision, but only 23 bit of entropy
85- f += Float64 (g. cache[g. idx+ 2 ])/ exp2 (23 )
86- f += Float64 (g. cache[g. idx+= 3 ])/ exp2 (46 )
87- return f % 1.0
88- end
89- end
80+ # function (g::WrappedRNG{Float32})()
81+ # g.idx+3 > length(g.cache) && fillcache(g)
82+ # @inbounds begin
83+ # f = Float64(g.cache[g.idx+1])
84+ # # a Float32 has 24 bits of precision, but only 23 bit of entropy
85+ # f += Float64(g.cache[g.idx+2])/exp2(23)
86+ # f += Float64(g.cache[g.idx+=3])/exp2(46)
87+ # return f % 1.0
88+ # end
89+ # end
9090
91- function (g:: WrappedRNG{Float16} )()
92- g. idx+ 6 > length (g. cache) && fillcache (g)
93- @inbounds begin
94- f = Float64 (g. cache[g. idx+ 1 ])
95- # a Float16 has 10 bits of entropy
96- f += Float64 (g. cache[g. idx+ 2 ])/ exp2 (10 )
97- f += Float64 (g. cache[g. idx+ 3 ])/ exp2 (20 )
98- f += Float64 (g. cache[g. idx+ 4 ])/ exp2 (30 )
99- f += Float64 (g. cache[g. idx+ 5 ])/ exp2 (40 )
100- f += Float64 (g. cache[g. idx+= 6 ])/ exp2 (50 )
101- return f % 1.0
102- end
103- end
91+ # function (g::WrappedRNG{Float16})()
92+ # g.idx+6 > length(g.cache) && fillcache(g)
93+ # @inbounds begin
94+ # f = Float64(g.cache[g.idx+1])
95+ # # a Float16 has 10 bits of entropy
96+ # f += Float64(g.cache[g.idx+2])/exp2(10)
97+ # f += Float64(g.cache[g.idx+3])/exp2(20)
98+ # f += Float64(g.cache[g.idx+4])/exp2(30)
99+ # f += Float64(g.cache[g.idx+5])/exp2(40)
100+ # f += Float64(g.cache[g.idx+=6])/exp2(50)
101+ # return f % 1.0
102+ # end
103+ # end
104104
105105
106106 # RNGGenerator struct
@@ -119,17 +119,17 @@ module RNGTest
119119 return new (ccall ((:unif01_CreateExternGen01 , libtestu01), Ptr{Cvoid}, (Ptr{UInt8}, Ptr{Cvoid}), genname, cf), Float64, genname)
120120 end
121121
122- function Unif01 (g:: WrappedRNG{T} , genname) where {T<: AbstractFloat }
123- # we assume that g being created out of an AbstractRNG, it produces Floats in the interval [0,1)
124- cf = @cfunction ($ g, Float64, ())
125- return new (ccall ((:unif01_CreateExternGen01 , libtestu01), Ptr{Cvoid}, (Ptr{UInt8}, Ptr{Cvoid}), genname, cf), Float64, genname)
126- end
122+ # function Unif01(g::WrappedRNG{T}, genname) where {T<:AbstractFloat}
123+ # # we assume that g being created out of an AbstractRNG, it produces Floats in the interval [0,1)
124+ # cf = @cfunction($g, Float64, ())
125+ # return new(ccall((:unif01_CreateExternGen01, libtestu01), Ptr{Cvoid}, (Ptr{UInt8}, Ptr{Cvoid}), genname, cf), Float64, genname)
126+ # end
127127
128- function Unif01 (g:: WrappedRNG{T} , genname) where {T<: Integer }
129- @assert Cuint === UInt32
130- cf = @cfunction ($ g, UInt32, ())
131- return new (ccall ((:unif01_CreateExternGenBits , libtestu01), Ptr{Cvoid}, (Ptr{UInt8}, Ptr{Cvoid}), genname, cf), UInt32, genname)
132- end
128+ # function Unif01(g::WrappedRNG{T}, genname) where {T<:Integer}
129+ # @assert Cuint === UInt32
130+ # cf = @cfunction($g, UInt32, ())
131+ # return new(ccall((:unif01_CreateExternGenBits, libtestu01), Ptr{Cvoid}, (Ptr{UInt8}, Ptr{Cvoid}), genname, cf), UInt32, genname)
132+ # end
133133 end
134134 function delete (obj:: Unif01 )
135135 if obj. gentype === Float64
@@ -139,7 +139,10 @@ module RNGTest
139139 end
140140 end
141141
142- const RNGGenerator = Union{Function, WrappedRNG}
142+ const RNGGenerator = Union{
143+ Function,
144+ # WrappedRNG
145+ }
143146
144147 # Result types
145148
0 commit comments