Skip to content

Require NumPy >= 2 and remove the NumPy 1 code paths - #289

Open
antonwolfy wants to merge 1 commit into
mainfrom
require-numpy-2
Open

antonwolfy wants to merge 1 commit into
mainfrom
require-numpy-2

Conversation

@antonwolfy

Copy link
Copy Markdown
Collaborator

mkl_umath picks its NumPy 1 or NumPy 2 loops at compile time (USE_NUMPY_2), but declares numpy >=1.26.4 at runtime. Every CI job and every published package since 0.3.0 is built against NumPy 2, so it can be installed with NumPy 1.x and then misbehaves. This PR requires NumPy 2 everywhere and removes the NumPy 1 code that nothing builds or tests anymore.

Problem

  • With the published 0.5.0 wheel (cp312, Linux) and NumPy 1.26.4, 4 tests fail: complex sign (F->F, D->D) in test_mkl_umath and test_fall_back_umath. After patch_numpy_umath(), np.sign(3+4j) returns 0.6+0.8j instead of NumPy 1's 1+0j. With NumPy 2.0.2 all tests pass.
  • On Windows, NumPy 1.x's ldexp only has int and long (32-bit there) loops, so patch_numpy_umath() finds no NumPy loops matching the int64 ldexp loops and raises RuntimeError (from reading _patch_numpy.pyx, not run on Windows).
  • All wheels from 0.4.0 to 0.5.0 (identical on PyPI and the Intel index) are built against NumPy 2 and allow NumPy 1.26.x; the NumPy 2 builds of 0.2.0–0.3.1 required NumPy 2. The lower bound dropped in task: numpy-base toggle for meta.yaml #181, which replaced pin_compatible('numpy-base') with numpy >=1.26.4 in conda-recipe/meta.yaml.

Changes

Require NumPy 2

  • pyproject.toml: dependencies = ["numpy >=2"] and numpy>=2 in [build-system] requires.
  • conda-recipe/meta.yaml: run numpy >=2 (was >=1.26.4). The published wheels take their requirements from this recipe's run dependencies.
  • conda-recipe/conda_build_config.yaml: numpy: '2' (was '1.26.4'), so a local conda build conda-recipe without --numpy builds against NumPy 2. CI always passes --numpy.

Remove the NumPy 1 code paths

  • mkl_umath_loops.{c,h}.src: drop the USE_NUMPY_2 switch, the NumPy 1 complex sign loop and the ldexp_long loops, and keep the NumPy 2 code unconditionally. The header now stops the build with #error "mkl_umath must be built against NumPy >= 2.0" when compiled against NumPy 1 headers.
  • generate_umath.py, generate_umath_doc.py: drop the NumPy version branches and the now unused numpy imports.
  • Delete ufunc_docstrings_numpy1.py and its .flake8 entry, and update the AGENTS.md references.
  • CHANGELOG entries under [dev].

Testing

  • Built with icx against NumPy 2.5.4 without warnings. The wheel has Requires-Dist: numpy>=2 and exports only the ldexp_int64 loops.
  • pytest --pyargs mkl_umath on py3.13 with NumPy 2.1.3 (the oldest NumPy for py3.13) and 2.5.4: 392 passed, 1 skipped.
  • The header compiles with NumPy 2.5.4 headers and stops at the #error with NumPy 1.26.4 headers.

Notes

mkl_umath chose its NumPy 1 or NumPy 2 loops at compile time
(USE_NUMPY_2), but declared numpy >=1.26.4 at runtime. Packages built
against NumPy 2 could therefore be installed with NumPy 1.x, where complex
sign returned NumPy 2 results and, on Windows, patch_numpy_umath() found
no NumPy loops matching the int64 ldexp loops. Every CI job and published
package since 0.3.0 builds against NumPy 2, so NumPy 1 support is not
exercised anywhere.

Require numpy >=2 in pyproject.toml (runtime and build-system) and in the
conda recipe, and default the recipe's conda_build_config.yaml to NumPy 2
so a local conda build without --numpy builds against NumPy 2.

Remove the NumPy 1 code: the USE_NUMPY_2 switch, the NumPy 1 complex sign
and ldexp_long loops, the NumPy version branches in generate_umath.py and
generate_umath_doc.py, and ufunc_docstrings_numpy1.py. Building against
NumPy 1 headers now stops with an explicit #error.
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.

1 participant