-
Notifications
You must be signed in to change notification settings - Fork 194
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
Add @inbounds in alias table sampling #630
Comments
Sure, why not. Though it seems we need an additional check that the indices of |
@ParadaCarleton Can you argument on why you want to close this? |
I don't like correctness bugs, and thought this was just hanging around because it was old enough to be before that Yuri post on all the correctness issues in JuliaStats packages. |
This optimization would be unsafe because it is possible for julia> StatsBase.alias_sample!(Random.default_rng(), rand(10), weights(fill(0, 10)), rand(10))
ERROR: BoundsError: attempt to access 10-element Vector{Float64} at index [281471800382896]
Stacktrace:
[1] throw_boundserror(A::Vector{Float64}, I::Tuple{Int64})
@ Base ./essentials.jl:14
[2] getindex
@ ./essentials.jl:891 [inlined]
[3] alias_sample!(rng::TaskLocalRNG, a::Vector{Float64}, wv::Weights{Int64, Int64, Vector{Int64}}, x::Vector{Float64})
@ StatsBase ~/.julia/packages/StatsBase/ebrT3/src/sampling.jl:729
[4] top-level scope
@ REPL[10]:1 With |
Seems like one could add
@inbounds
to this lineStatsBase.jl/src/sampling.jl
Line 624 in 41669cd
In fact its here already when using alias table sampling for
Categorical
inDistributions
:https://github.com/JuliaStats/Distributions.jl/blob/d6de7214e6d84df77d1eb3ec7a98d23862d1232d/src/samplers/aliastable.jl#L19
The text was updated successfully, but these errors were encountered: