ENH: C++ namespace and function overrides for npy_math #26729
Labels
01 - Enhancement
63 - C API
Changes or additions to the C API. Mailing list should usually be notified.
C++
Related to introduction and use of C++ in the NumPy code base
component: npy_math
Proposed new feature or change:
I'm working on improving an existing ufunc (complex
log1p
) in numpy, and I'm implementing the updated version in C++. The function will use several functions fromnpy_math
(npy_log
,npy_log1p
,npy_fabs
,npy_atan2
,npy_hypot
), and these all follow the C convention of having three versions, one for each of the typesnpy_float
,npy_double
andnpy_longdouble
, e.g.npy_fabsf
,npy_fabs
andnpy_fabsl
.It would really nice if we had a C++ namespace (e.g.
npy
to match the "poor man's namespace" implemented with the prefixnpy_
in C) that provides a single name with overloaded implementations for each type, e.g.npy::fabs
. This would make writing templated code in C++ much easier.As an experiment, I added this code to the end of
npy_math.h
:Then in a templated C++ function that includes
npy_math.h
, I usenpy::fabs
,npy::log
, etc. This works fine.Is there interest in such an update to
npy_math.h
(or some other header) to facilitate writing code in C++? Of course, giving all the functions innpy_math.h
similar wrappers will be more work, and there might be some gotchas that show up in the process, but with more and more code being implemented in C++ in NumPy, I think this is something we need.The text was updated successfully, but these errors were encountered: