-
Notifications
You must be signed in to change notification settings - Fork 190
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
MethodError from sample with Float32 weights #695
Comments
It doesn't seem to work with |
Sorry I copied the wrong line of code. This is the code that triggers the bug: using StatsBase
n = 5030
N = 141230
sample(1:n, StatsBase.Weights(rand(Float32,n)), N, replace=true) If you change to Float64 it works fine. |
OK. Looking at the problematic |
This bug is affecting me again in other projects. The |
Copying the error message: ERROR: MethodError: no method matching make_alias_table!(::Weights{Float32, Float32, Vector{Float32}}, ::Float32, ::Vector{Float64}, ::Vector{Int64})
Closest candidates are:
make_alias_table!(::AbstractVector{Float64}, ::Float64, ::AbstractVector{Float64}, ::AbstractVector{Int64}) at /home/juliohm/.julia/packages/StatsBase/DWW4r/src/sampling.jl:587
Stacktrace:
[1] alias_sample!(rng::Random._GLOBAL_RNG, a::UnitRange{Int64}, wv::Weights{Float32, Float32, Vector{Float32}}, x::Vector{Int64})
@ StatsBase ~/.julia/packages/StatsBase/DWW4r/src/sampling.jl:666
[2] sample!(rng::Random._GLOBAL_RNG, a::UnitRange{Int64}, wv::Weights{Float32, Float32, Vector{Float32}}, x::Vector{Int64}; replace::Bool, ordered::Bool)
@ StatsBase ~/.julia/packages/StatsBase/DWW4r/src/sampling.jl:914
[3] #sample#203
@ ~/.julia/packages/StatsBase/DWW4r/src/sampling.jl:929 [inlined]
[4] #sample#204
@ ~/.julia/packages/StatsBase/DWW4r/src/sampling.jl:932 [inlined]
[5] top-level scope
@ REPL[10]:1 |
Can you investigate whether widening the type signature seems to be OK? |
This bug is no longer present. julia> using StatsBase
julia> n = 5030
5030
julia> N = 141230
141230
julia> sample(1:n, StatsBase.Weights(rand(Float32,n)), N, replace=true)
141230-element Vector{Int64}:
247
862
2144
⋮
3452
1185 |
This issue was fixed by #499. |
I think this code should work:
It works fine with Float64.
The text was updated successfully, but these errors were encountered: