Skip to content

Commit

Permalink
Fix method ambiguity error of shuffle! with AbstractArray{Bool} o…
Browse files Browse the repository at this point in the history
…n Julia 1.11 (#24)

Co-authored-by: Eric Hanson <[email protected]>
  • Loading branch information
devmotion and ericphanson authored Apr 16, 2024
1 parent 7e5c4a8 commit 18aa75f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/StableRNGs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ end

# https://github.com/JuliaRandom/StableRNGs.jl/issues/10
Random.shuffle(r::StableRNG, a::AbstractArray) = Random.shuffle!(r, Base.copymutable(a))
function Random.shuffle!(r::StableRNG, a::AbstractArray)
# Fix method ambiguity issue: https://github.com/JuliaRandom/StableRNGs.jl/issues/23
Random.shuffle!(r::StableRNG, a::AbstractArray) = _shuffle!(r, a)
Random.shuffle!(r::StableRNG, a::AbstractArray{Bool}) = _shuffle!(r, a)
function _shuffle!(r::StableRNG, a::AbstractArray)
require_one_based_indexing(a)
n = length(a)
n <= 1 && return a # nextpow below won't work with n == 0
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ end
b = collect(a)
shuffle!(StableRNG(10), b)
@test b == a_shuffled

# https://github.com/JuliaRandom/StableRNGs.jl/issues/23
c = [false, true, false, true, false]
c_shuffled = [false, false, false, true, true]
@test shuffle!(StableRNG(123), c) == c_shuffled
d = [false true; true false]
d_shuffled = [true true; false false]
@test shuffle(StableRNG(31), d) == d_shuffled
end

# https://github.com/JuliaRandom/StableRNGs.jl/issues/20
Expand Down

2 comments on commit 18aa75f

@ericphanson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/105003

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.2 -m "<description of version>" 18aa75faac29ac977cb1cf6fa69a67f258090823
git push origin v1.0.2

Please sign in to comment.