Skip to content

Rebase custom patches onto upstream v0.8.0 (NumPy 2 support) - #1

Open
yannrichet wants to merge 81 commits into
stablefrom
feature/numpy2-support
Open

Rebase custom patches onto upstream v0.8.0 (NumPy 2 support)#1
yannrichet wants to merge 81 commits into
stablefrom
feature/numpy2-support

Conversation

@yannrichet

Copy link
Copy Markdown
Member

Summary

  • Rebases the 3 custom patches from our stable branch (based on upstream v0.6.6) onto upstream v0.8.0.
  • Pulls in upstream's fix for NumPy 2.0 compatibility (4c966bf, "CHG: Make vendored Numpy api compatable with Numpy v2"):
    • Corrects the hardcoded _ARRAY_API table offset for PyArray_CopyInto (82 → 50), which changed between NumPy 1.x and 2.x.
    • Switches the multiarray import to pybind11::detail::import_numpy_core_submodule, needed because NumPy 2.0 moved numpy.core to numpy._core. Requires pybind11 >= 2.12.0.
  • Custom patches carried forward, cherry-picked cleanly except one trivial conflict already resolved upstream in the same spirit:
    • Do not unset global CMake variables (conflict: upstream had already gated the CMAKE_INSTALL_PREFIX unset behind CARMA_DEV_MODE; kept that and additionally commented out the CMAKE_EXPORT_COMPILE_COMMANDS reset per our original intent)
    • Customize: add a smooth policy using macro to drive carma mem functions
    • Explicity namespace for ssize_t in pybind11

Context

This is part of upgrading libKriging's Python bindings (pylibkriging) to drop the numpy<2 pin, which currently exists because our vendored carma (v0.6.6) hardcodes NumPy C-API table offsets that changed in NumPy 2.0.

Test plan

  • Build libKriging Python bindings against this carma branch with NumPy 2.x installed
  • Run pylibkriging test suite with NumPy 1.x and NumPy 2.x

RUrlus and others added 30 commits September 22, 2021 16:15
there is no 10.11.x branch; probably meant to be 11.0.x
conradsnicta and others added 27 commits April 11, 2023 16:24
Main C++ code should be able to drive memory management of armadillo even for independent compilation units (i.e. not header only)
Verified against numpy 1.26.4 and 2.5.1 headers: PyArray_CopyInto's slot
in the _ARRAY_API table moved from 82 to 50, while every other function
carma uses kept its offset. The upstream numpy2 fix (4c966bf) hardcoded
the new index unconditionally, which silently calls the wrong C function
when loaded under NumPy 1.x. Pick the index at runtime from numpy.__version__.
@yannrichet

Copy link
Copy Markdown
Member Author

Found and fixed a real bug in the upstream numpy2 fix (4c966bf) while testing this against both NumPy versions: `PyArray_CopyInto`'s slot in the `_ARRAY_API` table moved from 82 (NumPy 1.x) to 50 (NumPy 2.x), confirmed empirically against the two headers. The upstream fix hardcoded 50 unconditionally, meaning this would silently call the wrong C function under NumPy 1.x (undefined behavior, not a clean crash).

Added a runtime check on `numpy.version` to pick the right index. Verified locally: built once, tested the same `.so` against NumPy 1.26.4 and NumPy 2.5.1 — both take the `PyArray_CopyInto` code path correctly (non-Fortran-contiguous predict input) and return correct results.

Full pylibkriging test suite (83 tests, excluding 2 unrelated pre-existing sklearn-wrapper failures) passes against NumPy 2.5.1 with this branch + pybind11 2.13.6.

ubuntu-latest and windows-latest moved to newer default images
(ubuntu-24.04, windows-2025) that no longer ship clang-14/gcc-11 or
the hardcoded VS2022 Enterprise path this workflow expects. Pin to
ubuntu-22.04 and windows-2022, which still provide them, to restore
what these jobs were originally testing.
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.

5 participants