Closed erykoff closed 5 months ago
I had already started this too, and figured I'd keep going before looking at how you did everything. cf. https://github.com/GalSim-developers/GalSim/compare/releases/2.5...numpy2
Here are the salient differences as I see them:
@rmjarvis Thanks for your comments and commits to cherry-pick. Re (2): in numpy 1.x, np.array()
will by default do a copy unless copy=False
; in 2.x np.array()
will only do a copy if necessary by default. (Note that this is different behavior than astype()
which would only do a copy if necessary by default in 1.x and 2.x). So if we want to minimize copies in 1.x (which we do!) we need the full shim wherever main uses copy=False
. Re (3) I'm not sure what I should change in the tests (though I do see your point that this may be a numpy bug).
So if we want to minimize copies in 1.x (which we do!) we need the full shim wherever main uses copy=False.
I don't think that's true. At least for most uses in GalSim. (I.e. aside from the two in table.py.) np.asarray(a, dtype)
does the same thing in both 1.x and 2.0 as np.array(a, dtype, copy=False)
does in 1.x and what np.array(a, dtype, copy=None)
does in 2.0.
Re (3) I'm not sure what I should change in the tests (though I do see your point that this may be a numpy bug).
My solution was to change -1
to np.int64(-1)
in __neg__
, and in the places where we add a negative value, cast it to np.int64
. cf. 1a9756077
Ah, okay. Replacing np.array()
with np.asarray()
would do the trick without the shim in many cases. I missed the subtle replacement of array()
with asarray()
in your comment and why are there both of these anyway? (Rhetorical question)
Apparently that OverFlowError is an intended anti-feature. cf. https://github.com/numpy/numpy/issues/26483#issuecomment-2123230081 But changing to use numpy int types in such cases seems like the right thing to do to work around it.
Closing in lieu of #1297. Thanks Eli for the first pass and discussion about the various options to make the code compatible with numpy 2.0.
This should work with numpy 2 now (tested locally with numpy 2.0.0rc2 and python=3.12). I based this off the 2.5 release branch, I don't know if that's the right thing to do.
One test -- checking the wfirst deprecation -- isn't working and I don't understand that or why it should be related to numpy2. Maybe a py312 thing?