-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
ENH: Add __array_ufunc__
#8247
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
ENH: Add __array_ufunc__
#8247
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
4fd7e84
ENH: Revert "Temporarily disable __numpy_ufunc__"
charris fcd11d2
ENH: Rename __numpy_ufunc__ to __array_ufunc__.
charris c7b25e2
ENH: Remove position arg from __array_ufunc__.
charris 8a9e790
MAINT: Put PyArray_GetAttrString_SuppressException in get_attr_string.h
njsmith 4dd5380
MAINT: dike out a bunch of weird old code implementing scalar power
njsmith 7d9bc2f
BUG/ENH: Switch to simplified __array_ufunc__/binop interaction
njsmith e4b5163
MAINT: allow __array_ufunc__ = None to force binops to defer.
mhvk 2e6d8c0
MAINT: Split out C code in ufunc_override.h to .c file.
mhvk d5c5ac1
MAINT: Add NPY_NO_EXPORT modifier to PyUFunc_CheckOverride.
charris 3124e96
MAINT: for __array_ufunc__ pass inputs as *args, ensure out is tuple.
mhvk 6a3ca31
DOC: describe current implementation of __array_ufunc__.
mhvk 79bb733
DOC: Style and sphinx fixes for arrays.classes.rst.
charris 7c3dc5a
TST: test that gufuncs are also overridden by __array_ufunc__.
mhvk 71201d2
DOC: Describe __array_func__ in subclassing
mhvk 3041710
ENH: implement ndarray.__array_ufunc__
mhvk 5fe6fc6
DOC Update NEP to reflect actual implementation.
mhvk e092823
MAINT: let ndarray.__array_ufunc__ bail if any overrides are in place.
mhvk 1147894
MAINT: Update array_ufunc NEP.
pv e325a10
DOC: Document behavior of ufuncs with default ndarray.__array_ufunc__
pv 39c2273
DOC: Update ndarray.__array_ufunc__ documentation vs. review comments
pv 6b41d11
DOC: clarify use of super and getattr
mhvk 0ede0e9
DOC: update NEP again.
mhvk 5f9252c
DOC: implement many smaller and bigger changes suggested in review.
mhvk 8cc2f71
BUG,MAINT: ensure out=None is never passed on to __array_ufunc__.
mhvk 856da73
DOC: remove left-over piece discussing binops
mhvk 2b6c7fd
REVERT: remove __array_ufunc__ override for np.dot and ndarray.dot.
mhvk 36e8494
REVERT: remove __array_ufunc__ override for np.matmul.
mhvk 55500b9
MAINT: simplify now that __array_ufunc__ overrides ufuncs only.
mhvk 25e973d
MAINT: split out umath-specific part of ufunc_override.
mhvk b1fa10a
BUG: ensure subclass of override class doesn't segfault.
mhvk 1de8f5a
DOC: Mention `__array_ufunc__` in the 1.13.0 release notes.
charris a460015
DOC: ufunc-overrides: sync the discussion vs. current implementation
pv cd2e42c
DOC: ufunc-overrides: revise hierarchy discussion
pv ff628f1
BUG: Add back removed elision code.
charris 1fc6e63
DOC,TST: clarify example of ndarray subclass using __array_ufunc__
mhvk a431743
BUG: Support nout == 0 and at method
eric-wieser 1e460b7
DOC,MAINT: small corrections to NEP following Stephan's comments.
mhvk 02600d3
ENH: Add NDArrayOperatorsMixin mixin class.
shoyer d3ff023
DOC: clarify recommendations for subclasses, deprecations.
mhvk b9359f1
MAINT: remove unnecessary checks, wrong code for 'outer', cleanup.
mhvk 256a8ae
BUG: Fix ArrayLike(NDArrayOperatorsMixin) operations with object()
shoyer 3272a86
ENH: Better error message for __array_ufunc__ not implemented
shoyer 32221df
ENH: NDArrayOperatorsMixin calls ufuncs directly, like ndarray
shoyer 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
REVERT: remove __array_ufunc__ override for np.matmul.
- Loading branch information
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
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
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.
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 don't think this implementation is correct. What if the caller provided the output array? That looks like it gets dropped. A bigger complication I think might be lurking is if out was provided and is some funky, nonstandard class it could potentially break anything. That would be another thing this method would need to check for, and would apply to almost any implementation.
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.
That documentation is incorrect. The signature is
Out(s) always ends up in
kwargs
in a tuple. Currently, if no out arrays supplied then noout
keyword. As for funky classes, I think we should require them to clean up their act ;)Uh oh!
There was an error while loading. Please reload this page.
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.
Note also that the arguments are "normalized" before the call to
__array_ufunc__
so that only the input arrays are ininputs
, everything else is put intokwargs
.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.
Agreed. However my point is that kwargs is never used. It is only part of the function definition. That's what I mean by "it gets dropped".
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.
@mattharrigan - for this part, best to look at the new version of this NEP... charris#11 (I think I got all your other commens; 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.
@mhvk I don't think you got my comment, sorry it wasn't clear enough. In your example implementation kwargs is part of the method signature but it is never used. I think kwargs must be passed on to np.multiply and np.dot. For instance, doubt this will work as desired: "np.multiply(asp, a, out=b)"
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.
Sorry for not looking carefully enough -- somehow I had not quite seen that you were commenting on the
demo
example -- I'm afraid this is left-over from the original PR, which is also why there still is thispos
argument; another thing that should change here is that the example is withmatmul
, and that the whole setup follows "best practice" (which we still need to agree on...).