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
UFuncArrayor the SCE.fnp-pythonreads 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_pythonworks on NumPy's ownndarray(it requires numpy and returnsnumpy.ndarray), and calls NumPy for every case its native kernels do not cover: 660cached_numpy(py)call sites (2026-10-08), including 17 of the 18numpy.fftfunctions, the 2-Dlinalgdecompositions and solvers, and everynumpy.polynomialfunction 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 theFNP_RUNTIME_MODEenvironment variable, which fails the import on an unknown value) select strict or hardened mode, andget_runtime_decisionsexports a bounded decision ledger. Hardened mode changes behaviour at four surfaces so far: thelinalgdecompositions and solvers reject inf/NaN operands withLinAlgError(ledger rowDIV-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_BYTESto change it - withMemoryErrorbefore allocating (DIV-HARDENED-ADMISSION-CAP);loadchecks every source (path or file-like,.npyor.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 withValueErrorbefore NumPy sees the bytes (DIV-HARDENED-LOAD-BOUNDS); andSeedSequence.spawnrefuses more than 4096 children per call (DIV-HARDENED-SPAWN-BUDGET), which strict mode spawns as NumPy does. The byte-order,clip,nan_to_numand float-error sites record only (beaddeadlock-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_pythonin Phase A is a drop-in Rust accelerator overnumpy.ndarray(plus theFnpArrayzero-copy subclass), while Phase B (deadlock-audit-8yzeh) tracks a standalone PEP 3118PyNdArrayobject without a runtimenumpydependency.
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.