Skip to content

Commit

Permalink
Fixes Issue JuliaLang#482 (issue with multidimensional sampling) (Jul…
Browse files Browse the repository at this point in the history
  • Loading branch information
amrods authored and nalimilan committed Apr 14, 2019
1 parent 413d51a commit b8a6245
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ Optionally specify a random number generator `rng` as the first argument
"""
function sample(rng::AbstractRNG, a::AbstractArray{T}, dims::Dims;
replace::Bool=true, ordered::Bool=false) where T
sample!(rng, a, Array{T}(undef, dims), rng; replace=replace, ordered=ordered)
sample!(rng, a, Array{T}(undef, dims); replace=replace, ordered=ordered)
end
sample(a::AbstractArray, dims::Dims; replace::Bool=true, ordered::Bool=false) =
sample(Random.GLOBAL_RNG, a, dims; replace=replace, ordered=ordered)
Expand Down
7 changes: 7 additions & 0 deletions test/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ check_sample_norep(a, (3, 12), 0; ordered=false)
a = sample(3:12, 5; replace=false, ordered=true)
check_sample_norep(a, (3, 12), 0; ordered=true)

# tests of multidimensional sampling

a = sample(3:12, (2, 2); replace=false)
check_sample_norep(a, (3, 12), 0; ordered=false)

@test sample(1:1, (2, 2); replace=true) == ones(Int, 2, 2)

# test of weighted sampling without replacement
a = [1:10;]
wv = Weights([zeros(6); 1:4])
Expand Down

0 comments on commit b8a6245

Please sign in to comment.