Skip to content

ENH: Port numpy._core._simd to the Limited API - #32244

Merged
mattip merged 7 commits into
numpy:mainfrom
prathamhole14:simd_limited_api
Sep 6, 2026
Merged

mattip merged 7 commits into
numpy:mainfrom
prathamhole14:simd_limited_api

Conversation

@prathamhole14

Copy link
Copy Markdown
Member

PR summary

Related to: #31913
I will update this soon with benchmarks. For now I will look how CI reacts, locally all the tests are passing for python 3.13 linux build with limted api flag on.

AI Disclosure

In researching and brainstorming specially the meson build part and for writing comments.

Replace the constructs that are not part of the Limited API: the static
PyTypeObject and its PySequenceMethods become a PyType_Spec heap type,
PyObject_New() becomes PyType_GenericAlloc(), and the fast sequence,
tuple and list accessors become their checked equivalents. Add the libc
includes that Python.h stops providing at Py_LIMITED_API >= 3.11.

Nearly all of the module's Python-facing code is compiled into the
_simd_mtargets archive, which the `limited_api:` kwarg does not reach,
so add py_limited_api_args and pass it there.
python.allow_limited_api defaults to false, so this is a no-op for
shipped wheels.
@prathamhole14
prathamhole14 marked this pull request as ready for review August 11, 2026 07:18
@prathamhole14

Copy link
Copy Markdown
Member Author

This PR is ready for review!

Comment thread meson.build Resolved

@mattip mattip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than one simplification this looks good to me.

@mattip

mattip commented Aug 31, 2026

Copy link
Copy Markdown
Member

There is just this niggle left

I will update this soon with benchmarks.

I think this is a non-critical part of NumPy, so I don't want to push too hard on benchmarks, was there something in particular that might be problematic?

@prathamhole14

prathamhole14 commented Aug 31, 2026 •

Copy link
Copy Markdown
Member Author

I think this is a non-critical part of NumPy, so I don't want to push too hard on benchmarks, was there something in particular that might be problematic?

Nope, I planned to do benchmark just to see if anything is affected. Not that I think anything will, since the diff doesn't necessarily make things slower. I did try benchmarking but all I was able to do is capture noise with no noticeable regression due to this diff. I think this is safe to go in terms of benchmarks.

@mattip

mattip commented Aug 31, 2026

Copy link
Copy Markdown
Member

Cool. At some point we should refactor _umath_tests_mtargets in numpy/_core/meson.build to use py_limited_api_args, (which means moving it up before _umath_tests_mtargets), do you want to do it in this PR or as follow up?

@prathamhole14

Copy link
Copy Markdown
Member Author

Done in this PR itself.

@mattip

mattip commented Sep 2, 2026

Copy link
Copy Markdown
Member

Ahh, I merged #32335 and now there are merge conflicts

@prathamhole14
prathamhole14 requested a review from mattip September 3, 2026 16:26
@mattip
mattip merged commit 86a7193 into numpy:main Sep 6, 2026
92 checks passed
@mattip

mattip commented Sep 6, 2026

Copy link
Copy Markdown
Member

Thanks @prathamhole14

@prathamhole14
prathamhole14 deleted the simd_limited_api branch September 6, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants