Skip to content

Commit 6ade53f

Browse files
authored
Merge pull request #18 from JuliaRandom/rf/fix-pair-tuples
adjust `rand` for `Pair` and `Tuple` types, now implemented in `Random`
2 parents 7d326f2 + 552420f commit 6ade53f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RandomExtensions"
22
uuid = "fb686558-2515-59ef-acaa-46db3789a887"
33
authors = ["Rafael Fourquet <fourquet.rafael@gmail.com>"]
4-
version = "0.4.3"
4+
version = "0.4.4"
55

66
[deps]
77
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

src/sampling.jl

+15-2
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ rand(rng::AbstractRNG, sp::SamplerTag{Cont{T}}) where {T<:Union{Pair,Complex}} =
206206
#### additional convenience methods
207207

208208
# rand(Pair{A,B}) => rand(make(Pair{A,B}, A, B))
209-
Sampler(::Type{RNG}, ::Type{Pair{A,B}}, n::Repetition) where {RNG<:AbstractRNG,A,B} =
210-
Sampler(RNG, make(Pair{A,B}, A, B), n)
209+
if VERSION < v"1.11.0-DEV.618" # now implemented in `Random`
210+
Sampler(::Type{RNG}, ::Type{Pair{A,B}}, n::Repetition) where {RNG<:AbstractRNG,A,B} =
211+
Sampler(RNG, make(Pair{A,B}, A, B), n)
212+
end
211213

212214
# rand(make(Complex, x)) => rand(make(Complex, x, x))
213215
Sampler(::Type{RNG}, u::Make1{T}, n::Repetition) where {RNG<:AbstractRNG,T<:Complex} =
@@ -226,6 +228,17 @@ Sampler(::Type{RNG}, ::Type{T}, n::Repetition
226228
) where {RNG<:AbstractRNG,T<:Union{Tuple,NamedTuple}} =
227229
Sampler(RNG, make(T), n)
228230

231+
if VERSION >= v"1.11.0-DEV.573"
232+
# now `Random` implements `rand(Tuple{...})`, so be more specific for
233+
# special stuff still not implemented by `Random`
234+
# TODO: we should probably remove this
235+
Sampler(::Type{RNG}, ::Type{Tuple}, n::Repetition) where {RNG <: AbstractRNG} =
236+
Sampler(RNG, make(Tuple), n)
237+
238+
Sampler(::Type{RNG}, ::Type{NTuple{N}}, n::Repetition) where {RNG <: AbstractRNG, N} =
239+
Sampler(RNG, make(NTuple{N}), n)
240+
end
241+
229242
#### make
230243

231244
# implement make(Tuple, S1, S2...), e.g. for rand(make(Tuple, Int, 1:3)),

0 commit comments

Comments
 (0)