Allow libraries to negotiate that they understand e.g. NumPy arrays? #774
Replies: 4 comments
-
Doesn't this require n-way multiple dispatch in general? How does |
Beta Was this translation helpful? Give feedback.
-
(As a correction from the above, accepting NumPy and maybe CuPy arrays can be interesting also for JAX/torch/...) It came up again in SciPy now, so going to list some references:
IMO it is a mistake not to provision for this and there is a reason everyone seems to have some (basic) solution. Yes, I also think that this should be very restrictive/conservative (but that mainly a documentation thing in most schemes). Of course what is actually important is the downstream need/ask, because array-api should adapt to those needs. From my side, I think there is enough evidence. We can say its not yet enough, but that can clearly change at this point in time. |
Beta Was this translation helpful? Give feedback.
-
There's several questions one could ask here:
In general, yes. It's pretty well explained in this section of NEP 18. Basically " subclasses before superclasses, and otherwise left to right", and then let each handler decide whether it can deal with foreign array objects or if it wants to return |
Beta Was this translation helpful? Give feedback.
-
I thought we decided that this kind of usage is UB (#399) but it might actually be good to at least revisit and reconfirm this. Another use case is pint+dask+cupy+xarray: pydata/xarray#7721 |
Beta Was this translation helpful? Give feedback.
-
Today dask came up a few times and also the possibility of a fallback to
__array_function__
for transitioning at least.This must have come up before, but did we ever discuss an API like:
which is not really important if you think about numpy, jax, torch, tensorflow: I don't think you should mix them really! But it seems more becomes interesting if we start talking about dask or quantities which are designed as wrappers?
The answer can be that this is not our problem have to coerce manually. In the NumPy world, we could actually just write
get_namespace
as:(and assume others will return their namespace, since in practice everyone has it de-facto)
Beta Was this translation helpful? Give feedback.
All reactions