-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow using __array_function__
as a fallback for missing Array API functions
#9530
Conversation
We don't do this anywhere elsewhere, so it doesn't make sense to do this only for `nanprod`.
This seems good, but does it cover this comment? #8834 (comment) |
Thanks @keewis - this would be very helpful! |
I don't think it does, but I think array types that implement both |
This almost certainly breaks vectorized indexing with cupy if you don't implement the fallback Though how are the pint tests passing? Do we have indexing tests with pint? |
As far as I can tell, That said, we should definitely try to provide an implementation for |
OK yes, lot less urgent then. I thought they had all implemented |
|
if hasattr(array, "__array_namespace__"): | ||
return ArrayApiIndexingAdapter(array) | ||
if hasattr(array, "__array_function__"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused now, why does the indexing adapter affect what's used for reductions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's the case. What I mentioned in the meeting was that we could use __array_function__
as a fallback for nan*
reductions, whereas choosing the wrong indexing adapter will cause xarray
to try indexing with a method the array type might not support.
I guess this is kinda hard to figure out implicitly, and I'd love to have a way (a special attribute like __xarray_preferred_array_protocol__
?) to explicitly communicate which protocol is preferred. That way, we won't have to worry about cupy
and pint
implementing the Array API, and cubed
can just set that attribute to state that it considers __array_function__
a fallback and instead prefers to use __array_namespace__
indexing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array_function as a fallback for nan* reductions,
👍 sorry I got confused.
As discussed in #8834 (comment), this swaps the order of special casing for types implementing both
__array_function__
and__array_namespace__
, such that the Array API is preferred over__array_function__
.I've also disabled passing the
out
kwarg tonanprod
, as that was the only occurrence where we actually do that, all othernan*
functions silently ignore that kwarg.whats-new.rst
cc @tomwhite