[Numpy-discussion] Adding to the non-dispatched implementation of NumPy methods

Nathaniel Smith njs at pobox.com
Tue Apr 23 03:09:07 EDT 2019

On Mon, Apr 22, 2019 at 11:13 PM Stephan Hoyer <shoyer at gmail.com> wrote:
>> On Mon, Apr 22, 2019 at 9:26 PM Nathaniel Smith <njs at pobox.com> wrote:
>>> Your last email didn't really clarify anything for me. I get that np.func.__numpy_implementation__ is intended to have the semantics of numpy's implementation of func, but that doesn't tell me much :-). And also, that's exactly the definition of np.func, isn't it?
> My understanding of the protocol we came up with in NEP-18 is that every NumPy function (that takes array-like arguments) now has two parts to its implementation:
> 1. The NEP-18 part involving calling the dispatcher function, and checking for/calling __array_function__ attributes on array-like arguments. This part is documented in NEP-18.
> 2. The original function definition, which is called if either (a) no __array_function__ attributes exist, or (b) the only __array_function__ attribute is numpy.ndarray.__array_function__. This part is documented in the docstring of the NumPy function.
> "__numpy_implementation__" provides a short-cut to (2) without (1). That's it.

OK, so the semantics are: the same as the normal function, except we
pretend that none of the arguments have an __array_function__

That's much clearer to me than how you were phrasing it before :-).
Though now the name "__numpy_implementation__" doesn't seem very
evocative of what it does... numpy's dispatch sequence has changed a
lot in the past (mostly adding new coercion rules), and will probably
change in the future, and "__numpy_implementation__" doesn't give much
guidance about which parts of the dispatch sequence should be skipped
as "dispatch" and which should be included as "implementation". Maybe
something like __skipping_array_function__?


Nathaniel J. Smith -- https://vorpus.org

More information about the NumPy-Discussion mailing list