Docs/Evidence
Conformance Methodology Deep-Dive
On this page 6 sections
The "verify with a real NumPy oracle" claim deserves to be unpacked. The conformance system has four orthogonal layers that catch different classes of bug. They are independent: a bug that slips one layer is almost always caught by another.
1. Differential testing
The most direct check: for a fixture input, run the same operation under both NumPy and FrankenNumPy, then compare the outputs.
capture_numpy_oracle: fixture → NumPy → oracle_outputs.json
run_ufunc_differential: fixture → FrankenNumPy → fnp_outputs.json
comparator → parity_report.json
The comparator is tiered: it first compares shapes, then dtypes, then values. Value comparison uses a per-test relative tolerance (default 1e-12 for f64, 1e-6 for f32) but accepts bit-exact equality when both implementations produce identical floats. The same skeleton powers run_ufunc_differential, the linalg/FFT/polynomial/string/masked/datetime/RNG/IO differential binaries, and the per-function shards under crates/fnp-python/tests/conformance_*.rs. The IO subsystem additionally ships two dedicated cross-engine tests: crates/fnp-io/tests/npy_numpy_conformance.rs (round-trips arrays through numpy.save/numpy.load then through fnp-io and verifies byte equality across load, load_auto, load_complex, load_npz, read_npy_bytes, savez, savez_compressed) and crates/fnp-io/tests/npy_npz_diagnostic.rs (diagnostic-oracle parity for the hardened-bound validators: validate_header_schema, validate_magic_version, validate_memmap_contract, validate_npz_archive_budget, validate_read_payload, validate_write_contract).
Why this catches bugs: it surfaces any case where a function returns the wrong number, the wrong shape, or the wrong dtype, even when the function "looks right" on inspection.
Why it isn't sufficient on its own: a bug that exactly matches a corresponding bug in NumPy will pass differentially. Hence layers 2–4.
2. Metamorphic testing
Verifies algebraic identities that must hold regardless of input. These don't depend on an oracle at all; they catch bugs that an oracle test couldn't, because they probe relationships, not values.
The metamorphic suite is consistent across the workspace: every numeric crate ships a tests/metamorphic_<area>.rs file — fnp-dtype/tests/metamorphic_dtype.rs, fnp-ndarray/tests/metamorphic_shapes.rs, fnp-iter/tests/metamorphic_iter.rs, fnp-ufunc/tests/metamorphic_math.rs, fnp-linalg/tests/metamorphic_linalg.rs, fnp-random/tests/metamorphic_rng.rs, fnp-io/tests/metamorphic_io.rs, and fnp-python/tests/metamorphic_array_ops.rs — eight files, one per area, plus the cross-cutting identities under crates/fnp-conformance/src/metamorphic_*.
Representative identities:
| Identity | What it catches |
|---|---|
a + b == b + a (elementwise) |
Asymmetric implementation of commutative ops |
a * 1 == a |
Multiplicative-identity bugs in dispatch |
sum(a) == sum(sort(a)) |
Order-dependent accumulator bugs |
sum(a) + sum(b) ≈ sum(concat(a, b)) |
Reduction kernel reset/restart bugs |
transpose(transpose(a)) == a |
View / stride inversion errors |
inv(inv(a)) ≈ a for well-conditioned a |
Numerical regression in matrix inversion |
fft(ifft(x)) ≈ x and ifft(fft(x)) ≈ x |
Inverse-transform symmetry breakage |
cumsum(a)[-1] == sum(a) |
Cumulative reduction vs total reduction drift |
sort(a)[::-1] == sort(a, descending) |
Sort-order parameter bugs |
concat(split(a, n)) == a |
Round-trip bugs in split/concat |
cholesky(a).T @ cholesky(a) ≈ a for SPD a |
Triangular factor orientation errors |
det(a) * det(b) ≈ det(a @ b) |
Determinant computation drift |
eig(a) values == roots of det(a - λI) (small a) |
Eigenvalue solver convergence regressions |
3. Adversarial testing
Hostile inputs designed to provoke crashes, panics, or silent corruption. Two complementary mechanisms:
Curated adversarial fixtures. Hand-authored corner cases stored under crates/fnp-*/tests/fixtures/adversarial/: NaN-filled arrays, ±Inf inputs, denormals at the transition boundary, very large shapes (close to usize::MAX), zero-element axes, single-element axes, broadcast shapes that align to the right margin, malformed .npy headers (truncated magic, future version, oversized header dict), corrupt ZIP EOCD records.
Coverage-guided fuzzing. 8 fuzz crates, 42 targets, 561 curated seed corpus files (see docs/FUZZING.md). cargo-fuzz / libFuzzer drives:
fnp-io:.npy/.npz/fromstring/loadtxtparsersfnp-ndarray:broadcast_shape,fix_unknown_dim,as_strided,sliding_window_viewfnp-iter:ndindex,flatiter_indices,nditer_plan,transfer_classfnp-dtype:dtype_parse,can_cast,result_type,min_scalar_typefnp-ufunc:parse_gufunc_signature,parse_fixed_signature,datetime_unit_parsefnp-random: seed entropy edge cases (from_u64_seed,seed_sequence)fnp-linalg:cholesky_nxn,det_nxn,qr_mxnover arbitrary matrices up to 16–32 dim
Crash discipline. A fuzz crash never becomes a "fix and move on" event. It becomes (a) a permanent seed file in the corpus so the case is regression-tested forever, (b) a parity_debt row in docs/DIVERGENCES.md if it exposes a NumPy-compatibility gap, or (c) a closed bead with a commit pointer if it is a straight bug fix.
4. Witness stability
Hard-coded "expected output" values for every RNG distribution and every algorithmic kernel. These pin the exact output sequence so that an unintended algorithmic change is caught immediately rather than silently shifting downstream pipelines.
Example: the standard_normal(5) witness for PCG64DXSM(12345) is the exact 5-element float vector that NumPy produces from the same seed. When we intentionally change an algorithm (e.g. the 2026-03-15 BTPE binomial port), the witness values are regenerated from the new implementation and the diff is reviewed in the same commit. That diff is itself an artifact: the old vs new witness arrays appear in the commit, so any future drift is obvious.
These witness arrays live in golden_*.rs files across the workspace: fnp-dtype/tests/golden_dtype.rs, fnp-ndarray/tests/golden_layout.rs, fnp-iter/tests/golden_iter.rs, fnp-ufunc/tests/golden_histogram.rs + fnp-ufunc/tests/public_api_golden.rs, fnp-linalg/tests/golden_linalg.rs, fnp-random/tests/golden_rng.rs, fnp-io/tests/golden_text_io.rs, fnp-python/tests/golden_native_functions.rs, fnp-runtime/tests/golden_runtime.rs — ten files, one per non-conformance crate (fnp-ufunc carries two: per-domain histogram witnesses and a separate public-API golden).
Alongside the structural suites (metamorphic / golden / conformance / e2e), each crate also keeps targeted regression test files for specific bugs found and fixed in the past — e.g. fnp-ufunc/tests/isclose_bugs.rs (isclose edge cases), test_nansum_empty.rs (nansum on empty arrays), test_nat.rs (NaT handling), test_strided.rs (strided iteration). These don't follow the <pattern>_<area>.rs naming because they're not pattern instances — they're permanent regression guards.
Shared harness for fnp-python conformance shards
The 194 conformance_*.rs shards under crates/fnp-python/tests/ are powered by a single ~28 KB shared helper at crates/fnp-python/tests/common/mod.rs. The harness declares each test case with a RequirementLevel (Must, Should, and May all fail the suite via assert_suite_passes unless explicitly marked CaseOutcome::ExpectedFail) and a comparison mode (Strict for int/bool/dtype/shape exactness, Close for tight rtol = 1e-12, atol = 1e-12 float array comparison, Surface for tuple / scalar / structured-dtype parity, Error for raise-alignment tests). Known divergences flip to XFAIL via CaseOutcome::ExpectedFail. The output is a JSON-line verdict stream plus a per-RequirementLevel markdown summary — that's what makes the shard surface compliance-matrix machine-readable (hardened in bead deadlock-audit-rc0923-epic-71qy3.17). The other 9 crates don't have a tests/common/ helper because their integration-test files are few enough (2–9 per crate) and varied enough that shared scaffolding isn't worth the indirection cost — each metamorphic_*.rs / golden_*.rs file is self-contained.
How the four layers compose
┌───── differential (oracle equal) ──── (1)
│
fixture / input ─────┼───── metamorphic (identity holds) ──── (2)
│
├───── adversarial (no crash/UB) ──── (3)
│
└───── witness (exact output bits) ─── (4)
A bug that lives in NumPy too will pass (1) but fail (2). A bug that produces a different-but-plausible value will fail (1). A bug that crashes will fail (3). A bug that silently shifts an RNG stream will fail (4). The orthogonality is the point.
On top of these four layers, crates/fnp-python/tests/e2e_workflow.rs exercises multi-function pipelines — chains of operations that should compose correctly together (load → reshape → reduce → save, RNG-backed Monte-Carlo loops, FFT round-trips with intermediate masking, etc.). The single-op layers can pass while a pipeline still produces wrong results from accumulated rounding, view aliasing, or dtype-promotion interactions; the e2e tests catch those compositional bugs.