Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
72474df
docs(examples): add hardware-aware examples — docs/EXAMPLES.md:1, exa…
sergiorandria Sep 2, 2026
e33e1ea
feat(isabelle): complete Padic verification — isabelle/Padic_Verifica…
sergiorandria Sep 2, 2026
e3643b2
bench(hardware): add HBM/tensor/ReRAM/photonics/neuromorphic/padic/la…
sergiorandria Sep 2, 2026
dfbdd28
ci: add GitHub Actions for ctest 38/38 + isabelle + examples — .githu…
sergiorandria Sep 2, 2026
e8a8643
feat(api): integrate api_macros across all subsystems — api_macros.hpp:1
sergiorandria Sep 2, 2026
e3fb140
feat(isabelle): add Hardware verification — isabelle/Hardware_Verific…
sergiorandria Sep 2, 2026
8945ae8
feat(python): add pybind11 bridge — python/numpy_cpp.cpp:1
sergiorandria Sep 2, 2026
4605f91
docs: rewrite AGENTS.md to Modern C++ Directives — AGENTS.md:1
sergiorandria Sep 2, 2026
bbdd43b
improve(linalg): add tensor/AMX dispatch hook for float GEMM — linalg…
sergiorandria Sep 2, 2026
d336129
fix(isabelle): complete Differential/Hardware proofs — Differential_V…
sergiorandria Sep 2, 2026
fc6a42c
fix(lattice,padic): revert LatticeScalar to arithmetic-only and fix t…
sergiorandria Sep 2, 2026
a144b52
feat(pqc): add secure_buffer RAII and hardened vector<bool> secure_zero
sergiorandria Sep 2, 2026
483b840
feat(creation): add NP_USE_SECURE_IMPL branch for zeros with secure_z…
sergiorandria Sep 2, 2026
7dd682b
build(cmake): add NP_USE_SECURE_IMPL option for hardened creation
sergiorandria Sep 2, 2026
0efa077
improve(spectral): integrate with lattice — spectral.hpp:228
sergiorandria Sep 2, 2026
237cf5f
feat(photonics): add hardware-aware MZI mesh backends and calibration
sergiorandria Sep 2, 2026
b6c71cd
fix(photonics): guard normal_distribution for zero stddev and fix dac…
sergiorandria Sep 2, 2026
d4d3166
refactor(creation): use secure_buffer::release for isolated zero init
sergiorandria Sep 2, 2026
54f528c
feat(lattice): implement blockwise BKZ and sieve heuristic for SVP
sergiorandria Sep 2, 2026
e6e053c
feat(pqc): add mlock/munlock page isolation and slack wipe
sergiorandria Sep 2, 2026
b9cffb2
feat(tensor): add AlphaEvolve 48-mult 4x4 and Strassen/Winograd hybrid
sergiorandria Sep 2, 2026
c82abb5
feat(differential): harden LLVM JIT for derivative and functions
sergiorandria Sep 2, 2026
14a2592
feat(quantum,physics): improve isolated VM circuit and add Navier-Sto…
sergiorandria Sep 2, 2026
da5b38d
feat(physics): add Navier-Stokes fluid solvers — physics.hpp:1
sergiorandria Sep 2, 2026
334b3c3
build(cmake): add powerful GPU/OpenMP meta-preset and driver dlopen
sergiorandria Sep 2, 2026
e185c1c
perf(linalg): tune-aware GPU dispatch + OpenMP for powerful CPUs
sergiorandria Sep 2, 2026
0f76daa
fix(quantum): Builder Rule-of-Five and measure lvalue fix
sergiorandria Sep 2, 2026
9f49c92
perf(tensor): dispatch Hopper/AMX to GPU when available
sergiorandria Sep 2, 2026
5db81ac
bench(hardware): add powerful GEMM 64-1024 CPU vs GPU vs Auto + memory
sergiorandria Sep 2, 2026
e2f0eaa
build(presets): add powerful preset for workstation + GPU
sergiorandria Sep 2, 2026
504a29c
docs(powerful): add tuning guide for workstation+GPU
sergiorandria Sep 2, 2026
d395cf1
examples(powerful): add GPU+AVX2 demo for powerful workstation
sergiorandria Sep 2, 2026
bc38a74
feat(tensor): add AlphaEvolve 48-mult 4x4 and Strassen/Winograd hybri…
sergiorandria Sep 2, 2026
3990158
feat(tensor): extend AlphaEvolve with Laderman 3x3, CW and optimizer
sergiorandria Sep 3, 2026
604d8bd
feat(examples): add Navier-Stokes lid-driven cavity — examples/physic…
sergiorandria Sep 3, 2026
922c922
fix(tensor): keep CPU backend name as CPU for test_compat
sergiorandria Sep 3, 2026
4a09998
feat(gpu): add cuFFT dlopen probe and FFT offload path
sergiorandria Sep 3, 2026
c7caac2
fix(physics): add max_divergence diagnostic to NavierStokes2D
sergiorandria Sep 3, 2026
de299ea
style(tensor): clang-format and modernize tensor_core
sergiorandria Sep 3, 2026
3b67b0c
feat(half,tensor): add FP16/BF16 and AlphaEvolve 4x4 — half.hpp:1, te…
sergiorandria Sep 3, 2026
37c5f22
feat(tensor): FP16/BF16 Hopper matmul via half
sergiorandria Sep 3, 2026
1c08356
feat(np): expose half in umbrella header
sergiorandria Sep 3, 2026
e6cb685
perf(threadpool): NUMA pinning for powerful Linux
sergiorandria Sep 3, 2026
172d90b
fix(tests): add (void) for nodiscard fft in error-handling paths
sergiorandria Sep 3, 2026
cec365d
fix(tests): add (void) for nodiscard nanargmax (powerful -Werror)
sergiorandria Sep 3, 2026
c4048de
fix(pqc): correct parenthesis in ct_eq_u32
sergiorandria Sep 3, 2026
57d3e06
fix(statistics): correct parenthesis in histogram bin calc
sergiorandria Sep 3, 2026
d6e21fc
fix(half): rename float16 to half for consistency — half.hpp:17
sergiorandria Sep 3, 2026
2ac3cd6
fix(half): avoid float16 tag conflict with dtype.hpp
sergiorandria Sep 3, 2026
35822e1
fix(half,tensor): make half production-ready and fix tensor fp16/bf16…
sergiorandria Sep 3, 2026
e311a59
refactor(tensor): consteval pow2 helpers and bit-twiddling next_pow2
sergiorandria Sep 3, 2026
ae7d0fd
feat(security): harden ndarray/matrix/polynomial for PQC production
sergiorandria Sep 3, 2026
b41f2ab
feat(security): add secure linalg wrappers (constant-time, PQC)
sergiorandria Sep 3, 2026
1391d2e
fix(memory): DRY TaggedArray, variant powerful, hugepage guard — memo…
sergiorandria Sep 3, 2026
52b3974
fix(memory): const_cast for madvise huge-page on const data
sergiorandria Sep 3, 2026
c9be05c
fix(analog): scale clamp, narrowing, IWYU — memristor.hpp:1
sergiorandria Sep 3, 2026
8176325
feat(security): add secure FFT wrappers (constant-time, PQC)
sergiorandria Sep 3, 2026
aa90d0a
fix(modular): bernoulli optional, factor check, dedekind q24 — modula…
sergiorandria Sep 3, 2026
7090930
perf(gpu): AVX512 FMA 16-wide for Xeon powerful (f32/f64)
sergiorandria Sep 3, 2026
13ef65e
perf(gpu,linalg): multi-GPU sharding for 4K GEMM
sergiorandria Sep 3, 2026
e3c1e9e
perf(simd): integrate SIMD across subsystems for powerful CPUs
sergiorandria Sep 3, 2026
5e926dc
docs(performance): add hardware bench for HBM/tensor/analog — docs/PE…
sergiorandria Sep 3, 2026
5e6d921
fix(np): reorder bigint before ndarray for ProxyBase<bigint> — np.hpp:13
sergiorandria Sep 3, 2026
734f6ae
fix(fixed): support bigint in NP_FIXED_BINOP concept
sergiorandria Sep 3, 2026
dbc58c2
feat(ndarray): support more shapes via span/range/array/C-array — nda…
sergiorandria Sep 3, 2026
bc9dd61
feat(gpu): add cuda stub header for header-only GPU dispatch
sergiorandria Sep 3, 2026
bb243e4
feat(cuda): integrate CUDA 12/13 new features via header-only dlopen
sergiorandria Sep 3, 2026
7c08228
fix(threadpool): RAII unique_ptr + jthread per AGENTS.md
sergiorandria Sep 3, 2026
d3a70a4
fix(review): threadpool RAII, cohomology static_cast, bundle cast
sergiorandria Sep 3, 2026
53b2775
fix(differential): use enum class for Node::Type per AGENTS.md
sergiorandria Sep 3, 2026
319d9e9
feat(isabelle): add Spectral/Hodge verification — isabelle/Spectral_V…
sergiorandria Sep 4, 2026
e7ed4a1
ci(python): add PyPI publish workflow — .github/workflows/publish.yml:1
sergiorandria Sep 4, 2026
c1413c5
feat(half): add simd quantize/dequantize for FP16 — half.hpp:68
sergiorandria Sep 4, 2026
e46dbbc
fix(isabelle): padic Hensel fully auto — Padic_Verification.thy:19
sergiorandria Sep 4, 2026
0843492
feat(examples): add spectral Hodge lattice — examples/spectral_hodge.…
sergiorandria Sep 4, 2026
374d583
refactor(tensor): consteval pow2 helpers and bit-twiddling next_pow2
sergiorandria Sep 4, 2026
72375e2
refactor(np): break tensor_core↔linalg cycle + split differential JIT
sergiorandria Sep 4, 2026
be4557d
feat(secure): centralize secure_allocator + ct trait
sergiorandria Sep 4, 2026
3b3fe3b
fix(bigint): add arithmetic operators for cpp_int fallback
sergiorandria Sep 4, 2026
82c92b2
fix(ci): bigint ADL + FMA guard + Blackwell
sergiorandria Sep 4, 2026
29f78ca
fix(bigint,ci): production hardening for bigint and Isabelle CI
sergiorandria Sep 4, 2026
a991e70
fix(bigint): fallback convert_to<T> for homology/homotopy/modular
sergiorandria Sep 4, 2026
a6a9ff6
fix(bigint): explicit operator T for static_cast in padic fallback
sergiorandria Sep 4, 2026
2ab227e
fix(bigint): fallback string bigint arithmetic + numeric compare for …
sergiorandria Sep 4, 2026
73fd706
fix(bigint): fallback unary minus string-based, no stoll overflow
sergiorandria Sep 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI

on:
push:
branches: [dev, main]
pull_request:
branches: [dev, main]

jobs:
ctest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
- name: Build
run: cmake --build build -j8
- name: Test 38/38
run: ctest --test-dir build --output-on-failure
- name: Bench hardware (smoke)
run: ./build/tests/bench_hardware || true

isabelle:
runs-on: ubuntu-latest
container: makarius/isabelle:Isabelle2025-2
steps:
- uses: actions/checkout@v4
- name: Build NumpyCpp session
run: |
export PATH="/usr/local/Isabelle/bin:/opt/Isabelle/bin:$PATH"
if ! command -v isabelle >/dev/null 2>&1; then
ISABIN=$(find / -name isabelle -type f 2>/dev/null | head -n1)
if [ -n "$ISABIN" ]; then export PATH="$(dirname "$ISABIN"):$PATH"; fi
fi
isabelle build -D isabelle -v

examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build examples
run: |
g++ -std=c++20 -I include examples/neuromorphic_snn.cpp -o /tmp/neuromorphic_snn && /tmp/neuromorphic_snn
g++ -std=c++20 -I include examples/hbm_matmul.cpp -o /tmp/hbm_matmul && /tmp/hbm_matmul
g++ -std=c++20 -I include examples/padic_hensel.cpp -o /tmp/padic_hensel && /tmp/padic_hensel
g++ -std=c++20 -I include examples/quantum_photonics.cpp -o /tmp/quantum_photonics && /tmp/quantum_photonics
23 changes: 23 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish

on:
push:
tags: ["v*"]
workflow_dispatch:

jobs:
pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Build sdist
run: |
pip install build
python -m build --sdist --outdir dist python/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
171 changes: 143 additions & 28 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,143 @@
# Development Guidelines

This document describes workflow, style, and testing expectations for contributors.

## Workflow
- Check `README.md` and `include/np/*.hpp` for existing API before adding new functions.
- Match NumPy reference signatures exactly (see `numpy-reference/reference/generated/` if available).
- Implement in appropriate header (`creation.hpp`, `math.hpp`, `logic.hpp`, `statistics.hpp`, `linalg.hpp`, `fft/`, `io.hpp`, `char.hpp`, `polynomial.hpp`).
- Add Doxygen comments with `Reference:` link.
- Ensure header is included in `np.hpp` if it is part of the public API.

## Style
- `snake_case` for functions, `PascalCase` for types, 2-space indent, Allman braces (`BreakBeforeBraces: Allman`).
- Format with `clang-format` using `.clang-format` at repo root: `clang-format -i include/np/*.hpp`.
- Keep `UseTab: Never`, `ColumnLimit: 90`, `SortIncludes: Never`.

## Testing
- Add a test file `tests/test_<module>.cpp` using `tests/test_util.hpp` (`test::check`, `test::approx`, `test::approx_c`).
- Register in `tests/CMakeLists.txt` `NP_TESTS`.
- Build and run: `cmake -S . -B build && cmake --build build && ctest --test-dir build --output-on-failure`.

## Commits
- One commit per logical task, message `feat(module): ...` with file:line references where helpful.
- Do not commit `build/`, `CMakeFiles/`, `DartConfiguration.tcl`, `CMakeCache.txt`.

## Notes
- `Matrix<T>` is legacy; prefer `ndarray<T>` + `linalg.hpp` for new code.
- `np::ch` (char) helpers operate on `ndarray<std::string>`.
#AGENTS.md — Modern C++ Directives

Instructions for any AI agent (or human) writing, reviewing, or refactoring C++ code in this repository. Follow these rules by default; deviate only when the codebase's existing conventions clearly require it, and say so.


## 1. Language Standard


- Target **C++20** by default. Use **C++23** features only if the project's `CMakeLists.txt` / toolchain already sets `CXX_STANDARD 23` and the compiler supports it (GCC 13+, Clang 16+, MSVC 19.34+).
- Never write C++98/03-style code (no raw `typedef`, no C-style casts, no `NULL`).
- Prefer standard library facilities over hand-rolled equivalents or third-party utility libraries unless the project already depends on one (e.g. Boost, Abseil, fmt).


## 2. Memory & Resource Management


- **No raw `new` / `delete`.** Use RAII everywhere.
- Ownership:
- `std::unique_ptr<T>` — default choice for owned, exclusive resources.
- `std::shared_ptr<T>` — only when shared ownership is a real requirement (not a substitute for design).
- `std::weak_ptr<T>` — to break cycles / observe without owning.
- Prefer value semantics and containers over pointers whenever lifetime doesn't need to outlive the enclosing scope.
- Non-owning references: pass `T&`, `const T&`, or `std::span<T>` / `std::string_view` instead of raw pointers where possible.
- No manual `malloc`/`free` in new code.
- Every resource (file handle, mutex lock, socket, GPU handle) must be wrapped in an RAII type.


## 3. Types & Correctness


- `const`-correct by default: mark variables, parameters, and member functions `const` unless mutation is required.
- Prefer `constexpr` over `const` for compile-time-known values; prefer `consteval`/`constinit` (C++20) where semantics call for it.
- Use `auto` for local variable deduction when it improves readability (iterators, lambdas, long template types);
do **not** use `auto` where it hides an important type at a glance (e.g. public API return types, numeric conversions).
- Use scoped `enum class`, never unscoped `enum`.
- Use `std::optional<T>` instead of sentinel values (`-1`, `nullptr`, magic strings) to represent "no value."
- Use `std::variant<...>` + `std::visit` instead of manual tagged unions or inheritance-based polymorphism when the set of alternatives is closed.
- Prefer `std::span<T>` over `(pointer, size)` pairs, and `std::string_view` over `const std::string&` for read-only string params.
- Use structured bindings (`auto [a, b] = ...`) instead of `.first`/`.second` or manual unpacking.
- Use Concepts (C++20) to constrain templates instead of SFINAE or unconstrained templates with unclear requirements.


## 4. Error Handling


- Use exceptions for truly exceptional, unrecoverable-at-the-call-site errors.
- For expected, recoverable failure paths (parse errors, "not found," validation), prefer `std::expected<T, E>` (C++23) or a project-standard `Result<T, E>` type over exceptions or error codes.
- Never use error codes returned through output parameters in new code.
- Never swallow exceptions silently (`catch (...) {}` with no action is forbidden). Log or rethrow.
- Mark functions `noexcept` when they genuinely cannot throw — this affects optimization and container behavior (e.g. `std::vector` move semantics).


## 5. Functions, Classes & API Design


- Follow the **Rule of Zero**: don't declare special member functions unless the class manages a resource directly. Let RAII members handle it.
- If you must manage a resource directly, follow the **Rule of Five** (or `= delete` copy/move explicitly).
- Mark single-argument constructors `explicit` unless implicit conversion is intentional and documented.
- Prefer free functions over static member functions for stateless utilities.
- Prefer composition over inheritance. Use inheritance only for genuine "is-a" polymorphism with virtual dispatch;
mark base destructors `virtual` (or classes `final`).- Pass small trivially
- copyable types by value;
pass large / non - trivial types by `const&`; use `&&` for sink parameters that will be moved-from.
- Return by value and rely on RVO/move semantics — don't manually optimize with output parameters unless profiling proves it necessary.


## 6. Modules, Headers & Build


- If the toolchain supports C++20 modules and the project has adopted them, prefer modules for new components. Otherwise use traditional headers with `#pragma once`.
- Keep headers minimal: forward-declare where possible, include only what you use (IWYU principle).
- One class/component per translation unit pair (`.hpp`/`.cpp`) unless components are tightly coupled and small.
- Use namespaces to scope project code;
avoid `using namespace std;` in headers (acceptable, sparingly, inside `.cpp` function scope only).


## 7. Concurrency


- Prefer `std::jthread` (C++20) over `std::thread` — it joins automatically and supports cooperative cancellation via `std::stop_token`.
- Protect shared state with RAII locks (`std::lock_guard`, `std::scoped_lock`, `std::unique_lock`) — never call `mutex.lock()`/`unlock()` manually.
- Prefer message-passing / task-based designs (queues, futures, `std::async`) over shared mutable state where feasible.
- Use `std::atomic<T>` for lock-free simple shared counters/flags; don't hand-roll atomics with volatile.


## 8. Algorithms & Containers


- Prefer `<algorithm>` and `<ranges>` (C++20) over hand-written loops: `std::ranges::sort`, `std::ranges::find`, range-based pipelines with `|` views.
- Prefer range-based `for` loops over index-based loops unless the index itself is needed.
- Choose containers deliberately: `std::vector` by default, `std::array` for fixed-size stack data, `std::unordered_map`/`std::map` based on ordering needs, `std::deque` only when front/back growth is required.
- Reserve capacity (`.reserve()`) when the final size is known ahead of a loop that grows a container.


## 9. Formatting & Style


- Format with **clang-format**; commit a `.clang-format` file (LLVM or Google base style, project's choice) and never hand-format against it.
- Naming: pick one convention and apply it consistently (e.g. `snake_case` for variables/functions, `PascalCase` for types, `SCREAMING_SNAKE_CASE` for macros/constants). Match whatever the existing codebase already uses — don't introduce a second convention.
- Keep functions short and single-purpose; extract helpers rather than nesting deeply.
- Avoid macros for anything expressible as a `constexpr` function, template, or `enum class`. Reserve macros for conditional compilation and header guards only.


## 10. Tooling & Static Analysis


Run before considering any change complete:


- `clang-format` — formatting.
- `clang-tidy` — static analysis (enable at minimum: `bugprone-*`, `modernize-*`, `performance-*`, `cppcoreguidelines-*`).
- **Sanitizers** in debug/test builds: `-fsanitize=address,undefined` (ASan+UBSan) at minimum; TSan for concurrent code.
- Treat compiler warnings as errors in CI (`-Wall -Wextra -Wpedantic -Werror` on GCC/Clang, `/W4 /WX` on MSVC).
- Prefer CMake as the build system, with `FetchContent` or a package manager (vcpkg/Conan) for dependencies rather than vendoring or system-wide installs.


## 11. Testing


- Every new function/class with non-trivial logic gets a unit test.
- Use an established framework already in the project (GoogleTest, Catch2, doctest); don't introduce a second framework.
- Tests must be deterministic and independent — no shared mutable global state between tests.
- Prefer property-style/table-driven tests for functions with many input classes.


## 12. What to Avoid


- Raw `new`/`delete`, C-style arrays for dynamic data, C-style casts (`(int)x`) — use `static_cast`/`dynamic_cast`/`reinterpret_cast`/`const_cast` explicitly.
- `using namespace std;` at file/header scope.
- Output parameters as the primary way to return data.
- Deep inheritance hierarchies and multiple inheritance (except interface-only mixins).
- Global mutable state.
- Manual index math where an iterator, range, or `std::span` would do.
- Silent narrowing conversions — use `{}`-initialization, which errors on narrowing.


## 13. Commit Hygiene


- Keep commits scoped to one logical change.
- Run formatter + linter + tests before proposing a change as done.
- Document *why*, not *what*, in comments — the code should already say what it does.
Loading
Loading