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

Address new copy semantics & broadcasting in np.solve in NumPy 2 #7341

Merged
merged 3 commits into from
Mar 14, 2024

Conversation

lagru
Copy link
Member

@lagru lagru commented Mar 13, 2024

Description

With NumPy 2.0.0, copy=False now raises a ValueError if the copy cannot be made in numpy.asarray and numpy.array, see the release notes for details. I'm using an approach by astropy to address this.

Additionally, broadcasting in np.linalg.solve is now handled differently in a backwards-incompatible way, see release notes on the recommended fix.

Checklist

Release note

We use changelist to
compile each pull request into an item of the release notes. Please refer to
the instructions
and past release notes
for guidance and examples.

...

With NumPy 2.0.0, `copy=False` now raises a ValueError if the copy
cannot be made. The previous behavior to only copy if needed is provided
with `copy=None`. During the transition period, use this symbol instead.
Remove once NumPy 2.0.0 is the minimal required version [1, 2]

This approach was inspired by astropy [3].

[1] https://numpy.org/devdocs/release/2.0.0-notes.html#new-copy-keyword-meaning-for-array-and-asarray-constructors
[2] https://www.github.com/numpy/numpy/pull/25168
[3] https://github.com/astropy/astropy/blob/2390bf8f8f2a1c5b6beffbd87db9af5aa6538df1/astropy/utils/compat/numpycompat.py#L29
@lagru lagru added the 🔧 type: Maintenance Refactoring and maintenance of internals label Mar 13, 2024
"The broadcasting rules for `np.solve(a, b)`` were ambiguous when b had 1
fewer dimensions than `a`. This has been resolved in a backward-
incompatible way and is now compliant with the Array API. The old
behaviour can be reconstructed by using
`np.solve(a, b[..., None])[..., 0]`."

https://numpy.org/devdocs/release/2.0.0-notes.html#removed-ambiguity-when-broadcasting-in-np-solve
https://www.github.com/numpy/numpy/pull/25914
@lagru lagru changed the title Use NP_COPY_IF_NEEDED for compatibility with new NumPy 2 copy semantics Address new copy semantics & broadcasting in np.solve in NumPy 2 Mar 13, 2024
Copy link
Member

@soupault soupault left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@soupault soupault merged commit bbffc2b into main Mar 14, 2024
66 checks passed
@soupault soupault deleted the maintenance/fix-np2.1.0 branch March 14, 2024 10:25
@stefanv stefanv added this to the 0.23 milestone Mar 14, 2024
@lagru lagru mentioned this pull request Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔧 type: Maintenance Refactoring and maintenance of internals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants