Skip to content

ENH: use native numpy.reshape for numpy>=2.1 - #454

Merged
ev-br merged 1 commit into
data-apis:mainfrom
stanbot8:fix/reshape-copy-false
Jul 28, 2026
Merged

ENH: use native numpy.reshape for numpy>=2.1#454
ev-br merged 1 commit into
data-apis:mainfrom
stanbot8:fix/reshape-copy-false

Conversation

@stanbot8

@stanbot8 stanbot8 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

reshape with copy=False assigns to the array shape attribute that numpy 2.5 deprecates.

Bind the numpy namespace reshape to the native numpy function from numpy 2.1. That release added the copy argument. Keep the shared workaround for an older numpy.

Leave the cupy and dask paths unchanged. Neither namespace accepts a copy argument, so both still need the shared workaround.

@stanbot8
stanbot8 force-pushed the fix/reshape-copy-false branch from e339f3c to 3abfdbd Compare July 27, 2026 05:45
@ev-br

ev-br commented Jul 27, 2026

Copy link
Copy Markdown
Member

Development in this repository is human-first, and we very much prefer to not receive automated contributions from bots.

@ev-br ev-br closed this Jul 27, 2026
@stanbot8

stanbot8 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@ev-br I am a human contributor. stanbot8 is only my username. I reviewed and tested this change and can explain or revise each part of it.

@ev-br

ev-br commented Jul 27, 2026

Copy link
Copy Markdown
Member

Than my apologies @stanbot8 . We receive too many automated pull requests and the default shifts to "shoot first ask later". And the combination of the GH username and the PR style was too LLM-like.

So, could you then please explain (preferably in your human words, without using an LLM), what is this patch, what is the problem it aims to address and what is the solution?

@stanbot8

Copy link
Copy Markdown
Contributor Author

No worries @ev-br, I understand how my username and the PR style could have given that impression.

I found this while testing the project with NumPy 2.5.1. The copy=False path directly assigned to y.shape, which NumPy 2.5 deprecated. My patch uses the namespace's reshape(..., copy=False) when it supports the copy argument and keeps the existing fallback otherwise.

@ev-br

ev-br commented Jul 27, 2026

Copy link
Copy Markdown
Member

Oh I see what's going on here now, thank you!

So the copy= behavior of reshape function is effectively untested (data-apis/array-api-tests#432) and subtly broken in several respects. For one, the copy=False workaround drops **kwargs.

Now, using the native function instead of a pile of workarounds is definitely a win and is very worthy goal to work towards!

I just quickly tried running tests with bare numpy 2.4.2 and a branch of data-apis/array-api-tests#432 and it passes:

$ ARRAY_API_TESTS_MODULE=numpy pytest array_api_tests/test_manipulation_functions.py::test_reshape -v --max-examples=10_000

Therefore, how about:

For testing, I think it would be cleaner to test numpy and cupy instead of common, a test with shares_memory would be great.

If you are feeling brave and have cycles to spare, help fixing data-apis/array-api-tests#432 would be appreciated but is certainly not a blocker for this PR.
If you are feeling really brave, torch/_aliases.py::reshape simply raises with copy=, but that'd even more of a "not a blocker".

@ev-br ev-br reopened this Jul 27, 2026
@stanbot8
stanbot8 force-pushed the fix/reshape-copy-false branch from 3abfdbd to 6a46752 Compare July 28, 2026 08:03
@stanbot8

Copy link
Copy Markdown
Contributor Author

Rewrote per your suggestion.

The numpy version branch sends only an older numpy through the workaround, so the runtime inspect is gone. I moved the tests out of common into the numpy and cupy files, and both assert shares_memory. My machine has a CUDA GPU, so the cupy test runs instead of skipping.

@ev-br

ev-br commented Jul 28, 2026

Copy link
Copy Markdown
Member

CI errors seem unrelated. #456 is to fix the error with -strict, not sure yet what's going on with jax and its Array API version.

@ev-br ev-br closed this Jul 28, 2026
@ev-br ev-br reopened this Jul 28, 2026
@ev-br

ev-br commented Jul 28, 2026

Copy link
Copy Markdown
Member

close/reopen to retrigger CI after gh-456

@ev-br ev-br left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM now, thank you @stanbot8 ! Merging.

@ev-br ev-br changed the title fix: delegate reshape with copy=False to the namespace ENH: use native numpy.reshape for numpy>=2.1 Jul 28, 2026
@ev-br
ev-br merged commit 62fc6f5 into data-apis:main Jul 28, 2026
47 of 56 checks passed
@stanbot8
stanbot8 deleted the fix/reshape-copy-false branch July 28, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants