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
use __array_function__ on functions outside numpy #13872
Comments
I think this is working as expected, though there is indeed something surprising going on here. By using How then could dask and sparse know how to handle I suppose this is arguably a bug in dask's |
that implementation would make
Indeed. That will always be the case when using |
I don't think it particularly matters in most cases. As long as the design is consistent, there's not much overhead in adding another special method. That said, we did go to a lot of trouble in NumPy to optimize this (e.g., all the dispatching logic written in C) and it seems needless to duplicate that. Particularly for SciPy, which is so closely tied to NumPy anyways. So I would lean towards encouraging using With regards to libraries implementing arrays, Also, clearly NumPy is not the ultimate array API -- it works, but if we were starting from scratch we might make different decisions. I would rather not use de-facto standards to enforce NumPy's API choices in |
Yes, this is something I was thinking about in general, but we hadn't really thought about what it would look like in practice. It was tricky enough to figure things out for internal use in NumPy, so we didn't expose That said, we're not going to change its internal location for 1.17, so if we do make it public in 1.18 (e.g., as |
Given that any library interested in using it is going to want to support at least a few NumPy versions, they'd need to vendor it anyway until NumPy 1.20 or so. So saying
Yes, I think I agree. That would then imply removing the domain check from
True. I think for almost any function (and also ufuncs), the numpy versions will have more keywords than other libraries. As long as the positional arguments match, and keywords that are common mean the same thing, I think this is fine.
This is always the case right, independent of this discussion? The API used and the executing library need to match for all keywords used. If today we do |
I'm not sure I follow -- what domain check are you referring to?
I was contemplating new optional non-NumPy arguments, or especially cases where optional arguments have different semantics in NumPy vs another library. The later is probably not very common, but is not inconceivable. @rgommers by the way, I saw your recent PyData Amsterdam talk on Youtube! Very nice, but one minor correction: you actually can override |
IIRC the one that ensures that
Thanks! Yes, I see you're right. It's a bit artificial though.
ah yes. that would indeed require some contemplation. at that point, using the package that has those non-numpy keywords directly is probably the less confusing way to go. |
I think this is a bug, but not 100% sure. The
ndarray.__array_function__
implementation seems special, it's not recognized when applyingarray_function_dispatch
to a function outside of NumPy (which NEP 18 suggests is possible).To try, I add the following lines to PyTorch at the end of
torch.__init__.py
:Then, I run the following (on 1.16.4 with the envvar enabled; need to rebuild to try master - EDIT: same for current master):
This gives:
So it works fine with Dask and pydata/sparse, but fails with NumPy - the traceback indicates that the dispatch to
numpy.sum
is not happening at all. Not expected I think?The text was updated successfully, but these errors were encountered: