perf(efficient_did): skip _ridge_solve_weights fancy-index copy when no row is zero-masked#639
Conversation
32dc1c2 to
15981b1
Compare
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment✅ Looks good — no unmitigated P0/P1 findings. Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
…no row is zero-masked When rest.size == n (the common case — no all-zero Omega* rows), the batched ridge solve consumes omega_stack directly instead of paying the O(n*H^2) omega_stack[rest] fancy-index copy, and returns the solved weights without the tail scatter through a preallocated uniform matrix. Value-identical on both backends: the Rust kernel takes a read-only borrow (PyReadonlyArray3) and adds the ridge in-kernel; the numpy chain builds its own om_ridged. Verified byte-identical function outputs on common and zero-masked stacks, bit-identical cond-10k end-to-end ATT; fit time 20.09s -> 19.99s median (memory-traffic cleanup). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
15981b1 to
d2389b1
Compare
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment✅ Looks good — no unmitigated P0/P1 findings. Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
Summary
_ridge_solve_weights(the batched Omega* ridge solve behind the conditional-path efficient weights): when no row of the stack is zero-masked (rest.size == n, the common case), consumeomega_stackdirectly instead of paying theO(n·H²)omega_stack[rest]fancy-index copy, and return the solved weights directly instead of scattering through a preallocated uniform matrix. Thezero_maskabs scan is retained (needed for correctness); mixed/all-zero stacks keep the prior arms verbatim.omis never mutated on either backend — the Rust kernel takes a read-only borrow (PyReadonlyArray3) and adds the ridge in-kernel; the numpy chain builds its ownom_ridged.TestRidgeSolveRustDispatch::test_zero_mask_arms_all_zero_mixed_nonelocks all three zero-mask arms (all-zero → uniform 1/H; mixed → zero rows uniform + solved rows byte-equal to a standalone sub-stack solve; no-zero fast path already locked byte-identical bytest_symbol_none_degrades_to_legacy_exactly).Methodology references (required if estimator / math changes)
(Omega* + λ·max(trace/H,0)·I)x = 1and backend dispatch as implementation choices)Validation
tests/test_efficient_did.py(new three-arm zero-mask test).tests/test_efficient_did.pyfull file passes on the Rust backend (202) and the ridge/tile subset underDIFF_DIFF_BACKEND=python; function-level byte-identity BEFORE vs AFTER on saved outputs; cond-10k end-to-end ATT bit-identical.Security / privacy
Generated with Claude Code