Skip to content

NumPy 2.x compatibility fixes for image interpolation and I/O#78

Merged
jnolan14 merged 3 commits into
freesurfer:masterfrom
inhuszar:fix/numpy2x
May 22, 2026
Merged

NumPy 2.x compatibility fixes for image interpolation and I/O#78
jnolan14 merged 3 commits into
freesurfer:masterfrom
inhuszar:fix/numpy2x

Conversation

@inhuszar
Copy link
Copy Markdown
Contributor

@inhuszar inhuszar commented May 22, 2026

Summary

This PR updates Surfa for NumPy 2.x compatibility while preserving NumPy 1.x behavior.

Changes include:

  • Replaces removed/fragile NumPy byte-order handling in image interpolation with a byteswap().view(dtype.newbyteorder('=')) path.
  • Fixes image reorientation axis bookkeeping to avoid NumPy 2.x tuple/scalar assignment behavior changes.
  • Adds compatibility handling for NumPy boolean and integer scalar dtypes in framed I/O and FreeSurfer NIfTI extension metadata.
  • Updates build configuration:
    • makes abi3 wheel building opt-in via SURFA_ABI3=1
    • fixes package_data so both .pyx and .h files are included.
  • Adds a regression test ensuring non-native-endian image data resizes identically to native-endian data for both linear and nearest interpolation.

Testing

Added test/test_numpy_compat.py covering native vs non-native endian resize behavior.

inhuszar added 3 commits May 22, 2026 01:07
Resolve interp.pyx byteorder conflict with native dtype view

Prefer dtype.newbyteorder('=') after byteswap() because the intended
post-conversion invariant is native-endian data. The no-argument form would
also work in this guarded block, but the explicit native byte order better
documents the intent and is less dependent on the surrounding condition.
@jnolan14 jnolan14 merged commit 393aab4 into freesurfer:master May 22, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants