-
-
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
Remove specialized sort! method for PartialQuickSort{Int} (fixes #12833) #12838
Conversation
There were two sort methods for PartialQuickSort, depending on whether it was parameterized by an Int (representing the last index needing to be sorted) or a Range. The version parameterized by an Int has one less comparison per branch, but it causes inference to fail to infer the return type of sort/sort! under many circumstances. Removing this version and only providing the generic function restores proper type inference. If there's an underlying bug that is fixed, this can be reverted (though the test should remain.)
I restarted the two travis jobs for you; both failed on x86_64. |
This fixes sbromberger/LightGraphs.jl#147. |
## has one less comparison per loop than the version below, but enabling | ||
## it causes return type inference to fail for sort/sort! (#12833) | ||
## | ||
# function sort!(v::AbstractVector, lo::Int, hi::Int, a::PartialQuickSort{Int}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't you do sort!{T}(v::AbstractVector{T}, ...) here, and then return v::AbstractVector{T} on line 369 to preserve type stability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This didn't fix the overallocations: #12833 (comment)
Remove specialized sort! method for PartialQuickSort{Int} (fixes #12833)
@JeffBezanson, can you explain why this additional method caused inference to fail? Too many |
There were two
sort
methods forPartialQuickSort
, dependingon whether it was parameterized by an
Int
(representing thelast index needing to be sorted) or a
Range
. The versionparameterized by an
Int
has one less comparison per branch,but it causes inference to fail to infer the return type of
sort
/sort!
under many circumstances. Removing this versionof
sort!
and only providing the generic function restores propertype inference.
If there's an underlying bug that is fixed, this can be reverted
(although the test should remain.)