Repository navigation
Require NumPy >= 2 and remove the NumPy 1 code paths - #289
Open
antonwolfy wants to merge 1 commit into
Open
antonwolfy wants to merge 1 commit into
antonwolfy wants to merge 1 commit into
Conversation
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.
antonwolfy
requested review from
jharlow-intel,
ndgrigorian,
vlad-perevezentsev and
xaleryb
as code owners
October 16, 2026 17:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mkl_umathpicks its NumPy 1 or NumPy 2 loops at compile time (USE_NUMPY_2), but declaresnumpy >=1.26.4at 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
sign(F->F,D->D) intest_mkl_umathandtest_fall_back_umath. Afterpatch_numpy_umath(),np.sign(3+4j)returns0.6+0.8jinstead of NumPy 1's1+0j. With NumPy 2.0.2 all tests pass.ldexponly hasintandlong(32-bit there) loops, sopatch_numpy_umath()finds no NumPy loops matching theint64ldexploops and raisesRuntimeError(from reading_patch_numpy.pyx, not run on Windows).pin_compatible('numpy-base')withnumpy >=1.26.4inconda-recipe/meta.yaml.Changes
Require NumPy 2
pyproject.toml:dependencies = ["numpy >=2"]andnumpy>=2in[build-system] requires.conda-recipe/meta.yaml: runnumpy >=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 localconda build conda-recipewithout--numpybuilds against NumPy 2. CI always passes--numpy.Remove the NumPy 1 code paths
mkl_umath_loops.{c,h}.src: drop theUSE_NUMPY_2switch, the NumPy 1 complexsignloop and theldexp_longloops, 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 unusednumpyimports.ufunc_docstrings_numpy1.pyand its.flake8entry, and update the AGENTS.md references.[dev].Testing
icxagainst NumPy 2.5.4 without warnings. The wheel hasRequires-Dist: numpy>=2and exports only theldexp_int64loops.pytest --pyargs mkl_umathon py3.13 with NumPy 2.1.3 (the oldest NumPy for py3.13) and 2.5.4: 392 passed, 1 skipped.#errorwith NumPy 1.26.4 headers.Notes
conda-recipe-cfgets the samenumpy >=2run requirement andnumpy: '2'default in Align conda-recipe-cf and its CI with the conda-forge feedstock #287. The comment Align conda-recipe-cf and its CI with the conda-forge feedstock #287 adds there mentionsUSE_NUMPY_2, so whichever PR lands second should reword it. Until Align conda-recipe-cf and its CI with the conda-forge feedstock #287 is merged, a localconda build conda-recipe-cfwithout--numpystops at the new#error; CI is not affected.ufunc_docstrings_numpy1.py:generate_umath_doc.pyis not wired intomeson.build, so the ufunc docstrings end with the literal macro name (mkl_umath._ufuncs.add.__doc__ends withDOC_NUMPY__CORE_UMATH_ADD) andufunc_docstrings_numpy2.pyis not used either. Left for a separate PR.