Skip to content

perf: windowed numba fast path for the kernel-CDF forward transform - #458

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/kernel-cdf-numba-fast-path
Aug 21, 2026
Merged

perf: windowed numba fast path for the kernel-CDF forward transform#458
Jammy2211 merged 1 commit into
mainfrom
feature/kernel-cdf-numba-fast-path

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Closes #457.

What

The RectangularAdaptDensity kernel-CDF forward transform dominates the numba CPU likelihood on the default Rectangular route — 1.66 s = 55% of a euclid eval, 27 s = 89% at hst (PyAutoLabs/autolens_profiling#151): an O(M×N) blocked erf broadcast with ~126 MB per-block temporaries, rebuilt every evaluation (the traced grid moves with the mass model, so nothing can be memoized across evals).

One file of source change (inversion/mesh/interpolator/rectangular.py): the numpy branch of F_raw now evaluates each dimension's weighted kernel CDF with a numba kernel (_kernel_cdf_dim_windowed) over sorted points + weight prefix sums, using a ±9-bandwidth saturation window — points below the window contribute exactly their weight via the prefix sum, points above contribute zero, and only the window is summed with erfc. Dropped tail terms are < 1e-19 of the weight sum, so values match the exact blocked sum to ~1e-13 (fp accumulation noise).

Differentiability guarantee preserved: the module's "no sorts anywhere" invariant is a JAX-gradient property; the sort here is internal evaluation order on the gradient-free xp is np branch only, and the blocked numpy implementation remains the JAX branch and the differentiable reference.

Results (4-core cloud container)

Testing

  • New: two dense-reference equivalence tests in test_autoarray/inversion/pixelization/interpolator/test_rectangular.py (weighted + unweighted, atol 1e-12, with out-of-box queries exercising the saturated tails).
  • All 10 existing interpolator property tests (monotonicity, unit-square mapping, etc.) pass unchanged on the new path; test_autoarray/ 1036 passed, 51 skipped; only the 3 pynufft transformer tests that fail identically on stock main in this environment.

Downstream

No public API change; JAX path untouched; interferometer and all other meshes untouched. Likelihood values shift at the ~1e-13 level (below the solver's own bistability).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vcc7MUBMnNU6n8qqS9ioVZ


Generated by Claude Code

…numpy branch)

The RectangularAdaptDensity kernel-CDF forward transform dominates the numba
CPU likelihood (euclid 1.66 s = 55% of the eval; hst 27 s = 89%): an
O(M x N) blocked erf broadcast with ~126 MB per-block temporaries, rebuilt
every evaluation. The numpy branch of F_raw now evaluates each dimension's
weighted kernel CDF with a numba kernel over sorted points + weight prefix
sums and a +-9-bandwidth saturation window — same values to ~1e-13 (dropped
tail terms < 1e-19 of the weight sum), 3.0-3.4x on the step.

The blocked numpy implementation remains the JAX branch and the
differentiable reference; the sort is internal evaluation order on the
gradient-free numpy path only, preserving the module's no-sorts
differentiability guarantee where it matters.

Validated: autolens_profiling pixelization_numba pins PASS at euclid + hst
(euclid eval 3.08 -> 1.17 s, hst ~30 -> 10.1 s on a 4-core container,
stacked with the merged #453/#455 wins); test_autoarray 1036 passed
(+2 new dense-reference equivalence tests, weighted and unweighted, with
out-of-range queries exercising the saturated tails).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vcc7MUBMnNU6n8qqS9ioVZ
@Jammy2211
Jammy2211 merged commit 25da365 into main Aug 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: windowed numba fast path for the RectangularAdaptDensity kernel-CDF transform

2 participants