MAINT: Simplify C++ sorting tags#31352
Merged
Merged
Conversation
Manaas sorting PR added a huge amount of duplication, but while this all might have made sense with C++11, the whole pattern is a ridiculous amount of code-duplication with C++17. This cleans it up, I used claude with guidance/follow-up, not sure if the `_type` pattern is best, but it works well and only changes the `_tag` header for now, which is nice. For the next step this should make things rather simple: We can introduce a `cmp<bool reverse>` template function (at worst per kind), I think. (It also removed the unused `_SWAP` macros, the most complicated change is moving the half helpers into the `numpy_tag.h` file, which is nicer, IMO.)
ca932d6 to
87d3041
Compare
Member
Author
|
Would be nice to get this in fairly quickly, so that gh-31345 can be rebased on top of it and avoid bloating it even more. |
Contributor
|
Very nice, huge deletions! I did wonder why the integer/float compares or less equals were duplicated, when basically identical... it might have been C++ 11, but for less equal in particular a base template could have cleared a lot up anyway! Sorry, I just didn't realize this was legacy I guess. Yeah, a bool argument to the template makes sense, we would probably still need greater functions for float at least, because of NaNs. But this should definitely make things much smaller, thanks a lot! |
Member
|
Wow, it's almost readable :) Thanks Sebastian. |
charris
approved these changes
Apr 28, 2026
MaanasArora
pushed a commit
to MaanasArora/numpy
that referenced
this pull request
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Manaas sorting PR added a huge amount of duplication, but while this all might have made sense with C++11, the whole pattern is a ridiculous amount of code-duplication with C++17.
This cleans it up, I used claude with guidance/follow-up, not sure if the
_typepattern is best, but it works well and only changes the_tagheader for now, which is nice.For the next step this should make things rather simple: We can introduce a
cmp<bool reverse>template function (at worst per kind), I think.(It also removed the unused
_SWAPmacros, the most complicated change is moving the half helpers into thenumpy_tag.hfile, which is nicer, IMO.)(Heavy use of claude, as it is mechanical replacement in a sense. -- It first gave me silly macros to make it shorter...)