[Numpy-discussion] Adding to the non-dispatched implementation of NumPy methods
Marten van Kerkwijk
m.h.vankerkwijk at gmail.com
Thu Apr 25 15:44:58 EDT 2019
It seems we are adding to the wishlist! I see four so far:
1. Exposed in API, can be overridden with __array_ufunc__
2. One that converts everything to ndarray (or subclass); essentially the
3. One that does asduckarray
4. One that assumes all arguments are arrays.
Maybe handiest would be if there is a method to coerce all relevant
arguments with a function of one's choice? I.e., in the example of Stephan,
one would have
if function in JUST_COERCE:
coerced_args, coerced_kwargs = function.__coerce__(np.asanyarray,
return function.__implementation__(*coerced_args, **coerced_kwargs)
Actually, this might in fact work with the plan proposed here, if we allow
for an extra, optional kwarg that contains the coercion function, that is
The possible advantage of this over yet more dunder methods is that one can
fine-tune the extent to which something has to mimic an array properly
(e.g., run `asanyarray` only if `shape` is not present).
It would be nice, though, if we could end up with also option 4 being
available, if only because code that just can assume ndarray will be
easiest to read.
All the best,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion