From a0c384f2720b0865f8fc2e20a1c25dfcbd8a5e1d Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 14 Oct 2026 14:06:03 +0200 Subject: [PATCH 1/3] Fix ufunc docstrings showing the C macro name Since the NumPy 2.x alignment (gh-65), generate_umath.py emits each docstring as a DOC_* macro name, as NumPy does, but kept it quoted and the header defining those macros was never generated. Every ufunc __doc__ therefore ended with the literal macro name, e.g. DOC_NUMPY__CORE_UMATH_SIN, instead of the docstring text. - meson.build: generate _umath_doc_generated.h with generate_umath_doc.py and add it to the _ufuncs sources - generate_umath.py: emit the macro unquoted and include the header in the generated code, matching upstream NumPy - test_basic.py: check every ufunc docstring is expanded --- CHANGELOG.md | 1 + meson.build | 16 +++++++++++++++- mkl_umath/generate_umath.py | 6 +++--- mkl_umath/tests/test_basic.py | 8 ++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e2fdd3e..00bff0bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Pinned Cython in the Coverity Scan workflow so generated code stays stable between scans, and added `coverity/README.md` documenting the known Cython-boilerplate false positives and the scan review checklist [gh-266](https://github.com/IntelPython/mkl_umath/pull/266) ### Fixed +* Fixed the ufunc docstrings, which held only the name of the C macro meant to supply them (e.g. `DOC_NUMPY__CORE_UMATH_SIN`): the docstring header is now generated by the build and included in the generated ufunc code [gh-XXX](https://github.com/IntelPython/mkl_umath/pull/XXX) * Fixed `absolute` (float32/float64) returning `-NaN` for `+NaN` input on the scalar fallback path (same issue as numpy/numpy@dc478c58b9, gh-31433) [gh-269](https://github.com/IntelPython/mkl_umath/pull/269) * Fixed an over-decref of the borrowed module dictionary reference on the module initialization error path [gh-264](https://github.com/IntelPython/mkl_umath/pull/264) * Fixed a leak of the module object when the NumPy C-API import fails during module initialization [gh-263](https://github.com/IntelPython/mkl_umath/pull/263) diff --git a/meson.build b/meson.build index b162475d..27ba09c7 100644 --- a/meson.build +++ b/meson.build @@ -141,6 +141,17 @@ gen_umath_c = custom_target( command: [py, '@INPUT@', '-o', '@OUTPUT@'] ) +gen_umath_doc_h = custom_target( + '_umath_doc_generated', + output: '_umath_doc_generated.h', + input: 'mkl_umath/generate_umath_doc.py', + command: [py, '@INPUT@', '-o', '@OUTPUT@'], + depend_files: [ + 'mkl_umath/ufunc_docstrings_numpy1.py', + 'mkl_umath/ufunc_docstrings_numpy2.py' + ] +) + gen_loops_h = custom_target( 'mkl_umath_loops_h', output: ['mkl_umath_loops.h'], @@ -189,7 +200,10 @@ loops_dep = declare_dependency(link_with: mkl_umath_loops) py.extension_module( '_ufuncs', - sources: ['mkl_umath/src/ufuncsmodule.c', gen_umath_c, gen_loops_h], + sources: [ + 'mkl_umath/src/ufuncsmodule.c', gen_umath_c, gen_umath_doc_h, + gen_loops_h + ], include_directories: inc_np, dependencies: [mkl_dep, loops_dep], c_args: c_args + ['-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION'], diff --git a/mkl_umath/generate_umath.py b/mkl_umath/generate_umath.py index ca6a578b..09f2fb36 100644 --- a/mkl_umath/generate_umath.py +++ b/mkl_umath/generate_umath.py @@ -29,8 +29,7 @@ # 1) The `defdict` dictionary is completely different. # 2) In the `make_arrays` function, `cfunc_fname = f"{tname}_*"` is changed to # `cfunc_fname = f"mkl_umath_{tname}_*"` -# 3) In the `make_ufuncs` function, line 988: `{doc}` is changed to `"{doc}"` -# 4) In the `make_code` function, the string used there is different. +# 3) In the `make_code` function, the string used there is different. """ Generate the code to build all the internal ufuncs. At the base is the defdict: @@ -1161,7 +1160,7 @@ def make_ufuncs(funcdict): f = PyUFunc_FromFuncAndDataAndSignatureAndIdentity( {funcs}, {data}, {signatures}, {nloops}, {nin}, {nout}, {identity}, "{name}", - "{doc}", 0, {sig}, identity + {doc}, 0, {sig}, identity ); if ({has_identity}) {{ Py_DECREF(identity); @@ -1254,6 +1253,7 @@ def make_code(funcdict, filename): #include "numpy/arrayobject.h" #include "numpy/ufuncobject.h" #include "mkl_umath_loops.h" + #include "_umath_doc_generated.h" %s static int diff --git a/mkl_umath/tests/test_basic.py b/mkl_umath/tests/test_basic.py index 8433428c..9e1bdee7 100644 --- a/mkl_umath/tests/test_basic.py +++ b/mkl_umath/tests/test_basic.py @@ -202,3 +202,11 @@ def test_absolute_nan_signbit(size, dtype): f"absolute({sign}nan) must be +nan for " f"{dtype.__name__} at size {size}" ) + + +@pytest.mark.parametrize("func", umaths) +def test_docstring(func): + # the ufunc must carry the docstring text, not the name of its C macro + doc = getattr(mu, func).__doc__ + assert "DOC_" not in doc, f"'{func}' docstring is an unexpanded macro" + assert "Parameters" in doc, f"'{func}' docstring is missing its body" From 573e25aaca6394142ebc18851c74d1c9ac6cda65 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 14 Oct 2026 14:06:39 +0200 Subject: [PATCH 2/3] Add PR link to the changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00bff0bc..7f005a93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Pinned Cython in the Coverity Scan workflow so generated code stays stable between scans, and added `coverity/README.md` documenting the known Cython-boilerplate false positives and the scan review checklist [gh-266](https://github.com/IntelPython/mkl_umath/pull/266) ### Fixed -* Fixed the ufunc docstrings, which held only the name of the C macro meant to supply them (e.g. `DOC_NUMPY__CORE_UMATH_SIN`): the docstring header is now generated by the build and included in the generated ufunc code [gh-XXX](https://github.com/IntelPython/mkl_umath/pull/XXX) +* Fixed the ufunc docstrings, which held only the name of the C macro meant to supply them (e.g. `DOC_NUMPY__CORE_UMATH_SIN`): the docstring header is now generated by the build and included in the generated ufunc code [gh-282](https://github.com/IntelPython/mkl_umath/pull/282) * Fixed `absolute` (float32/float64) returning `-NaN` for `+NaN` input on the scalar fallback path (same issue as numpy/numpy@dc478c58b9, gh-31433) [gh-269](https://github.com/IntelPython/mkl_umath/pull/269) * Fixed an over-decref of the borrowed module dictionary reference on the module initialization error path [gh-264](https://github.com/IntelPython/mkl_umath/pull/264) * Fixed a leak of the module object when the NumPy C-API import fails during module initialization [gh-263](https://github.com/IntelPython/mkl_umath/pull/263) From d5ada9276618b002865cfa843aa9a27464c8e05c Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Thu, 15 Oct 2026 19:51:14 +0200 Subject: [PATCH 3/3] Move the changelog entry under a new [dev] section --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f005a93..23b537fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [dev] - YYYY-MM-DD + +### Fixed +* Fixed the ufunc docstrings, which held only the name of the C macro meant to supply them (e.g. `DOC_NUMPY__CORE_UMATH_SIN`): the docstring header is now generated by the build and included in the generated ufunc code [gh-282](https://github.com/IntelPython/mkl_umath/pull/282) + ## [0.6.0] - 2026-10-15 ### Added @@ -15,7 +20,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Pinned Cython in the Coverity Scan workflow so generated code stays stable between scans, and added `coverity/README.md` documenting the known Cython-boilerplate false positives and the scan review checklist [gh-266](https://github.com/IntelPython/mkl_umath/pull/266) ### Fixed -* Fixed the ufunc docstrings, which held only the name of the C macro meant to supply them (e.g. `DOC_NUMPY__CORE_UMATH_SIN`): the docstring header is now generated by the build and included in the generated ufunc code [gh-282](https://github.com/IntelPython/mkl_umath/pull/282) * Fixed `absolute` (float32/float64) returning `-NaN` for `+NaN` input on the scalar fallback path (same issue as numpy/numpy@dc478c58b9, gh-31433) [gh-269](https://github.com/IntelPython/mkl_umath/pull/269) * Fixed an over-decref of the borrowed module dictionary reference on the module initialization error path [gh-264](https://github.com/IntelPython/mkl_umath/pull/264) * Fixed a leak of the module object when the NumPy C-API import fails during module initialization [gh-263](https://github.com/IntelPython/mkl_umath/pull/263)