Skip to content
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

Merged
merged 1 commit into from
Aug 28, 2015

Conversation

kmsquire
Copy link
Member

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
of sort! and only providing the generic function restores proper
type inference.

If there's an underlying bug that is fixed, this can be reverted
(although the test should remain.)

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.)
@kmsquire kmsquire added the types and dispatch Types, subtyping and method dispatch label Aug 28, 2015
@timholy
Copy link
Member

timholy commented Aug 28, 2015

I restarted the two travis jobs for you; both failed on x86_64.

@sbromberger
Copy link
Contributor

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},
Copy link
Contributor

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?

Copy link
Contributor

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)

JeffBezanson added a commit that referenced this pull request Aug 28, 2015
Remove specialized sort! method for PartialQuickSort{Int} (fixes #12833)
@JeffBezanson JeffBezanson merged commit 01d8cdf into master Aug 28, 2015
@kmsquire
Copy link
Member Author

@JeffBezanson, can you explain why this additional method caused inference to fail? Too many sort methods? Would @sbromberger's suggestion above fix things? (I guess I could test that, but I don't have time right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants