-
-
Notifications
You must be signed in to change notification settings - Fork 12k
Closed
Description
In the __array__ documentation it says:
If a class (ndarray subclass or not) having the
__array__method is used as the output object of an ufunc, results will be written to the object returned by__array__.
however, this does not seem to be the case, as this example shows:
import numpy as np
class NDLike(object):
def __init__(self, values):
self.values = np.asarray(values)
def __array__(self):
return self.values
def __array_wrap__(self, result):
return type(self)(result)
def __repr__(self):
return "[%s]\n%s" % (type(self), self.values)
# Adding these make no difference
def __array_prepare__(self, array, context=None):
return array.values if isinstance(array, NDLike) else array
__array_priority__ = 1000000.0this works:
>>> x = NDLike([1, 2, 3])
>>> np.negative(x)
[<class '__main__.NDLike'>]
[-1 -2 -3]while this doesnt:
>>> x = NDLike([1, 2, 3])
>>> out = NDLike([0, 0, 0])
>>> np.negative(x, out=out)
TypeError: return arrays must be of ArrayTypeClearly, there is no attempt to call __array__ on out.
It seems either the documentation is wrong, or the implementation is lacking.
Enviromenment: Windows 10, python 2.7.11, numpy 1.10.1
Metadata
Metadata
Assignees
Labels
No labels