Skip to content

Commit d00620b

Browse files
peng.li24claude
andcommitted
feat: initial numpcpp import — C++ numpy pixel-level alignment
Import core.h/cpp, linalg.h/cpp, einsum.h/cpp, and test_einsum.py from melange tpp_onemodel_cpp/numpy/. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
0 parents  commit d00620b

9 files changed

Lines changed: 2617 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(numpycpp VERSION 0.1.0 LANGUAGES CXX)
3+
4+
# C++20
5+
set(CMAKE_CXX_STANDARD 20)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
8+
9+
if(NOT CMAKE_BUILD_TYPE)
10+
set(CMAKE_BUILD_TYPE Release)
11+
endif()
12+
13+
# Dependencies
14+
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
15+
find_package(pybind11 CONFIG REQUIRED)
16+
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
17+
18+
# Collect sources
19+
file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/numpy/*.cpp)
20+
21+
# Headers
22+
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
23+
24+
# Python module
25+
pybind11_add_module(numpycpp ${SOURCES})
26+
27+
target_include_directories(numpycpp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
28+
target_link_libraries(numpycpp PRIVATE Eigen3::Eigen)
29+
30+
set_target_properties(numpycpp PROPERTIES
31+
PREFIX ""
32+
SUFFIX ".so"
33+
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
34+
)
35+
36+
# Install
37+
install(TARGETS numpcpp
38+
LIBRARY DESTINATION ${Python3_SITEARCH}
39+
)
40+
41+
install(DIRECTORY numpy/
42+
DESTINATION include/numpycpp
43+
FILES_MATCHING PATTERN "*.h"
44+
)
45+
46+
message(STATUS "numpycpp v${PROJECT_VERSION}")
47+
message(STATUS " C++ Standard: ${CMAKE_CXX_STANDARD}")
48+
message(STATUS " Python: ${Python3_VERSION}")
49+
message(STATUS " Eigen3: ${EIGEN3_INCLUDE_DIR}")

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# numpcpp
2+
3+
C++ pixel-level alignment of Python numpy, powered by Eigen.
4+
5+
## Overview
6+
7+
`numpycpp` provides a C++ implementation of numpy's core API (`numpy.*`, `numpy.linalg.*`, `numpy.einsum`), designed for seamless pybind11 integration. Every function mirrors Python numpy's signature and semantics.
8+
9+
## Dependencies
10+
11+
- C++20
12+
- [pybind11](https://github.com/pybind/pybind11)
13+
- [Eigen3](https://eigen.tuxfamily.org/) >= 3.3
14+
15+
## Build
16+
17+
```bash
18+
mkdir build && cd build
19+
cmake .. -DCMAKE_BUILD_TYPE=Release
20+
make -j$(nproc)
21+
```
22+
23+
## Usage
24+
25+
```python
26+
import numpcpp
27+
```
28+
29+
## License
30+
31+
MIT

0 commit comments

Comments
 (0)