Skip to content

Commit 7a61554

Browse files
committed
add make(Tuple, s, n::Integer)
1 parent 76ad51f commit 7a61554

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/containers.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ end
6464
@make_container(p::AbstractFloat, m::Integer, [n::Integer])
6565
# Tuple as a container
6666
@make_container(T::Type{<:Tuple})
67-
67+
@make_container(::Type{Tuple}, n::Integer)
6868

6969
## arrays (same as in Random, but with explicit type specification, e.g. rand(Int, Array, 4)
7070

src/sampling.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ end
182182

183183
make(T::Type{<:Tuple}, args...) = _make(T, args...)
184184

185+
make(::Type{Tuple}, X, n::Integer) = make(NTuple{Int(n)}, X)
186+
make(::Type{Tuple}, ::Type{X}, n::Integer) where {X} = make(NTuple{Int(n)}, X)
187+
185188
# disambiguate
186189

187190
make(::Type{T}, X) where {T<:Tuple} = _make(T, X)

test/runtests.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ const spString = Sampler(MersenneTwister, String)
182182
s = rand(rng..., 1:3, Tuple{Int8, UInt8})
183183
@test s isa Tuple{Int8, UInt8}
184184
@test all(in(1:3), s)
185+
186+
s = rand(rng..., 1:3, Tuple, 4)
187+
@test s isa NTuple{4,Int}
188+
@test all(in(1:3), s)
185189
end
186190

187191
@testset "Rand" for rng in ([], [MersenneTwister(0)], [RandomDevice()])
@@ -272,6 +276,13 @@ end
272276

273277
@test rand(make(Tuple{Int8,Int8})) isa Tuple{Int8,Int8}
274278
@test rand(make(Tuple{Int8,UInt})) isa Tuple{Int8,UInt}
279+
280+
# make(Tuple, s, n)
281+
s = rand(make(Tuple, 1:3, 4))
282+
@test s isa NTuple{4,Int}
283+
@test all(in(1:3), s)
284+
s = rand(make(Tuple, Int8, 4))
285+
@test s isa NTuple{4,Int8}
275286
end
276287

277288
@testset "rand(make(NTuple{N}/Tuple{...}, x))" begin

0 commit comments

Comments
 (0)