-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
ENH: integrate.trapezoid: add array API standard support #21524
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
Conversation
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.
thanks for working on this @Armavica !
There is a masked array test, which does not work with Array API. I understand that supporting masked arrays is out of scope of Array API. How should we then proceed with this test?
You can decorate the test with skip_xp_invalid_arg
from scipy.conftest
- see https://scipy.github.io/devdocs/dev/api-dev/array_api.html#adding-tests.
I remember that Lucas told me that np.diff would probably need to be reimplemented, so I don't really understand why my initial strategy of blindly replacing np with xp seems to pass some tests.
Let’s see if we get any failures when you push the converted tests :)
05cd0ef
to
21fbda7
Compare
Thank you for your comments and for the pointers to documentation! I addressed your comments, it looks like tests are passing :) |
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.
We also need to convert the tests here as described on https://scipy.github.io/devdocs/dev/api-dev/array_api.html#adding-tests. At the moment, all of the tests still only input NumPy arrays, which is why xp.diff
and xp.asanyarray
aren't failing.
Ah, that's why! I had the feeling something was still wrong despite tests passing. Thank you, I get it now. |
21fbda7
to
25dc07c
Compare
I fixed the array API commit, and added a commit to fix a bug which was already present in the original version, in cases where |
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.
thanks, getting close!
4caccb6
to
ea61a03
Compare
Could you add this test file to the |
ea61a03
to
5fd3556
Compare
I added the line to the file as requested. It looks like this change automatically triggered review requests on my behalf? |
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.
thanks @Armavica ! I pushed a small update (explained inline) and I'm happy with this now. Will leave open for a while in case anyone has comments about the bug-fix!
Thank you for your help on this @lucascolley! |
Note that another approach for what I fixed would be to do like in scipy/scipy/integrate/_quadrature.py Lines 459 to 461 in 8e4d71a
|
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.
Actually, one more thing! Could you add an array-like test, along the lines of the tests added in gh-21209? It doesn't have to be complicated, just a sanity check that we are still accepting Python lists.
I added the test but I am probably missing something because I don't think the test runs. At least on my machine, it never does (even with |
I think it is just over-indented! It's currently sitting inside |
f9959f5
to
957a92d
Compare
Gosh that's embarrassing… 😅 It's fixed and the test seems to run now. |
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.
LGTM, thanks again!
What was the behaviour before your fix, by the way? Just nonsense returned? |
@Armavica thanks for working on this. @lucascolley I saw that you requested my review. I took a close look and didn't find much wrong with the Array API translation, but mostly because I was distracted by the function's nonstandard broadcasting rules. They don't follow either those of NumPy linalg or The one thing I did notice is that this preserved |
No, an indexing error. |
957a92d
to
0629129
Compare
@mdhaber I added this. It turned out to break the previous version of |
Thanks; I wasn't explicit enough. Please pass the arrays into |
0629129
to
9be2b02
Compare
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.
CI failures look unrelated - thanks again @Armavica !
d = dx | ||
else: | ||
x = np.asanyarray(x) | ||
if x.ndim == 1: |
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.
looks like this x.ndim == 1
guard is what has gone missing for gh-21908.
Reference issue
Towards gh-20930.
What does this implement/fix?
Implement the Array API for
integrate.trapezoid
.Additional information
Hello! I met @lucascolley at the NumFocus summit this week, and he advised me to start with
integrate.trapezoid
to help with the Array API implementation effort. I am submitting this as a draft PR because I don't understand yet everything that is going on here, and I am looking for feedback and advice.I have several questions so far:
np.diff
would probably need to be reimplemented, so I don't really understand why my initial strategy of blindly replacingnp
withxp
seems to pass some tests.