[Numpy-discussion] Should unique types of all arguments be passed on in __array_function__?

Marten van Kerkwijk m.h.vankerkwijk at gmail.com
Sun Nov 4 10:59:24 EST 2018


Hi All,

While thinking about implementations using __array_function__, I wondered
whether the "types" argument passed on is not defined too narrowly.
Currently, it only contains the types of arguments that provide
__array_ufunc__, but  wouldn't it make more sense to provide the unique
types of all arguments, independently of whether those types have defined
__array_ufunc__? It would seem quite useful for any override to know, e.g.,
whether a string or an integer is passed on.

I thought of this partially as I was wondering how an implementation for
ndarray itself would look like. For that, it is definitely useful to know
all unique types, since if it is only ndarray, no casting whatsoever needs
to be done, while if there are integers, lists, etc, an attempt has to be
made to turn these into arrays (i.e., the `as[any]array` calls currently
present in the implementations, which really more logically are part of
`ndarray.__array_function__` dispatch).

Should we change this? It is quite trivially done, but perhaps I am missing
a reason for omitting the non-override types.

All the best,

Marten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20181104/30ed894f/attachment.html>


More information about the NumPy-Discussion mailing list