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

Numpy2 compatibility (brian2.units) #1506

Merged
merged 5 commits into from Mar 11, 2024
Merged

Numpy2 compatibility (brian2.units) #1506

merged 5 commits into from Mar 11, 2024

Conversation

mstimberg
Copy link
Member

Various fixes for to make the unit system compatible with the upcoming numpy 2.0 release. It might make sense to revisit this more fundamentally at a later point, but for now the main change is that __array_wrap__ and __array_prepare__ are merged into __array_ufunc__. Without doing anything further, this actually enables some new functionality like:
Before:

>>> np.add.reduce(np.arange(3)*mV)
Quantity(0.003)

After:

>>> np.add.reduce(np.arange(3)*mV)
3*mV

But I don't think many users do complex calculations with Quantity arrays in the first place. Still, we need to point this out clearly in the release notes, it might break some code. As discussed, the changes in numpy's system also lead to things like x**(2*volt) no longer raising an error, since float(2*volt) == 2.0 and this makes things go through the square instead of the pow ufunc.

@mstimberg mstimberg merged commit 4bd1e55 into master Mar 11, 2024
90 of 98 checks passed
@mstimberg mstimberg deleted the numpy2_deprecations branch March 11, 2024 12:06
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.

None yet

1 participant