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

Marten van Kerkwijk m.h.vankerkwijk at gmail.com
Sun Apr 28 11:40:53 EDT 2019


Hi Ralf,

Thanks for the comments and summary slides. I think you're
over-interpreting my wish to break people's code! I certainly believe - and
think we all agree - that we remain as committed as ever to ensure that
```
np.function(inputs)
```
continues to work just as before. My main comment is that I want to ensure
that no similar guarantee will exist for
```
np.function.__wrapped__(inputs)
```
(or whatever we call it). I think that is quite consistent with NEP-18,
since as originally written there was not even the possibility to access
the implementation directly (which was after long discussions about whether
to allow it, including ideas like `import numpy.internal_apt as np`). In
this respect, the current proposal is a large deviation from the original
intent, so we need to be clear about what we are promising.

In summary, I think the guarantees should be as follows:
1.If you call np.function and
  - do not define __array_function__, changes happen only via the usual
cycle.
  - define __array_function__, you take responsibility for returning the
result.
2. If you call np.function.__wrapped__ and
  - input only ndarray, changes happen only via the usual cycle;
  - input anything but ndarray, changes can happen in any release.

On the larger picture,in your slides, the further split that happens is
that if no override is present, the first thing that actually gets called
is not the function implementation but rather `ndarray.__array_function__`.
I think it is important to add this to your mental image (and the slides),
since it means that generic parts of the implementations (like coercion
;-), can be moved there. For ufuncs, this is relatively easy, for other
functions less so since they differ quite a bit in what coercion they do.

All the best,

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


More information about the NumPy-Discussion mailing list