Skip to content

Commit 2aa03f3

Browse files
authored
Merge pull request #43 from JuliaRandom/an/norngwrapper
Comment out the WrappedRNG definitions and tests
2 parents 91c1102 + 994d9e4 commit 2aa03f3

File tree

2 files changed

+112
-109
lines changed

2 files changed

+112
-109
lines changed

src/RNGTest.jl

Lines changed: 92 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -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

test/runtests.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,23 @@ end
163163
end
164164
end
165165

166-
@testset "smallcrush" begin
167-
rng = RNGTest.wrap(MersenneTwister(0), UInt32)
168-
RNGTest.smallcrushTestU01(rng)
169-
@test all(t -> t > pval, mapreduce(s -> [s...], vcat, RNGTest.smallcrushJulia(rng)))
170-
end
171-
172-
@testset "Distributed smallcrushJulia" begin
173-
pids = addprocs()
174-
@everywhere using RNGTest
175-
for T in (UInt32, UInt64, Float64)
176-
if isdefined(Random, :Xoshiro)
177-
rng = RNGTest.wrap(Xoshiro(), T)
178-
else
179-
rng = RNGTest.wrap(MersenneTwister(), T)
180-
end
181-
results = RNGTest.smallcrushJulia(rng)
182-
@test all(ps -> all(>(pval), ps), results)
183-
end
184-
rmprocs(pids)
185-
end
166+
# @testset "smallcrush" begin
167+
# rng = RNGTest.wrap(MersenneTwister(0), UInt32)
168+
# RNGTest.smallcrushTestU01(rng)
169+
# @test all(t -> t > pval, mapreduce(s -> [s...], vcat, RNGTest.smallcrushJulia(rng)))
170+
# end
171+
172+
# @testset "Distributed smallcrushJulia" begin
173+
# pids = addprocs()
174+
# @everywhere using RNGTest
175+
# for T in (UInt32, UInt64, Float64)
176+
# if isdefined(Random, :Xoshiro)
177+
# rng = RNGTest.wrap(Xoshiro(), T)
178+
# else
179+
# rng = RNGTest.wrap(MersenneTwister(), T)
180+
# end
181+
# results = RNGTest.smallcrushJulia(rng)
182+
# @test all(ps -> all(>(pval), ps), results)
183+
# end
184+
# rmprocs(pids)
185+
# end

0 commit comments

Comments
 (0)