Uh oh!
There was an error while loading. Please reload this page.
perf(reg_flow): route bending==0 Lamé calls to matvec_lame/diag_lame - #52
perf(reg_flow): route bending==0 Lamé calls to matvec_lame/diag_lame#52balbasty wants to merge 1 commit into
Conversation
…51) _flow_matvec / _flow_matvec_acc / _flow_diag unconditionally selected the full combined matvec_all / diag_all stencil whenever shears or div were non-zero, even when bending == 0 -- leaving the cheaper Lamé-only matvec_lame / diag_lame stencils (already exercised via relax_lame_) unreachable from the public dispatch. _flow_kernel and _flow_relax already branch correctly on bending != 0; this mirrors that exact nesting into the remaining three, so an elastic-only (non-bending) registration configuration -- a common use case -- uses the ~9-tap Lamé stencil instead of the ~25-tap combined one. Pure performance change: the two stencils are mathematically identical when bending == 0, and the full test suite's output is byte-identical before and after (verified against a pristine kernels checkout so the comparison isolates this change). Closes#51 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015xcQBMEdA5eQtTsx2wB3AC
balbasty
commented
Aug 18, 2026
Closing this — not because the analysis was wrong. It wasn't: I re-derived the change independently and this PR's reasoning holds up, including the part that went beyond the issue. Why it's being closedThis PR comes from the The analysis was sound — credit where it's dueVerified independently:
I also confirmed the "no numerical change" claim from the kernel builders rather than from the test suite alone: at Where the change actually landedOn Verification there: the full suite report is byte-identical before and after (37/37 lines, 13/13 suites, 0 failures), which is what a pure routing change must produce. Note on #51#51 is already closed — auto-closed on 2026-08-05 by the unrelated merged PR #82, which referenced it. The defect was nevertheless still live on Nothing stranded
Generated by Claude Code |
Agent: claude-fastfields-to-teeny
Closes#51
The bug
_flow_matvec/_flow_diaginreg_flow.cpprouted any non-zeroshears/divstraight to the full combinedmatvec_all/diag_allstencil, with nobending != 0guard:That leaves the cheaper Lamé-only
matvec_lame/diag_lamestencils — which exist in the impl and are already exercised viarelax_lame_— unreachable from the public dispatch._flow_kerneland_flow_relaxin the same file already branch correctly:This PR mirrors that exact nesting into the remaining dispatch functions. Elastic-only (non-bending) registration — a common configuration — now pays a ~9-tap stencil per voxel per channel instead of ~25-tap.
Sites fixed — three, one more than the issue predicted
main_flow_matvec_flow_diag_flow_matvec_acc_flow_kernel,_flow_relax_flow_matvec_rls,_flow_diag_rls,_flow_relax_rls*_lame_jrls/*_membrane_jrlsexist at the impl layer (no bending-aware JRLS kernel), andbendingis rejected by the public wrapper before dispatch_flow_matvec_acc(theout += L(inp)/out -= L(inp)accumulate variant, added tomainby task #53 after the reference fix onclaude/fastfields-teeny-refactor-js42idwas written) is a verbatim copy of_flow_matvec's dispatch withopin place of'=', and carried the identical bug. Fixing only the two functions the issue names would have left the accumulate path on the expensive stencil for no reason, so it is fixed here too — same two-line change, same commit theme.This is a re-application, not a cherry-pick of
8afcab4(ex-PR #39):main's dispatch functions now thread aconst bound::BoundVec & bvecfirst argument through to every impl call.Verification
make test CXX=clang++. To isolate this change, both runs used a pristinefastfields-kernelscheckout atmain's pinned commit15295c2(i.e. without thediag_bendingcorner-term fix in kernels #49, which I am proposing in parallel).Full test-suite stdout is byte-identical before and after (
diff= empty) — all 12 binaries PASS, 0 failures, identical check counts:As expected for a pure performance fix — the two stencils are mathematically identical when
bending == 0.Coverage of the newly-reachable path is real, not incidental.
test_reg_flowalready runs severalbending == 0, shears/div != 0cases:run_2d_lame_symmetry/run_3d_lame_symmetry(DCT2, DFT, DST2, Zero) — now throughmatvec_lamerun_2d_lame_diag(bending = 0,shears = 1.2,div = 0.8) — now throughdiag_lamerun_2d_matvec_addsub(..., bending = 0.0, shears = 1.3, div = 0.7, ...)— covers the_flow_matvec_accchange withop = '+'/'-'run_2d_kernel_impulsewithbending = 0— the strongest check: it validatesflow_matvecagainst the materialisedflow_kernelstencil, and_flow_kernelwas already onkernel_lameforbending == 0. So this test previously cross-checkedmatvec_allagainstkernel_lame, and now cross-checksmatvec_lameagainstkernel_lame— independent confirmation that the two agree.Note on the concurrent PR #50
#50 (
claude-jitfields-to-fastfieldsworkstream) is still open and unmerged at the time of writing, and it templates_flow_diag/_flow_kernelonchar op. That touches the same function signatures but not theif (shears...)/if (bending...)branch structure this PR changes, so the two are logically independent — expect at most a small textual conflict in_flow_diag's body, resolved by keeping both changes (char opin the template args, nestedbendingbranch in the body). I based this branch onorigin/main(6aaa159) and have not touched #50 or its branch.Generated by Claude Code