Skip to content

Commit c2a260f

Browse files
author
peng.li24
committed
refactor: inline backend #ifdef into elementwise.h / linalg.h, delete shim files
Delete numpy/detail/math_backend.h and numpy/detail/linalg_backend.h — these one-liner shim files only forwarded a single #ifdef NUMPYCPP_STD_ONLY block. Inline the selection directly in elementwise.h and linalg.h: elementwise.h: NUMPYCPP_STD_ONLY → detail/std_math_backend.h default → detail/npy_math_float.h + detail/svml_bridge.h linalg.h: NUMPYCPP_STD_ONLY → detail/std_linalg_backend.h default → detail/blas_bridge.h Build verified: both bit-exact and std targets compile and all 917 tests pass.
1 parent 2031c04 commit c2a260f

5 files changed

Lines changed: 21 additions & 101 deletions

File tree

numpy/detail/linalg_backend.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

numpy/detail/math_backend.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

numpy/elementwise.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,23 @@
3737
#include <algorithm>
3838

3939
// ── Internal detail headers ──────────────────────────────────────────────────
40-
// math_backend.h selects the math implementation at compile time:
41-
// NUMPYCPP_STD_ONLY not set → svml_bridge.h (bit-exact, dlsym + SVML)
42-
// NUMPYCPP_STD_ONLY set → std_math_backend.h (pure <cmath>, perf-first)
40+
// Backend selected at compile time:
41+
// NUMPYCPP_STD_ONLY not defined (default):
42+
// svml_bridge.h + npy_math_float.h — bit-exact (dlsym + SVML + AVX-512)
43+
// NUMPYCPP_STD_ONLY defined:
44+
// std_math_backend.h — pure <cmath>, performance-first, no dlsym
4345
// avx512_loops.h provides AVX-512 specialisations; skipped in STD_ONLY mode.
4446
// Both require NUMPYCPP_INTERNAL_INCLUDE; we manage that here.
4547
#ifndef NUMPYCPP_INTERNAL_INCLUDE
4648
# define NUMPYCPP_INTERNAL_INCLUDE
4749
# define _NUMPYCPP_EW_OWNS_GUARD
4850
#endif
49-
#include "detail/math_backend.h"
51+
#ifdef NUMPYCPP_STD_ONLY
52+
# include "detail/std_math_backend.h"
53+
#else
54+
# include "detail/npy_math_float.h"
55+
# include "detail/svml_bridge.h"
56+
#endif
5057
#include "detail/macros.h" // NUMPY_UNROLL4
5158

5259
namespace numpy {

numpy/linalg.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,20 @@
2929
#endif
3030

3131
// ── Internal detail headers ──────────────────────────────────────────────────
32-
// linalg_backend.h selects the linalg implementation at compile time:
33-
// NUMPYCPP_STD_ONLY not set → blas_bridge.h (bit-exact, OpenBLAS ILP64)
34-
// NUMPYCPP_STD_ONLY set → std_linalg_backend.h (pure loops, perf-first)
32+
// Backend selected at compile time:
33+
// NUMPYCPP_STD_ONLY not defined (default):
34+
// blas_bridge.h — bit-exact (OpenBLAS ILP64, dlsym)
35+
// NUMPYCPP_STD_ONLY defined:
36+
// std_linalg_backend.h — pure C++ loops, performance-first
3537
#ifndef NUMPYCPP_INTERNAL_INCLUDE
3638
# define NUMPYCPP_INTERNAL_INCLUDE
3739
# define _NUMPYCPP_LINALG_OWNS_GUARD
3840
#endif
39-
#include "detail/linalg_backend.h"
41+
#ifdef NUMPYCPP_STD_ONLY
42+
# include "detail/std_linalg_backend.h"
43+
#else
44+
# include "detail/blas_bridge.h"
45+
#endif
4046
#ifdef _NUMPYCPP_LINALG_OWNS_GUARD
4147
# undef NUMPYCPP_INTERNAL_INCLUDE
4248
# undef _NUMPYCPP_LINALG_OWNS_GUARD

numpycpp-config.cmake.in

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +0,0 @@
1-
@PACKAGE_INIT@
2-
3-
# numpycpp -- header-only C++ numpy API library.
4-
#
5-
# Backend selection (set BEFORE find_package, or via cmake -D):
6-
# cmake -DNUMPYCPP_STD_ONLY=OFF .. # bitexact (default): SVML + OpenBLAS via dlsym
7-
# cmake -DNUMPYCPP_STD_ONLY=ON .. # std: pure <cmath> + C++ loops, no dlsym
8-
#
9-
# The flag is propagated automatically to every target that links numpycpp:
10-
# bitexact → INTERFACE_LINK_LIBRARIES dl
11-
# std → INTERFACE_COMPILE_DEFINITIONS NUMPYCPP_STD_ONLY
12-
13-
# Non-namespaced + namespaced alias.
14-
# pybind11_add_module users: if the :: target is lost during generation, use
15-
# target_include_directories(mymod PRIVATE ${numpycpp_INCLUDE_DIRS})
16-
add_library(numpycpp INTERFACE IMPORTED)
17-
18-
set_target_properties(numpycpp PROPERTIES
19-
IMPORTED_GLOBAL TRUE
20-
INTERFACE_COMPILE_FEATURES "cxx_std_17"
21-
INTERFACE_INCLUDE_DIRECTORIES "${PACKAGE_PREFIX_DIR}/include/numpycpp"
22-
)
23-
24-
add_library(numpycpp::numpycpp ALIAS numpycpp)
25-
26-
# Propagate the correct backend flags to every consumer automatically.
27-
if(NUMPYCPP_STD_ONLY)
28-
# std backend: no external dependencies
29-
set_property(TARGET numpycpp APPEND PROPERTY
30-
INTERFACE_COMPILE_DEFINITIONS NUMPYCPP_STD_ONLY)
31-
message(STATUS "numpycpp: std backend (pure <cmath>, no dlsym)")
32-
else()
33-
# bitexact backend (default): libdl needed for dlsym -> numpy .so at runtime
34-
set_property(TARGET numpycpp APPEND PROPERTY
35-
INTERFACE_LINK_LIBRARIES dl)
36-
message(STATUS "numpycpp: bitexact backend (SVML + OpenBLAS via dlsym, -ldl)")
37-
endif()
38-
39-
# Fallback variables (pybind11_add_module target-loss workaround)
40-
set(numpycpp_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/numpycpp")
41-
42-
check_required_components(numpycpp)

0 commit comments

Comments
 (0)