[Numpy-svn] [numpy/numpy] 367b40: BUG: core: ensure binop execution uses ufuncs as f...
GitHub
noreply at github.com
Tue May 5 22:39:14 EDT 2015
Branch: refs/heads/master
Home: https://github.com/numpy/numpy
Commit: 367b4094125062fa9018db0f310b28780259f29b
https://github.com/numpy/numpy/commit/367b4094125062fa9018db0f310b28780259f29b
Author: Pauli Virtanen <pav at iki.fi>
Date: 2015-04-04 (Sat, 04 Apr 2015)
Changed paths:
M numpy/core/src/multiarray/arrayobject.c
M numpy/core/src/multiarray/number.c
Log Message:
-----------
BUG: core: ensure binop execution uses ufuncs as fallback
These changes only affect objects defining __numpy_ufunc__. Other
objects use the __array_priority__ mechanism to decide whether
NotImplemented should be returned or not.
The binops previously returned NotImplemented even if other._r<op>__ is
ndarray.__r<op>__, rather than trying to evaluate the result via ufuncs.
This causes problems in binops of two objects that both subclass from
ndarray and define __numpy_ufunc__.
The solution added here makes the total logic as follows:
def __binop__(self, other):
if (hasattr(other, '__numpy_ufunc__') and
not isinstance(other, self.__class__) and
hasattr(other, '__rop__') and
other.__class__.__rop__ is not self.__class__.__rop__):
return NotImplemented
return np.binop(self, other)
Commit: 6ba4fed3aa26979734faa462e172959fad69723b
https://github.com/numpy/numpy/commit/6ba4fed3aa26979734faa462e172959fad69723b
Author: Pauli Virtanen <pav at iki.fi>
Date: 2015-04-04 (Sat, 04 Apr 2015)
Changed paths:
M numpy/core/src/multiarray/number.c
Log Message:
-----------
BUG: core: inplace ops don't have corresponding rhs ops, so no need to check the slot
Commit: d1153b4cba5510bd1961e3a7ae7f0c07c124a202
https://github.com/numpy/numpy/commit/d1153b4cba5510bd1961e3a7ae7f0c07c124a202
Author: Marten van Kerkwijk <mhvk at astro.utoronto.ca>
Date: 2015-04-04 (Sat, 04 Apr 2015)
Changed paths:
M numpy/core/tests/test_multiarray.py
Log Message:
-----------
Add tests that __numpy_ufunc__ works with subclasses.
In particular, for a class S3(S2), where S2 defines __numpy_ufunc__, ensure
that, e.g., S3() + S2() does *not* pass control to S2 if S2 and S3 share the
same __radd__.
Commit: eecb2e3c07f29c0ac991d364a846a2f8293a432a
https://github.com/numpy/numpy/commit/eecb2e3c07f29c0ac991d364a846a2f8293a432a
Author: Charles Harris <charlesr.harris at gmail.com>
Date: 2015-05-05 (Tue, 05 May 2015)
Changed paths:
M numpy/core/src/multiarray/arrayobject.c
M numpy/core/src/multiarray/number.c
M numpy/core/tests/test_multiarray.py
Log Message:
-----------
Merge pull request #5748 from mhvk/numpyufunc-binop-fix
BUG Numpy ufunc binop fix for subclasses with __numpy_ufunc__ (closes #4815)
Compare: https://github.com/numpy/numpy/compare/a29c296f0bf3...eecb2e3c07f2
More information about the Numpy-svn
mailing list