Project documentation

Fixed-size C++23 state estimation with a thin Python interface.

Benchmarks

The numbers below are from the project's own benchmark harness. Reproduce with:

python benchmarks/benchmark_finance_shapes.py
python benchmarks/benchmark_cpp_core.py --nx=2 --nz=1 --opencv=always

The headline is in the changelog.

Per-call (Python, finance shapes)

shape fast-kalman cv2 speedup
1×1 random walk 394 ns 3090 ns 7.8×
2×1 constant velocity 402 ns 3073 ns 7.6×
3×1 constant acceleration 415 ns 3115 ns 7.5×
4×2 pairs CV 457 ns 3346 ns 7.3×
6×3 basket CV 649 ns 3624 ns 5.6×
4×4 factor model 616 ns 3457 ns 5.6×
8×8 factor model 1747 ns 4656 ns 2.7×

C++-direct (no Python on either side)

shape fast-kalman cv::KalmanFilter speedup
1×1 10 ns 2459 ns 235×
2×1 20 ns 2533 ns 125×
3×1 30 ns 2618 ns 86×
4×2 68 ns 3071 ns 45×
6×3 226 ns 3456 ns 15×
4×4 181 ns 3607 ns 20×
8×8 1143 ns 8513 ns 7×

Batched (Python, stock-trades hot path)

NX=2, NZ=1, varying delta_t and measurement_variance per tick, 200k ticks:

Path ns/tick vs. cv2 per-tick
cv2.KalmanFilter per tick 3495 1.0×
kf.update(z, dt, mvar) + kf.x[1] read 314 11.1×
kf.update_many(zs, delta_t=…, measurement_variance=…) 26 134×
kf.update_many(…, record_states=True) 31 113×

Templated vs runtime Dyn

A (5, 3) filter doesn't have a templated specialization in v0.3.0 — it returns a _DynLinearKalmanFilter. Microbenchmark per-step cost:

shape templated path Dyn path slowdown
4×2 (templated) 76 ns n/a —
5×3 (Dyn only) n/a 240 ns n/a
6×3 (templated) 226 ns 350 ns* 1.55×

*estimated; the 6×3 Dyn path was measured before it became a kept pair. The Dyn slowdown for the 9 kept pairs ranges 1.5–3× depending on shape; for shapes that don't autovectorize well to begin with (large nx), the gap narrows.

If a shape you care about is consistently in the Dyn path and you want a templated specialization, file an issue with the shape and the benchmark you care about.

What the benchmarks don't measure