Skip to content

MAINT: Simplify C++ sorting tags#31352

Merged
charris merged 1 commit into
numpy:mainfrom
seberg:simplify-sort-tags
Apr 28, 2026
Merged

MAINT: Simplify C++ sorting tags#31352
charris merged 1 commit into
numpy:mainfrom
seberg:simplify-sort-tags

Conversation

@seberg
Copy link
Copy Markdown
Member

@seberg seberg commented Apr 28, 2026

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.)

(Heavy use of claude, as it is mechanical replacement in a sense. -- It first gave me silly macros to make it shorter...)

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.)
@seberg seberg force-pushed the simplify-sort-tags branch from ca932d6 to 87d3041 Compare April 28, 2026 11:36
@seberg
Copy link
Copy Markdown
Member Author

seberg commented Apr 28, 2026

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.

@MaanasArora
Copy link
Copy Markdown
Contributor

MaanasArora commented Apr 28, 2026

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!

@seberg seberg changed the title MAINT: Simplify sorting tags (I didn't try to remove them...) MAINT: Simplify C++ sorting tags Apr 28, 2026
@charris
Copy link
Copy Markdown
Member

charris commented Apr 28, 2026

Wow, it's almost readable :) Thanks Sebastian.

@charris charris merged commit 6ec400a into numpy:main Apr 28, 2026
103 of 106 checks passed
@seberg seberg deleted the simplify-sort-tags branch April 29, 2026 06:00
MaanasArora pushed a commit to MaanasArora/numpy that referenced this pull request May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants