-
Notifications
You must be signed in to change notification settings - Fork 875
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
Explicitly use int64
in Numpy/cython code to avoid OS inconsistency
#3992
Explicitly use int64
in Numpy/cython code to avoid OS inconsistency
#3992
Conversation
@njzjz Perhaps you could give me some advice or comment here because I'm not a cython expert? Thanks a ton in advance. Looks like quite some code is broken when running on Windows system with NumPy < 2, because with 862c454 integer is explicitly declared as It looks like we should update all cython-related code to internally cast type as |
Also, it may be useful to run tests against both numpy 1.x and 2.x. |
Agreed! NumPy is recommending the same:
|
@njzjz I decide perhaps still explicitly use @janosh I'm not a cython expert (important 😅 ) so please review all changes very carefully :) Added a
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you sure we need to change np.array(dtype=int->np.int64)
across the whole code base? reading the numpy docs you linked, it sounds like the potential for platform inconsistency is specific to cython code? so might be enough to only int->np.int64
in .pyx
files?
Sorry perhaps I should tweak the title, current one might be misleading. After NumPy 2.x, the default NumPy int type for 64-bit windows system changed from
Meaning if we pass a numpy array as Meanwhile I think this is better than a fused type of |
int64
in cython code to avoid OS inconsistencyint64
in Numpy/cython code to avoid OS inconsistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a lot for looking into this @DanielYang59! hugely appreciated! 👍
No problem. Also appreciate the input from @njzjz Perhaps we should add a note in next release informing downstream packages of such potentially breaking change ( |
sure thing! would you like to draft a note? |
Sure, and feel free to polish it as you like. [Breaking] Default NumPy/Cython integer type changed to
|
Summary
int64
in cython code to avoid OS inconsistency (default int type changed in Windows) as follow up PR of build against NPY2 #3894, to fix Incompatability with numpy <2 on Windows forLattice.find_points_in_spheres
#3990NumPy < 2
Cython code need attention
src/pymatgen/optimization/linear_assignment.pyx
src/pymatgen/optimization/neighbors.pyx
src/pymatgen/util/coord_cython.pyx
Pin some threads from
NumPy
for reference: