-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Random
: make randperm!
and randcycle!
accept AbstractArray
#58596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Random
: make randperm!
and randcycle!
accept AbstractArray
#58596
Conversation
Hello! I am a bot. Thank you for your pull request! I have assigned
|
I feel like even the |
@rfourquet Can you review this? |
2190c3d
to
1154fd9
Compare
6bf6bb5
to
45a4855
Compare
Relax the dispatch from `Array` to `AbstractArray`, while requiring one-based indexing.
45a4855
to
c2cb419
Compare
I guess this would make the error message more confusing for |
Perhaps we could add some error hints to help that situation? |
Don't see anything special about julia> using Random
julia> f(t::Type) = randperm!(Array{t}(undef, Int(typemax(t))::Int + 1))
f (generic function with 1 method)
julia> f(Bool)
ERROR: InexactError: Bool(2)
Stacktrace:
[1] Bool
@ ./bool.jl:191 [inlined]
[2] convert
@ ./number.jl:7 [inlined]
[3] setindex!
@ ./array.jl:985 [inlined]
[4] randperm!(r::TaskLocalRNG, a::Vector{Bool})
@ Random ~/tmp/jl/jl/julia-2190c3d1c4/share/julia/stdlib/v1.13/Random/src/misc.jl:330
[5] randperm!(a::Vector{Bool})
@ Random ~/tmp/jl/jl/julia-2190c3d1c4/share/julia/stdlib/v1.13/Random/src/misc.jl:336
[6] f(t::Type)
@ Main ./REPL[2]:1
[7] top-level scope
@ REPL[3]:1
julia> f(Int8)
ERROR: InexactError: trunc(Int8, 128)
Stacktrace:
[1] throw_inexacterror(func::Symbol, to::Type, val::Int64)
@ Core ./boot.jl:863
[2] checked_trunc_sint
@ ./boot.jl:877 [inlined]
[3] toInt8
@ ./boot.jl:892 [inlined]
[4] Int8
@ ./boot.jl:1002 [inlined]
[5] convert
@ ./number.jl:7 [inlined]
[6] setindex!
@ ./array.jl:985 [inlined]
[7] randperm!(r::TaskLocalRNG, a::Vector{Int8})
@ Random ~/tmp/jl/jl/julia-2190c3d1c4/share/julia/stdlib/v1.13/Random/src/misc.jl:330
[8] randperm!(a::Vector{Int8})
@ Random ~/tmp/jl/jl/julia-2190c3d1c4/share/julia/stdlib/v1.13/Random/src/misc.jl:336
[9] f(t::Type)
@ Main ./REPL[2]:1
[10] top-level scope
@ REPL[4]:1
julia> f(UInt8)
ERROR: InexactError: trunc(UInt8, 256)
Stacktrace:
[1] throw_inexacterror(func::Symbol, to::Type, val::Int64)
@ Core ./boot.jl:863
[2] checked_trunc_uint
@ ./boot.jl:885 [inlined]
[3] toUInt8
@ ./boot.jl:947 [inlined]
[4] UInt8
@ ./boot.jl:1007 [inlined]
[5] convert
@ ./number.jl:7 [inlined]
[6] setindex!
@ ./array.jl:985 [inlined]
[7] randperm!(r::TaskLocalRNG, a::Vector{UInt8})
@ Random ~/tmp/jl/jl/julia-2190c3d1c4/share/julia/stdlib/v1.13/Random/src/misc.jl:330
[8] randperm!(a::Vector{UInt8})
@ Random ~/tmp/jl/jl/julia-2190c3d1c4/share/julia/stdlib/v1.13/Random/src/misc.jl:336
[9] f(t::Type)
@ Main ./REPL[2]:1
[10] top-level scope
@ REPL[5]:1 |
I'm assigning this to @rfourquet. |
Relax the dispatch from
Array
toAbstractArray
, while requiring one-based indexing.