TST: add test cases + implementations for array functions (NEP 18) new in numpy 2.0#15691
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
👋 Thank you for your draft pull request! Do you know that you can use |
| SUBCLASS_SAFE_FUNCTIONS |= {np.linalg.cross} | ||
|
|
||
| # doesn't make much sense with quantites ? | ||
| SUBCLASS_SAFE_FUNCTIONS |= {np.linalg.svdvals} |
There was a problem hiding this comment.
Maybe note that It works because it just calls svd internally, which transfers the unit (quantities are fine I think)
There was a problem hiding this comment.
Note that I actually didn't add a test yet, because the reference implementation lives in SciPy so it's a little bit more involved. But I'm working on it, and I'll add a comment at the same time, thanks for your suggestion !
|
This is more like future-proofing maintenance. We usually do not add change log for this. Thanks! |
|
@neutrinoceros - thanks so much for doing this. I'm in a meeting the rest of the week, but probably can find some time for review. Is that useful already, or are you still making changes? |
|
@mhvk I'd like to have allowed_failures go green before I mark this as "open for review", and I'll try to accomplish that tomorrow, but feel free to review at any point ! What I have already is unlikely to change again before your feedback :) |
mhvk
left a comment
There was a problem hiding this comment.
OK, had a look now. Quite a few comments, but mostly small.
|
|
||
| @function_helper(module=np.linalg) | ||
| def outer(x1, x2, /, *args, **kwargs): | ||
| return (x1, x2) + args, kwargs, x1.unit * x2.unit, None |
There was a problem hiding this comment.
This won't work, since only one of x1, x2 has to be a Quantity, the other can be a regular array. I'd just copy the relevant parts of np.outer (annoyingly, they have different signature, so we cannot just add to helps).
Note that you should not add the *args, **kwargs here since the numpy equivalent does not take any further arguments.
Aside: a pity the implementation does asarray rather than asanyarray since with the latter this would just have worked... See numpy/numpy#25101 (comment)
There was a problem hiding this comment.
Note that you should not add the *args, **kwargs here since the numpy equivalent does not take any further arguments.
The idea is to delegate any unknown arguments to the numpy function that gets called later, since it might gain new arguments in the future. See my other comment. I can still remove those if you're not convinced this has value.
|
@mhvk A good fraction of your comments are about the need (or lack thereof) for |
|
Haven't gone into the details, but I could verify the fixes are working locally. As of today (8 December) there are 3 more ufuncs added though, |
|
Thanks for catching those, surely they'll make the way into nightlies soon. I've added the relevant PRs to the issue's description. |
|
Ok I think I covered everything @dhomeier listed. Opening for review again ! |
Obviously updated more frequently than scientific-python-nightly-wheels, but no |
|
Looks like it should update over the weekend. We can wait. |
|
But with my git+https://github.com/numpy/numpy.git |
|
@neutrinoceros - I think we should add More concretely, let's just follow precedent in this PR; I think I might quite easily be convinced that it is better to allow more, but best not done in a fixup PR... |
Gotcha. I'll open another issue specifically to discuss this matter. Thank you ! edit: here it is #15703 |
mhvk
left a comment
There was a problem hiding this comment.
Thanks! One request to reverse to what you had, one potential bug left...
| def outer(x1, x2, /): | ||
| # maybe this one can be marked as subclass-safe in the near future ? | ||
| # see https://github.com/numpy/numpy/pull/25101#discussion_r1419879122 | ||
| return (x1, x2), {}, x1.unit * x2.unit, None |
There was a problem hiding this comment.
Thanks for adding the comment. Note that this still will break if either x1 or x2 is not a Quantity (which is allowed). You'll sadly need to follow the logic in outer.
There was a problem hiding this comment.
Thank you, indeed I forgot to follow up on your first comment. Commit incoming !
010d160 to
4e57e38
Compare
|
rebased, but devdeps CI is still red. I'm not sure whether numpy nightlies are now caught up, so I'm thinking this should wait a little bit longer. |
|
No, it's at git20231208.a5b67bb now, which should have numpy/numpy#25086 merged. def test_basic_testing_completeness():
> assert all_wrapped == (tested_functions | IGNORED_FUNCTIONS | UNSUPPORTED_FUNCTIONS)
E AssertionError: assert {<function ma...338a130>, ...} == {<function ma...338a130>, ...}
E Extra items in the left set:
E <function astype at 0x1033945f0> |
|
Thanks for having a look @dhomeier, I just fixed this one locally so hopefully this is about ready now🤞🏻 |
mhvk
left a comment
There was a problem hiding this comment.
Looks all good now! Approving but not yet merging, since the PR was still marked as draft.
f37349d to
bb3bef3
Compare
|
Yes I just didn't wan't to re-open before I saw CI gone green ! I squashed and rebased, now feel free to merge away ! |
pllim
left a comment
There was a problem hiding this comment.
Just a small typo. Otherwise LGTM and I am so happy devdeps is green again. Thanks!
…type, unique_all, unique_counts, unique_inverse, unique_values, linalg.cross, linalg.outer, linalg.svdvals, linalg.tensordot, linalg.matmul)
6b6a254 to
e201579
Compare
|
Thank you! |
…array functions (NEP 18) new in numpy 2.0
…691-on-v6.0.x Backport PR #15691 on branch v6.0.x (TST: add test cases + implementations for array functions (NEP 18) new in numpy 2.0)
Description
Will fix #15690
This isn't finished yet but I'm opening as a draft 10min ahead of the dev call. I'll come back to this later today or tommorow.
Nothing it polished yet but early feedback is welcome nonetheless.