-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
sortperm segfaults with lt=(>=) #48172
Comments
With julia> sortperm(a, lt=(>=))
ERROR: BoundsError: attempt to access 30-element Vector{Int64} at index [0]
Stacktrace:
[1] getindex
@ ./array.jl:924 [inlined]
[2] partition!(v::Vector{Int64}, lo::Int64, hi::Int64, o::Base.Order.Perm{Base.Order.Lt{Base.Order.var"#1#3"{typeof(>=), typeof(identity)}}, Vector{Int64}})
@ Base.Sort ./sort.jl:557
[3] sort!(v::Vector{Int64}, lo::Int64, hi::Int64, a::Base.Sort.QuickSortAlg, o::Base.Order.Perm{Base.Order.Lt{Base.Order.var"#1#3"{typeof(>=), typeof(identity)}}, Vector{Int64}})
@ Base.Sort ./sort.jl:572
[4] sort!(v::Vector{Int64}, alg::Base.Sort.QuickSortAlg, order::Base.Order.Perm{Base.Order.Lt{Base.Order.var"#1#3"{typeof(>=), typeof(identity)}}, Vector{Int64}})
@ Base.Sort ./sort.jl:661
[5] sortperm(v::Vector{Int64}; alg::Base.Sort.QuickSortAlg, lt::Function, by::Function, rev::Nothing, order::Base.Order.ForwardOrdering)
@ Base.Sort ./sort.jl:927
[6] top-level scope
@ REPL[2]:1 |
the MWE can be (slightly) shortened to
|
I don't know if this will give any clue as to where the problem lies, but for vectors of this type longer than 22 the following problem arises
|
Looks like improper use of I can no reproduce the crash on Julia master though, but likely it gives unsurprising results still. |
Duplicate of #11429 Fixed in the upcoming release by #45222. julia> VERSION
v"1.9.0-beta2"
julia> sortperm(rand(1:10,10^3), lt=(>=));
julia> a = [10, 9, 8, 9, 7, 1, 3, 10, 4, 5, 5, 4, 6, 10, 10, 2, 2, 2, 8, 9, 1, 2, 8, 6, 7, 10, 1, 3, 5, 10];
julia> sortperm(a, lt=(>=));
julia> b = [7, 1, 3, 10, 4, 5, 5, 4, 6, 10, 10, 2, 2, 2, 8, 9, 1, 2, 8, 6, 7, 10];
julia> sort(b; lt=(>=)); #fail
julia> sort(b; lt=(>=), alg=InsertionSort); #pass
julia> sort(b; lt=(>=), alg=MergeSort); #pass
julia> sort(b; lt=(<=), rev=true); #fail
[...] You are supposed to use a "less than" ordering, not a "less than or equal to" ordering, so we don't guarantee correct behavior with The current observed behavior is that an unstable algorithm will give correct results and a stable algorithm will give correct results and reverse the order of all elements that compare equal (i.e. the exact opposite of stable), but don't count on it. |
I was finally able to get debugging working under vscode.
|
Precisely! |
Reported on discourse:
crashes with a segmentation fault. (I can reproduce on every version of Julia from 1.8 back to 0.4. In 0.3 it throws a
BoundsError
.)A similar but deterministic case that reliably causes a segfault is:
The text was updated successfully, but these errors were encountered: