This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
pocket_numpy (repo: xtensor-numpy) is a C++ project that integrates the pocketpy lightweight Python interpreter with numpy-like array functionality powered by xtensor and Eigen. It produces:
- A native CLI (
pocketpy.exe) that runs Python scripts with numpy support - Python wheels via pybind11 (package name:
pocket_numpy) - A WebAssembly build for browser deployment
# Build (installs in editable mode with scikit-build-core)
make build
# Run numpy tests via pocketpy CLI
make test # runs: build/pocketpy.exe tests/test_numpy.py
# Run a single test file
build/pocketpy.exe tests/test_numpy.py
# Run tests via pytest (after pip install)
python3 -m pytest tests/
# Install as pip package
make python_install
# Build WASM
make build_wasm
# Serve WASM demo locally
make serve_wasmDefines C++ type aliases (int8–64, uint8–64, float32, float64, bool_, complex64/128) and dtype_traits<T> template for runtime dtype identification. Contains the ndarray<T> template backed by xt::xarray<T>.
ndarray_base is an abstract base class with ~80+ virtual methods (shape, reductions, slicing, arithmetic, sorting, etc.). ndarray<T> is the concrete template implementation. This virtual dispatch pattern enables a single Python-facing interface that works across all numeric types via std::unique_ptr<ndarray_base>.
Registers the numpy module into pocketpy's runtime. Binds all ndarray methods, array creation functions (ones, zeros, full, arange, linspace, identity), random number generation, and dtype attributes. This is the largest source file.
Ramer-Douglas-Peucker polyline simplification exposed via pybind11 as the _core module. Supports 2D and 3D point arrays using Eigen matrix types.
Initializes pocketpy, registers the numpy module via py_module_initialize(), then executes a Python script or enters REPL mode.
- pocketpy — git submodule at
pocketpy/ - xtensor, xtl, Eigen — vendored headers in
include/ - pybind11 — required via pip/CMake for Python wheel builds
numpy— static library (numpy.cpp + pocketpy)pocketpy_cli— CLI executable linked against numpy_core— pybind11 module for RDP bindings
- NEVER use
git commit --amend. Always create a new commit instead. Amending rewrites history and can destroy previous work, especially after a failed pre-commit hook where--amendwould silently modify the wrong commit.
- C++17 required; C11 for pocketpy C sources
- Default build type is Release with
-O3; debug uses-O0 -ggdb - xtensor warnings are suppressed by default (
SHOW_XTENSOR_WARNINGS=OFF) - Tests are standalone Python scripts (not pytest-based) so they can also run under pocketpy and WASM
- macOS deployment target is 10.14+ (required for
std::visit)