[Numpy-discussion] NEP: Dispatch Mechanism for NumPy’s high level API

Stephan Hoyer shoyer at gmail.com
Sun Jun 3 19:45:54 EDT 2018


On Sun, Jun 3, 2018 at 4:25 PM Marten van Kerkwijk <
m.h.vankerkwijk at gmail.com> wrote:

> I think one might still want to know *where* the type occurs (e.g., as an
> output or index would have different implications).
>

This in certainly true in general, but given the complete flexibility of
__array_function__ there's no way we can make every check convenient. The
best we can do is make it easy to handle the common cases, where the
argument position does not matter.


> Possibly, a solution would rely on the same structure as used for the
> "dance". But as a general point, I don't see the advantage of passing types
> rather than arguments - less information for no benefit.
>

Maybe this is premature optimization, but there will certainly be fewer
unique types than arguments to check for types. I suspect this may make for
a noticeable difference in performance in use cases involving a large
number of argument.

For example, suppose np.concatenate() is called on a list of 10,000 dask
arrays. Now dask.array.Array.__array_function__ needs to check all
arguments to decide whether it can use dask.array.concatenate() or needs to
return NotImplemented. By using the `types` argument, it only needs to do
isinstance() checks on the single argument in `types`, rather than all
10,000 overloaded function arguments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180603/25653d72/attachment.html>


More information about the NumPy-Discussion mailing list