Skip to content

Commit fe6c9ba

Browse files
authored
Sampler: use type instead of instance for the RNG argument (#2)
Cf. JuliaLang/julia#28010
1 parent 6c09481 commit fe6c9ba

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
julia 0.7.0-DEV.3261
1+
julia 0.7-beta2

src/sampling.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44
## Uniform
55

6-
Sampler(rng::AbstractRNG, d::Union{UniformWrap,UniformType}, n::Repetition) =
7-
Sampler(rng, d[], n)
6+
Sampler(RNG::Type{<:AbstractRNG}, d::Union{UniformWrap,UniformType}, n::Repetition) =
7+
Sampler(RNG, d[], n)
88

99

1010
## floats
1111

1212
### override def from Random
1313

14-
Sampler(rng::AbstractRNG, ::Type{T}, n::Repetition) where {T<:AbstractFloat} =
15-
Sampler(rng, CloseOpen01(T), n)
14+
Sampler(RNG::Type{<:AbstractRNG}, ::Type{T}, n::Repetition) where {T<:AbstractFloat} =
15+
Sampler(RNG, CloseOpen01(T), n)
1616

1717
### fall-back on Random definitions
1818
rand(r::AbstractRNG, ::SamplerTrivial{CloseOpen01{T}}) where {T} =
@@ -23,18 +23,18 @@ rand(r::AbstractRNG, ::SamplerTrivial{CloseOpen12{T}}) where {T} =
2323

2424
### CloseOpenAB
2525

26-
Sampler(rng::AbstractRNG, d::CloseOpenAB{T}, n::Repetition) where {T} =
27-
SamplerTag{CloseOpenAB{T}}((a=d.a, d=d.b - d.a, sp=Sampler(rng, CloseOpen01{T}(), n)))
26+
Sampler(RNG::Type{<:AbstractRNG}, d::CloseOpenAB{T}, n::Repetition) where {T} =
27+
SamplerTag{CloseOpenAB{T}}((a=d.a, d=d.b - d.a, sp=Sampler(RNG, CloseOpen01{T}(), n)))
2828

2929
rand(rng::AbstractRNG, sp::SamplerTag{CloseOpenAB{T}}) where {T} =
3030
sp.data.a + sp.data.d * rand(rng, sp.data.sp)
3131

3232

3333
## sampler for pairs and complex numbers
3434

35-
function Sampler(rng::AbstractRNG, u::Combine2{T}, n::Repetition) where T <: Union{Pair,Complex}
36-
sp1 = Sampler(rng, u.x, n)
37-
sp2 = u.x == u.y ? sp1 : Sampler(rng, u.y, n)
35+
function Sampler(RNG::Type{<:AbstractRNG}, u::Combine2{T}, n::Repetition) where T <: Union{Pair,Complex}
36+
sp1 = Sampler(RNG, u.x, n)
37+
sp2 = u.x == u.y ? sp1 : Sampler(RNG, u.y, n)
3838
SamplerTag{Cont{T}}((sp1, sp2))
3939
end
4040

@@ -44,29 +44,29 @@ rand(rng::AbstractRNG, sp::SamplerTag{Cont{T}}) where {T<:Union{Pair,Complex}} =
4444

4545
### additional methods for complex numbers
4646

47-
Sampler(rng::AbstractRNG, u::Combine1{Complex}, n::Repetition) =
48-
Sampler(rng, Combine(Complex, u.x, u.x), n)
47+
Sampler(RNG::Type{<:AbstractRNG}, u::Combine1{Complex}, n::Repetition) =
48+
Sampler(RNG, Combine(Complex, u.x, u.x), n)
4949

50-
Sampler(rng::AbstractRNG, ::Type{Complex{T}}, n::Repetition) where {T<:Real} =
51-
Sampler(rng, Combine(Complex, T, T), n)
50+
Sampler(RNG::Type{<:AbstractRNG}, ::Type{Complex{T}}, n::Repetition) where {T<:Real} =
51+
Sampler(RNG, Combine(Complex, T, T), n)
5252

5353

5454
## Normal & Exponential
5555

5656
rand(rng::AbstractRNG, ::SamplerTrivial{Normal01{T}}) where {T<:Union{AbstractFloat,Complex{<:AbstractFloat}}} =
5757
randn(rng, T)
5858

59-
Sampler(rng::AbstractRNG, d::Normalμσ{T}, n::Repetition) where {T} =
60-
SamplerSimple(d, Sampler(rng, Normal(T), n))
59+
Sampler(RNG::Type{<:AbstractRNG}, d::Normalμσ{T}, n::Repetition) where {T} =
60+
SamplerSimple(d, Sampler(RNG, Normal(T), n))
6161

6262
rand(rng::AbstractRNG, sp::SamplerSimple{Normalμσ{T},<:Sampler}) where {T} =
6363
sp[].μ + sp[].σ * rand(rng, sp.data)
6464

6565
rand(rng::AbstractRNG, ::SamplerTrivial{Exponential1{T}}) where {T<:AbstractFloat} =
6666
randexp(rng, T)
6767

68-
Sampler(rng::AbstractRNG, d::Exponentialθ{T}, n::Repetition) where {T} =
69-
SamplerSimple(d, Sampler(rng, Exponential(T), n))
68+
Sampler(RNG::Type{<:AbstractRNG}, d::Exponentialθ{T}, n::Repetition) where {T} =
69+
SamplerSimple(d, Sampler(RNG, Exponential(T), n))
7070

7171
rand(rng::AbstractRNG, sp::SamplerSimple{Exponentialθ{T},<:Sampler}) where {T} =
7272
sp[].θ * rand(rng, sp.data)

0 commit comments

Comments
 (0)