JuliaStats / Statistics.jl

The Statistics stdlib that ships with Julia.
https://juliastats.org/Statistics.jl/dev/
Other
71 stars 40 forks source link

`quantile!` produces an unrelated assertion error when computing quantiles of a large range #121

Open yurivish opened 2 years ago

yurivish commented 2 years ago

In an earlier issue @jishnub noticed that certain ranges are considered nonempty despite the fact that their length is zero:

julia> r = typemin(Int):typemax(Int)
-9223372036854775808:9223372036854775807

julia> length(r)
0

julia> isempty(r)
false

This behavior triggers an assertion error in quantile! even though quantiles for such ranges are mathematically well-defined:

julia> using Statistics

julia> quantile!([0], r, [1])
ERROR: AssertionError: n > 0

The assertion has the comment "this case should never happen here":

https://github.com/JuliaStats/Statistics.jl/blob/0588f2cf9e43f9f72af5802feaf0af4b652c3257/src/Statistics.jl#L994