Skip to content
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

MAINT: A few updates to the array_api #20066

Merged
merged 23 commits into from Nov 12, 2021
Merged

Conversation

asmeurer
Copy link
Member

@asmeurer asmeurer commented Oct 7, 2021

A few minor updates to the array_api namespace based on recent updates to the spec.

CC @seberg you may actually want to review this one before it is merged this time.

The spec has recently been updated to only require multiaxis (i.e., tuple)
indices in the case where every axis is indexed, meaning there are either as
many indices as axes or the index has an ellipsis.
@seberg
Copy link
Member

seberg commented Oct 7, 2021

The main comment I remember was that you had a lot of complexity to support arr[boolean_arr,] when maybe all you need to support is arr[boolean_arr]. But I guess there was no change/decision w.r.t. to that one made. And isn't the most important point the non-multi-dim index part? arr3d[0] not being strictly defined or did you decide against that after all?

Copy link
Member

@mattip mattip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linting

numpy/array_api/tests/test_array_object.py Show resolved Hide resolved
numpy/array_api/_array_object.py Outdated Show resolved Hide resolved
where does value-based promotion for 0-dimensional arrays, so we use the same
trick as in the Array operators to avoid this.
@asmeurer
Copy link
Member Author

I pushed a fix to the type promotion on where. As far as I can tell, the fix suggested at #18585 (comment) wouldn't work since where isn't a ufunc.

Printing behavior isn't required by the spec. This is just to make things
easier to understand, especially with the array API test suite.
asmeurer added a commit to data-apis/array-api-tests that referenced this pull request Oct 27, 2021
This test will not pass NumPy without the changes in
numpy/numpy#20066 due to an update in indexing
behavior in the spec.
from_dlpack() should be used to create arrays using DLPack.
unique() in the array API was replaced with three separate functions,
unique_all(), unique_inverse(), and unique_values(), in order to avoid
polymorphic return types.

Additionally, it should be noted that these functions to not currently conform
to the spec with respect to NaN behavior. The spec requires multiple NaNs to
be returned, but np.unique() returns a single NaN. Since this is currently an
open issue in NumPy to possibly revert, I have not yet worked around this. See
numpy#20326.
This does nothing in NumPy, and is just present so that the signature is valid
according to the spec.
The "multiaxis indexing must index every axis explicitly or use an ellipsis"
was supposed to include any type of index, not just tuple indices.
@asmeurer
Copy link
Member Author

asmeurer commented Nov 9, 2021

This is ready for review. There have been several small changes to the spec since the last time anyone has looked at this. With this PR, everything should now be up-to-date, except for a handful of things which are being updated in separate pull requests.

@rgommers
Copy link
Member

@asmeurer there is one test failure, test_device_property. Could you fix that?

@rgommers
Copy link
Member

The boolean indexing question higher up (#20066 (comment)) also deserves a reply.

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all LGTM modulo the test failure.

numpy/array_api/_set_functions.py Outdated Show resolved Hide resolved
@asmeurer
Copy link
Member Author

@asmeurer there is one test failure, test_device_property. Could you fix that?

Sorry about that. #20335 has messed up my ability to run the tests locally.

@asmeurer
Copy link
Member Author

The main comment I remember was that you had a lot of complexity to support arr[boolean_arr,] when maybe all you need to support is arr[boolean_arr]. But I guess there was no change/decision w.r.t. to that one made. And isn't the most important point the non-multi-dim index part? arr3d[0] not being strictly defined or did you decide against that after all?

I did address the point of treating a[0] and a[0,] differently. That was just a misreading of the spec on my part. I think we could drop a[boolean_arr,] if that simplifies the code. What was the suggested way to do that? Any refactoring of the index validation should be fine so long as it passes the tests in test_array_object.py as well as the test_indexing test in the array API testsuite.

asmeurer and others added 6 commits November 10, 2021 17:29
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
The array_api cannot use the NumPy testing functions because array_api arrays
do not mix with NumPy arrays, and also NumPy testing functions may use APIs
that aren't supported in the array API.
@rgommers rgommers added this to the 1.22.0 release milestone Nov 12, 2021
@rgommers
Copy link
Member

This all looks good. CI failures are okay: linter ones are uninteresting, the typing error was fixed in main yesterday, and the segfault is unrelated (happening in other PRs). So in this goes.

I did address the point of treating a[0] and a[0,] differently. That was just a misreading of the spec on my part. I think we could drop a[boolean_arr,] if that simplifies the code. What was the suggested way to do that?

Seems fine either way to me, and can be done in a separate follow-up given that it's a discussion that predates this PR. Let's see if @seberg has a preference here.

@rgommers
Copy link
Member

Ah wait, there's even more failures. They all look unrelated, but rerunning CI anyway to get this a bit more green.

@rgommers
Copy link
Member

Looking much better now, in it goes. Thanks @asmeurer & reviewers!

@rgommers rgommers merged commit ff2e2a1 into numpy:main Nov 12, 2021
@seberg
Copy link
Member

seberg commented Nov 12, 2021

A followup is fine and would be nice. I don't recall the logic exactly, what I do remember is that the indexing check was very complex (with some recursive calls), and a lot of that complexity was there to accomodate arr[boolean_arr,]. I believe in the original PR I had proposed a simplification.
That said, I think it is correct, just seemed more complex than necessary.

@seberg
Copy link
Member

seberg commented Nov 12, 2021

PS: And since this is experimental and a corner case, I don't think it would matter if you change arr[boolean_arr,] from being allowed to being rejected.

leofang pushed a commit to leofang/cupy that referenced this pull request Nov 12, 2021
cr313 added a commit to cr313/test-array-api that referenced this pull request Apr 19, 2024
This test will not pass NumPy without the changes in
numpy/numpy#20066 due to an update in indexing
behavior in the spec.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants