[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
current implementation;
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,
*args, **kwargs)
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
```
return function.__implementation__(*args,
coercion_function=np.asanyarray, **kwargs)
```
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,
Marten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20190425/f5802628/attachment.html>
More information about the NumPy-Discussion
mailing list