Skip to content
Navigation Menu
{{ message }}
-
-
Notifications
You must be signed in to change notification settings - Fork 12.5k
ENH: Add registration for sorting loops using new ufunc convenience function #29900
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
edd072f
ENH: Add registration for sort and argsort in new convenience ufunc r…
MaanasArora 7bc78c2
Go back to cached import for sort/argsort
seberg b5ee0f0
DOC: Add release notes for #29900
MaanasArora ba50a25
MAINT: Just pass on errors instead of raising.
mhvk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| A new `PyUFunc_AddLoopsFromSpecs` convenience function has been added to the C API. | ||
| ----------------------------------------------------------------------------------- | ||
| This function allows adding multiple ufunc loops from their specs in one call using | ||
| a NULL-terminated array of `PyUFunc_LoopSlot` structs. It allows registering | ||
| sorting and argsorting loops using the new ArrayMethod API. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| DType sorting and argsorting supports the ArrayMethod API | ||
| --------------------------------------------------------- | ||
| User-defined dtypes can now implement custom sorting and argsorting using | ||
| the ArrayMethod API. This mechanism can be used in place of the `PyArray_ArrFuncs` | ||
| slots which may be deprecated in the future. | ||
|
|
||
| The sorting and argsorting methods are registered by passing the arraymethod | ||
| specs that implement the operations to the new `PyUFunc_AddLoopsFromSpecs` function. | ||
| See the ArrayMethod API documentation for details. |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
You can’t perform that action at this time.

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.
This is slightly vague. Where is this name found? Could one register for a ufunc defined outside numpy? I think by default it should be looked up on
np, but one should be able to give a name including package. I guess one can test this using some of the private test ufuncs.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.
We could do this, I think. The logic would be to allow for a
:, if given, you import the part before the:and then useGetAttrfor the part after (in principle should support.in the second part too).It might be that the import mechanism can already do both in one go, but I am not sure. If it is tedious in C, could create a little Python helper to do it since it is very easy there, e.g. something like this
And if there is no
:we would just go withnumpy(and maybe the internal ufunc module as well to robustify it).I am wondering if it makes sense to provision for when the object isn't found (or not a ufunc). We could for example allow for
"?numpy.strings:..."to make it easier to support across versions.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 keep thinking about nice ways to expand, but the more I do so, the more it is clear that we should not go there now!
So, just a small comment: I would call this entry plain "name" -- it is already in the "UFunc_LoopSlot" namespace, so adding
ufunc_seems superfluous.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.
Makes sense - I agree adding more detail could be a bit broad at this time maybe! I've changed the
ufunc_nametoname, thanks!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 am happy to not do it here, but I am curious about your reasoning :). I suppose it may be weird enough to support for non-numpy and honestly, writing this helper isn't hard (although this type of convenience seems to make more of a dent than I tend to expect).
Anyway, one thing we don't yet support, but happy to also defer is adding ufuncs that are not available in the main namespace.