Skip to content

Test sort_int_range! for reverse sorting of large unsigned types#42718

Closed
LilithHafner wants to merge 2 commits intoJuliaLang:masterfrom
LilithHafner:patch-1
Closed

Test sort_int_range! for reverse sorting of large unsigned types#42718
LilithHafner wants to merge 2 commits intoJuliaLang:masterfrom
LilithHafner:patch-1

Conversation

@LilithHafner
Copy link
Copy Markdown
Member

@LilithHafner LilithHafner commented Oct 20, 2021

Fixes #43034

v = rand(UInt64(1):UInt64(2), 7)
issorted(sort(v; rev=true); rev=true) # false

The bug was in iterating over a reversed unsigned range (which is not possible). It only comes up for 'UInt, UInt64&UInt128because the signed1::Intpromotes to a signed result if theUIntis smaller in1:rangelen`.

This came up in the process of building a comprehensive sorting test suite which may or may not ever end up suitable for merging into SortingAlgorithms or Base. It tests on many input types, which catches things like this, but results in very long compilation times (~30s) and a lot of compiled code (GBs).

@LilithHafner
Copy link
Copy Markdown
Member Author

I also renamed where to counts because I think counts is more descriptive, and also where is a keyword.

@vtjnash
Copy link
Copy Markdown
Member

vtjnash commented Nov 11, 2021

Sorry that we missed this! Do you think #29842 solves this for you? I think that may be a more complete fix.

Copy link
Copy Markdown
Member

@tkf tkf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it'd be nice if we can fix it at the level of reverse, as in #29842. But I think the test is a nice addition.

I think it'd be better to do the refactoring where -> counts in a separate PR. It's hard to explain a big diff (when squashed) like this in a concise commit message and hard to know what has been done when people revisit this in the future.

@LilithHafner
Copy link
Copy Markdown
Member Author

@vtjnash yes, that would fix it. I agree that it would also be a better solution.
@tkf, I'll revert this back to the first commit adding the test and make a separate PR for where -> counts

@LilithHafner
Copy link
Copy Markdown
Member Author

The rename PR is #43052

@LilithHafner LilithHafner changed the title Fix sort_int_range! for reverse sorting of large unsigned types Test sort_int_range! for reverse sorting of large unsigned types Nov 12, 2021
@tkf
Copy link
Copy Markdown
Member

tkf commented Nov 12, 2021

It looks like @vtjnash already merged this PR into #29842. I put closes #42718 there so that this PR will be closed once #29842 lands.

@LilithHafner LilithHafner deleted the patch-1 branch May 12, 2022 13:43
@ViralBShah ViralBShah added the sorting Put things in order label Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sorting Put things in order

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sorting broken on an edge case

4 participants