-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
ENH: Add __array_ufunc__
#8247
ENH: Add __array_ufunc__
#8247
Commits on Apr 27, 2017
-
ENH: Revert "Temporarily disable __numpy_ufunc__"
This reverts commit bac094c and enables __numpy_ufunc__ for development in the NumPy 1.13.0 development cycle.
Configuration menu - View commit details
-
Copy full SHA for 4fd7e84 - Browse repository at this point
Copy the full SHA 4fd7e84View commit details -
ENH: Rename __numpy_ufunc__ to __array_ufunc__.
The first commit in changing __numpy_ufunc__ by removing the index argument and making the out argument value always a tuple. These changes were proposed in numpygh-5986 and have been accepted. Renaming before further changes avoids triggering tests in scipy and astropy while keeping the numpy tests working.
Configuration menu - View commit details
-
Copy full SHA for fcd11d2 - Browse repository at this point
Copy the full SHA fcd11d2View commit details -
ENH: Remove position arg from __array_ufunc__.
Previously when __array_ufunc__ for one of the ufunc arguments was called, that arguments position was passed in the call. This PR removes that argument as proposed in numpygh-5986.
Configuration menu - View commit details
-
Copy full SHA for c7b25e2 - Browse repository at this point
Copy the full SHA c7b25e2View commit details -
MAINT: Put PyArray_GetAttrString_SuppressException in get_attr_string.h
This is an ugly kluge, but until we merge multiarray.so and umath.so moving stuff into private/*.h serves as a reasonable workaround.
Configuration menu - View commit details
-
Copy full SHA for 8a9e790 - Browse repository at this point
Copy the full SHA 8a9e790View commit details -
MAINT: dike out a bunch of weird old code implementing scalar power
For some reason, np.generic.__pow__ felt the need to reimplement Python's full binop dispatch logic. The code has been there since the beginning of (git) history, isn't required to pass any tests, and AFAICT doesn't actually do anything interesting. I suspect it was just split apart from the (much more trivial) implementation of all the other np.generic binop methods because nb_power has a slightly different signature than all the others (it takes an extra argument, which we ignore, but still has to be accepted and passed as appropriate), and then got forgotten when the other implementations were simplified long ago. This commit throws away all that code and makes gentype_power a 2-liner, just like all the other gentype_@name@ methods.
Configuration menu - View commit details
-
Copy full SHA for 4dd5380 - Browse repository at this point
Copy the full SHA 4dd5380View commit details -
BUG/ENH: Switch to simplified __array_ufunc__/binop interaction
As per the discussion at numpygh-5844, and in particular numpy#5844 (comment) this commit switches binop dispatch to mostly defer to ufuncs, except in some specific cases elaborated in a long comment in number.c. The basic strategy is to define a single piece of C code that knows how to handle forward binop overrides, and we put it into private/binop_override.h so that it can be accessed by both the array code in multiarray.so and the scalar code in umath.so.
Configuration menu - View commit details
-
Copy full SHA for 7d9bc2f - Browse repository at this point
Copy the full SHA 7d9bc2fView commit details -
MAINT: allow __array_ufunc__ = None to force binops to defer.
In previous versions, one could force ndarray binops to defer by setting a high __array_priority__. With __array_ufunc__ this gets ignored, and this commit ensures it is still possible to avoid using the standard python language feature that setting something to None means it is not implemented. In consequence, inside a ufunc, if __array_ufunc__ is None, it will be treated as if it had returned NotImplemented (leading to a TypeError if no other object had a functioning __array_ufunc__ override).
Configuration menu - View commit details
-
Copy full SHA for e4b5163 - Browse repository at this point
Copy the full SHA e4b5163View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2e6d8c0 - Browse repository at this point
Copy the full SHA 2e6d8c0View commit details -
Configuration menu - View commit details
-
Copy full SHA for d5c5ac1 - Browse repository at this point
Copy the full SHA d5c5ac1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3124e96 - Browse repository at this point
Copy the full SHA 3124e96View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6a3ca31 - Browse repository at this point
Copy the full SHA 6a3ca31View commit details -
Configuration menu - View commit details
-
Copy full SHA for 79bb733 - Browse repository at this point
Copy the full SHA 79bb733View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7c3dc5a - Browse repository at this point
Copy the full SHA 7c3dc5aView commit details -
DOC: Describe __array_func__ in subclassing
This includes the use of super everywhere, and in the brief description of __array_ufunc__ in the reference section.
Configuration menu - View commit details
-
Copy full SHA for 71201d2 - Browse repository at this point
Copy the full SHA 71201d2View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3041710 - Browse repository at this point
Copy the full SHA 3041710View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5fe6fc6 - Browse repository at this point
Copy the full SHA 5fe6fc6View commit details -
MAINT: let ndarray.__array_ufunc__ bail if any overrides are in place.
As part of this, split off the checking for overrides from the actual trying to execute them (in ufunc_override.c), so that just the check can be done in ndarray.__array_ufunc__.
Configuration menu - View commit details
-
Copy full SHA for e092823 - Browse repository at this point
Copy the full SHA e092823View commit details -
MAINT: Update array_ufunc NEP.
Bring into compliance with current ndarray.__array_ufunc__ implementation and type casting hierarchy.
Configuration menu - View commit details
-
Copy full SHA for 1147894 - Browse repository at this point
Copy the full SHA 1147894View commit details -
Configuration menu - View commit details
-
Copy full SHA for e325a10 - Browse repository at this point
Copy the full SHA e325a10View commit details -
Configuration menu - View commit details
-
Copy full SHA for 39c2273 - Browse repository at this point
Copy the full SHA 39c2273View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6b41d11 - Browse repository at this point
Copy the full SHA 6b41d11View commit details -
Configuration menu - View commit details
-
Copy full SHA for 0ede0e9 - Browse repository at this point
Copy the full SHA 0ede0e9View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5f9252c - Browse repository at this point
Copy the full SHA 5f9252cView commit details -
BUG,MAINT: ensure out=None is never passed on to __array_ufunc__.
As part of this, it turns out the number of output arguments nout was needed, so that was passed in. Also, testing showed that arguments passed in both as positional and keyword arguments were not caught, so a duplication check was added.
Configuration menu - View commit details
-
Copy full SHA for 8cc2f71 - Browse repository at this point
Copy the full SHA 8cc2f71View commit details -
DOC: remove left-over piece discussing binops
The text had been changed following the suggestion of @njsmith, but somehow I had forgotten to delete the original.
Configuration menu - View commit details
-
Copy full SHA for 856da73 - Browse repository at this point
Copy the full SHA 856da73View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2b6c7fd - Browse repository at this point
Copy the full SHA 2b6c7fdView commit details -
Configuration menu - View commit details
-
Copy full SHA for 36e8494 - Browse repository at this point
Copy the full SHA 36e8494View commit details -
MAINT: simplify now that __array_ufunc__ overrides ufuncs only.
In particular, use fact that we're guaranteed to have a PyUFuncObject in PyUFunc_CheckOverride.
Configuration menu - View commit details
-
Copy full SHA for 55500b9 - Browse repository at this point
Copy the full SHA 55500b9View commit details -
MAINT: split out umath-specific part of ufunc_override.
And put it in src/umath instead of src/private. This leaves only the PyUFunc_WithOverride function in ufunc_override.c, which is all that is needed outside of umath (it is called by array_ufunc in multiarray/methods.c).
Configuration menu - View commit details
-
Copy full SHA for 25e973d - Browse repository at this point
Copy the full SHA 25e973dView commit details -
Configuration menu - View commit details
-
Copy full SHA for b1fa10a - Browse repository at this point
Copy the full SHA b1fa10aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 1de8f5a - Browse repository at this point
Copy the full SHA 1de8f5aView commit details -
Configuration menu - View commit details
-
Copy full SHA for a460015 - Browse repository at this point
Copy the full SHA a460015View commit details -
Configuration menu - View commit details
-
Copy full SHA for cd2e42c - Browse repository at this point
Copy the full SHA cd2e42cView commit details -
BUG: Add back removed elision code.
Code inadvertantly removed in rebasing old PR on new work.
Configuration menu - View commit details
-
Copy full SHA for ff628f1 - Browse repository at this point
Copy the full SHA ff628f1View commit details -
DOC,TST: clarify example of ndarray subclass using __array_ufunc__
Also add a few more tests of the same example for good measure.
Configuration menu - View commit details
-
Copy full SHA for 1fc6e63 - Browse repository at this point
Copy the full SHA 1fc6e63View commit details -
Configuration menu - View commit details
-
Copy full SHA for a431743 - Browse repository at this point
Copy the full SHA a431743View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1e460b7 - Browse repository at this point
Copy the full SHA 1e460b7View commit details -
ENH: Add NDArrayOperatorsMixin mixin class.
This mixin class provides an easy way to implement arithmetic operators that defer to __array_ufunc__ like numpy.ndarray in non-ndarray subclasses.
Configuration menu - View commit details
-
Copy full SHA for 02600d3 - Browse repository at this point
Copy the full SHA 02600d3View commit details -
Configuration menu - View commit details
-
Copy full SHA for d3ff023 - Browse repository at this point
Copy the full SHA d3ff023View commit details -
Configuration menu - View commit details
-
Copy full SHA for b9359f1 - Browse repository at this point
Copy the full SHA b9359f1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 256a8ae - Browse repository at this point
Copy the full SHA 256a8aeView commit details -
ENH: Better error message for __array_ufunc__ not implemented
* ENH: Better error message for __array_ufunc__ not implemented New behavior: >>> import numpy as np >>> class Dummy: ... def __array_ufunc__(self, *args, **kwargs): ... return NotImplemented >>> np.negative(Dummy()) TypeError: operand type(s) do not implement __array_ufunc__( <ufunc 'negative'>, '__call__', <__main__.Dummy object at 0x1106df8d0>): 'Dummy' * check for null errmsg_formatter
Configuration menu - View commit details
-
Copy full SHA for 3272a86 - Browse repository at this point
Copy the full SHA 3272a86View commit details -
ENH: NDArrayOperatorsMixin calls ufuncs directly, like ndarray
* ENH: NDArrayOperatorsMixin calls ufuncs directly, like ndarray Per our discussion in numpy#8247 (comment) * add back in accidentally dropped __repr__
Configuration menu - View commit details
-
Copy full SHA for 32221df - Browse repository at this point
Copy the full SHA 32221dfView commit details