-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
ENH: Add sort_compare dtype slot to register new-style sorts
#30415
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
base: main
Are you sure you want to change the base?
Conversation
…comparison function
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.
doc/source/reference/c-api/array.rst
Outdated
| If defined, implements a comparison function for two array elements | ||
| for use in sorting and argsorting. This can be defined in place of the | ||
| custom sort functions using the ArrayMethod API (see :ref:`array-methods-sorting`) | ||
| to implement sorting for the DType. |
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.
maybe add a mention for why you'd want to do this - e.g. if comparisons have some big cost that can be amortized over the whole array
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.
I've added a note - a bit on the detailed side, hopefully that works, thanks!
|
Thanks for looking @ngoldbaum!
Agreed, the full loop implementation would probably be overkill in many cases. I think this would be necessary to expose the sorts on the user-dtypes too since they don't define full sorts now, so a good way to test the new infrastructure! |
Follows #29737 and #30328 (and supersedes #29987) to implement a
sort_compareslot that can be used to register sorting methods using a comparison function. This functionality also existed in the ArrFuncs slots, but now we implement the new-style sorting methods, and the array method context is passed to the comparison function rather than the array itself.I've tested this with
mpfdtypeon the user dtypes repo (though having a bit of an issue with installation... the slot wasn't visible there, so had to redefine just the macro). Unfortunately there don't seem to be dtypes we can write tests for within numpy itself, though I did a small experiment with the scaled float dtype. ping @seberg @mhvk @ngoldbaum if you're interested - thanks!