Skip to content

Commit b5e3248

Browse files
author
peng.li24
committed
refactor: split headers into init/elementwise/reduce/manipulation/io/linalg + numpy.h umbrella
Header reorganisation: numpy/numpy.h ← new umbrella (single include entry point) numpy/init.h ← zeros_like, ones_like, full numpy/elementwise.h ← sqrt/exp/sin/…, comparison, logical, isnan, astype numpy/reduce.h ← pairwise_sum, sum/mean/std/var/any/all, axis_reduce_impl, cumsum numpy/manipulation.h ← diff/stack/concat/transpose/roll/flip, take/compress/slice/put/putmask numpy/io.h ← isin/intersect1d/flatnonzero, interp, safe_divide, unwrap numpy/linalg.h ← dot, norm, matmul + einsum merged in (einsum.h absorbed) numpy/detail/macros.h← NUMPY_UNROLL4, NUMPY_SMALL_STACK (shared macro header) Backward compat: numpy/core.h → shim: #include "numpy/numpy.h" numpy/einsum.h → shim: #include "numpy/numpy.h" DEB packaging: cmake/preinst: always rm -rf /usr/include/numpycpp before install/upgrade so stale headers from previous versions cannot accumulate All 900 tests pass.
1 parent d842caa commit b5e3248

19 files changed

Lines changed: 1805 additions & 1790 deletions

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ set(CPACK_DEBIAN_PACKAGE_SECTION "libdevel")
6565
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
6666
set(CPACK_DEBIAN_FILE_NAME "numpycpp-dev-${CPACK_PACKAGE_VERSION}-Linux.deb")
6767
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr")
68+
# Wipe the old include tree on install/upgrade so stale headers cannot accumulate.
69+
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/cmake/preinst")
6870

6971
include(CPack)
7072

README.md

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,26 @@ All APIs are tested against Python numpy under strict bit-level comparison: ever
2929

3030
### Usage
3131

32-
**Public headers**these are the only files you should `#include`:
32+
**Public headers**include the umbrella or individual modules:
3333

3434
```cpp
35-
#include "numpy/core.h" // numpy.* equivalents
36-
#include "numpy/linalg.h" // numpy.linalg.*
37-
#include "numpy/einsum.h" // numpy.einsum
35+
#include "numpy/numpy.h" // ← single entry point (recommended)
36+
37+
// or include only what you need:
38+
#include "numpy/init.h" // zeros_like, ones_like, full
39+
#include "numpy/elementwise.h" // sqrt, exp, sin, astype, …
40+
#include "numpy/reduce.h" // sum, mean, std, var, cumsum, …
41+
#include "numpy/manipulation.h" // transpose, take, slice, putmask, …
42+
#include "numpy/io.h" // isin, interp, unwrap, …
43+
#include "numpy/linalg.h" // dot, norm, matmul, einsum
3844
```
3945

4046
> `numpy/detail/` headers are **internal** — automatically pulled in by the
4147
> public headers. Do not include them directly; a compile-time `#error` fires
4248
> if you try.
49+
>
50+
> Legacy single-file headers `numpy/core.h` and `numpy/einsum.h` are kept as
51+
> backward-compatible shims that simply `#include "numpy/numpy.h"`.
4352
4453
```cpp
4554
std::vector<double> data = {1.0, 4.0, 9.0};
@@ -212,25 +221,32 @@ All 900 tests pass under strict IEEE 754 bit comparison (float64 + float32).
212221

213222
```
214223
numpycpp/
215-
├── numpy/ # native C++ headers
216-
│ ├── core.h # [PUBLIC] numpy.* equivalents
217-
│ ├── linalg.h # [PUBLIC] numpy.linalg.*
218-
│ ├── einsum.h # [PUBLIC] numpy.einsum
219-
│ └── detail/ # [INTERNAL] do not include directly — #error guard
220-
│ ├── svml_bridge.h # SVML / npy_* scalar math dispatch
221-
│ ├── npy_math_float.h # npy_* float32 wrappers
222-
│ ├── blas_bridge.h # BLAS (cblas) thin wrappers
223-
│ └── avx512_loops.h # AVX-512 vectorised exp/sin/cos loops
224-
├── pycpp/ # pybind11 wrappers (optional)
224+
├── numpy/ # native C++ headers
225+
│ ├── numpy.h # [PUBLIC] umbrella — #includes everything below
226+
│ ├── init.h # [PUBLIC] zeros_like, ones_like, full
227+
│ ├── elementwise.h # [PUBLIC] sqrt/exp/sin/…, comparison, logical, astype
228+
│ ├── reduce.h # [PUBLIC] sum/mean/std/var/cumsum, axis reductions
229+
│ ├── manipulation.h # [PUBLIC] transpose/take/slice/put/putmask/argsort/…
230+
│ ├── io.h # [PUBLIC] isin, interp, unwrap, safe_divide
231+
│ ├── linalg.h # [PUBLIC] dot, norm, matmul, einsum
232+
│ ├── core.h # [SHIM] backward-compat → #include "numpy.h"
233+
│ ├── einsum.h # [SHIM] backward-compat → #include "numpy.h"
234+
│ └── detail/ # [INTERNAL] do not include directly — #error guard
235+
│ ├── macros.h # NUMPY_UNROLL4, NUMPY_SMALL_STACK
236+
│ ├── svml_bridge.h # SVML / npy_* scalar math dispatch
237+
│ ├── npy_math_float.h # npy_* float32 wrappers
238+
│ ├── blas_bridge.h # BLAS (cblas) thin wrappers
239+
│ └── avx512_loops.h # AVX-512 vectorised exp/sin/cos loops
240+
├── pycpp/ # pybind11 wrappers (optional)
225241
│ ├── core_py.h
226242
│ ├── linalg_py.h
227243
│ └── einsum_py.h
228-
├── tests/ # bit-level precision tests + test module
229-
│ ├── module.cpp # pybind11 module for testing
230-
│ ├── test_all.py # single entry — all APIs, 900 tests, float64+float32
231-
│ ├── conftest.py # silent-mode output suppression
232-
│ └── CMakeLists.txt # test-module build
233-
├── CMakeLists.txt # build & .deb packaging
244+
├── tests/ # bit-level precision tests + test module
245+
│ ├── module.cpp # pybind11 module for testing
246+
│ ├── test_all.py # single entry — all APIs, 900 tests, float64+float32
247+
│ ├── conftest.py # silent-mode output suppression
248+
│ └── CMakeLists.txt # test-module build
249+
├── CMakeLists.txt # build & .deb packaging
234250
└── README.md
235251
```
236252

cmake/preinst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
# numpycpp DEB pre-install hook.
3+
# Always wipe the previous include tree so stale headers cannot accumulate
4+
# across version upgrades (e.g. old numpy/core.h would shadow new modules).
5+
set -e
6+
case "$1" in
7+
install|upgrade)
8+
rm -rf /usr/include/numpycpp
9+
;;
10+
esac

0 commit comments

Comments
 (0)