[Numpy-discussion] Behavior of __array_wrap__?
Travis E. Oliphant
Wed Apr 2 11:20:22 CDT 2008
Brian Granger wrote:
> I am creating a custom array type (distributed memory arrays -
> DistArray) and I am using the __array__ and __array_wrap__ methods and
> __array_priority__ attribute to get these arrays to work with numpy's
> ufuncs. Things are working fine when I call a ufunc like this:
> # This works fine (c comes back as an DistArray)
> a = DistArray(10)
> b = DistArray(10)
> c = np.add(a, b)
> But, when you pass in an ndarray as the return array, the
> __array_wrap__ doesn't get called:
That is true. Currently, the output argument must be an ndarray,
because the idea is to save memory.
If you have an object that uses __array_wrap__ to channel the output
back into your object's memory, then there is no benefit to the output
It could be possible to allow additional output arguments that are not
ndarrays to be syntactic sugar for __array_wrap__, but this has not been
done and if the documentation led you to believe that it was possible,
then the docs need to be updated.
More information about the Numpy-discussion