Skip to content

Commit b8a6245

Browse files
amrodsnalimilan
authored andcommitted
Fixes Issue #482 (issue with multidimensional sampling) (#483)
1 parent 413d51a commit b8a6245

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/sampling.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ Optionally specify a random number generator `rng` as the first argument
390390
"""
391391
function sample(rng::AbstractRNG, a::AbstractArray{T}, dims::Dims;
392392
replace::Bool=true, ordered::Bool=false) where T
393-
sample!(rng, a, Array{T}(undef, dims), rng; replace=replace, ordered=ordered)
393+
sample!(rng, a, Array{T}(undef, dims); replace=replace, ordered=ordered)
394394
end
395395
sample(a::AbstractArray, dims::Dims; replace::Bool=true, ordered::Bool=false) =
396396
sample(Random.GLOBAL_RNG, a, dims; replace=replace, ordered=ordered)

test/sampling.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ check_sample_norep(a, (3, 12), 0; ordered=false)
170170
a = sample(3:12, 5; replace=false, ordered=true)
171171
check_sample_norep(a, (3, 12), 0; ordered=true)
172172

173+
# tests of multidimensional sampling
174+
175+
a = sample(3:12, (2, 2); replace=false)
176+
check_sample_norep(a, (3, 12), 0; ordered=false)
177+
178+
@test sample(1:1, (2, 2); replace=true) == ones(Int, 2, 2)
179+
173180
# test of weighted sampling without replacement
174181
a = [1:10;]
175182
wv = Weights([zeros(6); 1:4])

0 commit comments

Comments
 (0)