FrankenNumPy

Docs/Architecture

Architecture

           ┌──────────────────────────────────────────────┐
           │              User API Layer                  │
           │   UFuncArray · MaskedArray · StringArray     │
           │ (datetime / timedelta = UFuncArray + DType)  │
           └───────────────────────┬──────────────────────┘
                                   │
       ┌───────────┬───────────────┼──────────────┬───────────┐
       ▼           ▼               ▼              ▼           ▼
  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
  │ fnp-ufunc│ │fnp-linalg│ │fnp-random│ │  fnp-io  │ │fnp-python│
  │ array ops│ │ linalg   │ │ RNG      │ │ NPY/NPZ  │ │ PyO3     │
  │ + FFT    │ │ kernels  │ │ engine   │ │ + text   │ │ bindings │
  └─────┬────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘
        │
  ┌─────┴────────────────────────────────────────────────────┐
  │                                                          │
  ▼                                                          ▼
  ┌──────────┐ ┌────────────┐ ┌──────────┐ ┌──────────────┐
  │ fnp-dtype│ │ fnp-ndarray│ │ fnp-iter │ │ fnp-runtime  │
  │ dtype    │ │ SCE core   │ │ transfer │ │ strict/      │
  │ rules    │ │ strides    │ │ semantics│ │ hardened     │
  └──────────┘ └────────────┘ └──────────┘ └──────────────┘
                     ▲                            ▲
                     │                            │
       Stride Calculus Engine (SCE)        Evidence Ledger
       - shape → strides (C/F)             + Decision Engine
       - broadcast legality                + Override Audit
       - reshape with -1 inference
       - alias-safe view transitions

(The only first-class user-facing array struct types in fnp-ufunc are UFuncArray, MaskedArray, and StringArray. Datetime and timedelta arrays are not separate struct types; they are UFuncArray instances with DType::DateTime64 or DType::TimeDelta64 and ArrayStorage::I64 backing, with the unit (ns, us, ms, s, min, h, D, W, M, Y) carried on the dtype via DateTimeUnit.)

fnp-python sits above the canonical chain as the Python-facing surface; it does not alter the layering below it. Facts about that layering that the diagram does not show (verified 2026-09-23):

  • Two engines. The Python hot paths do not flow through UFuncArray or the SCE. fnp-python reads numpy buffers as typed zero-copy slices and computes in its own kernels (it calls SCE functions at 12 sites in ~202k lines, 2026-10-08), so there is the Rust-API engine described above and a separate Python kernel layer.
  • NumPy underneath. fnp_python works on NumPy's own ndarray (it requires numpy and returns numpy.ndarray), and calls NumPy for every case its native kernels do not cover: 660 cached_numpy(py) call sites (2026-10-08), including 17 of the 18 numpy.fft functions, the 2-D linalg decompositions and solvers, and every numpy.polynomial function except the six series evaluators and the six least-squares fits (see the Submodule Coverage Matrix).
  • Runtime modes. fnp_python.set_runtime_mode / get_runtime_mode (and the FNP_RUNTIME_MODE environment variable, which fails the import on an unknown value) select strict or hardened mode, and get_runtime_decisions exports a bounded decision ledger. Hardened mode changes behaviour at four surfaces so far: the linalg decompositions and solvers reject inf/NaN operands with LinAlgError (ledger row DIV-HARDENED-LINALG-NONFINITE); the shape- and count-driven creation routines (zeros, empty, full, arange, linspace, eye, repeat, tile, ...) refuse one array larger than an admission cap - 4 GiB by default, FNP_HARDENED_MAX_ARRAY_BYTES to change it - with MemoryError before allocating (DIV-HARDENED-ADMISSION-CAP); load checks every source (path or file-like, .npy or .npz) against the fnp-io bounds - header <= 65,536 bytes, rank <= 32, no element-count overflow, payload as long as declared where the length is known, .npz <= 4,096 members and <= 2 GiB decoded, ZIP structure and CRC checks - and refuses a violation with ValueError before NumPy sees the bytes (DIV-HARDENED-LOAD-BOUNDS); and SeedSequence.spawn refuses more than 4096 children per call (DIV-HARDENED-SPAWN-BUDGET), which strict mode spawns as NumPy does. The byte-order, clip, nan_to_num and float-error sites record only (bead deadlock-audit-rc0923-epic-71qy3.10).
  • Two-tier architecture (decided 2026-10-17, bead deadlock-audit-rc0923-epic-71qy3.11, docs/adr/ADR-001-parity-pivot.md). The 10 core Rust crates are a standalone, clean-room reimplementation of NumPy's array engine (#![forbid(unsafe_code)], zero Python/C dependencies); fnp_python in Phase A is a drop-in Rust accelerator over numpy.ndarray (plus the FnpArray zero-copy subclass), while Phase B (deadlock-audit-8yzeh) tracks a standalone PEP 3118 PyNdArray object without a runtime numpy dependency.

fnp-conformance is the perpendicular axis. It consumes every crate, captures NumPy oracle output, runs differential / metamorphic / adversarial / witness suites, generates RaptorQ artifacts, and exposes 48 dedicated binaries under crates/fnp-conformance/src/bin/ that drive the CI gates.


This section in the README on GitHub