Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork11.9k
Description
We talked about this a few years ago in#22710, but I think we're at the point where we have broad consensus we should start working on moving long C macros and.c.src templates to C++ templates.
Reasons to do this:
- C macros are hard to debug and hard to read
- The
.c.srctemplates are a thing any new contributor has to learn. They also make it substantially harder to grep the codebase for strings that show up in tracebacks. - C++ templates have much better editor and LSP tooling, with broad support for C++ features in popular tooling that universally has zero support for our custom
.c.srcformat.
C++ templates aren't perfect, of course, and we should strive to avoid overusing them in ways that will harm binary size or compile time. That will require review on a case-by-case basis.
Currently we have the following.c.src templates in the codebase:
numpy/_core/src/_simd/_simd.dispatch.c.srcnumpy/_core/src/_simd/_simd_data.inc.srcnumpy/_core/src/multiarray/_multiarray_tests.c.srcnumpy/_core/src/multiarray/argfunc.dispatch.c.srcnumpy/_core/src/multiarray/arraytypes.c.srcnumpy/_core/src/multiarray/einsum.c.srcnumpy/_core/src/multiarray/einsum_sumprod.c.srcnumpy/_core/src/multiarray/lowlevel_strided_loops.c.srcnumpy/_core/src/multiarray/nditer_templ.c.srcnumpy/_core/src/multiarray/scalartypes.c.srcnumpy/_core/src/npymath/ieee754.c.srcnumpy/_core/src/npymath/npy_math_complex.c.srcnumpy/_core/src/umath/_umath_tests.c.srcnumpy/_core/src/umath/funcs.inc.srcnumpy/_core/src/umath/loops.c.srcnumpy/_core/src/umath/loops_arithm_fp.dispatch.c.srcnumpy/_core/src/umath/loops_arithmetic.dispatch.c.srcnumpy/_core/src/umath/loops_autovec.dispatch.c.srcnumpy/_core/src/umath/loops_comparison.dispatch.c.srcnumpy/_core/src/umath/loops_exponent_log.dispatch.c.srcnumpy/_core/src/umath/loops_half.dispatch.c.srcnumpy/_core/src/umath/loops_minmax.dispatch.c.srcnumpy/_core/src/umath/loops_modulo.dispatch.c.srcnumpy/_core/src/umath/loops_umath_fp.dispatch.c.srcnumpy/_core/src/umath/loops_unary.dispatch.c.srcnumpy/_core/src/umath/loops_unary_complex.dispatch.c.srcnumpy/_core/src/umath/loops_unary_fp.dispatch.c.srcnumpy/_core/src/umath/loops_unary_fp_le.dispatch.c.srcnumpy/_core/src/umath/matmul.c.srcnumpy/_core/src/umath/scalarmath.c.srcI know that@seiko2plus has a long overdue patch to replace all the SIMD loops with C++ templates, and we should work on getting that in and not try to duplicate.
Separately I think good candidates to look at first includematmul.c.src,einsum.c.src, andeinsum_sumprod.c.src.
I wouldn't worry too much about the usage in internal-only tests, since those files don't get touched often and changes there won't help us with code that users actually run.
SeeRalf's comment below for npymath, it should be left alone.
I thinkscalarmath.c.src,scalartypes.c.src,nditer_templ.c.src, andarraytypes.c.src might be trickier since that would require dealing with a lot of internal headers that never anticipated being used inside C++ code.