Collapse quadratic forms to a single triangular solve - #2373
Open
jessegrabowski wants to merge 2 commits into
Open
Collapse quadratic forms to a single triangular solve#2373jessegrabowski wants to merge 2 commits into
jessegrabowski wants to merge 2 commits into
Conversation
jessegrabowski
force-pushed
the
quadratic-form-single-solve
branch
from
August 26, 2026 01:17
5d33e7c to
477ab59
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Computing
b.T @ K^-1 @ bappliesK^-1with a forward and a back substitution, and then the surrounding dot contracts the result straight back to a scalar. WritingK = C C.T, the same quantity is||C^-1 b||^2, so one substitution does. The rewrite catchescho_solveand also a hand-written pair of transposed triangular solves, whose factor doesn't have to come from a Cholesky; the square-root Kalman filter gets its factor out of a QR.The first commit lifts the
b_ndim=2gate onpsd_solve_to_chol_solveso a positive-definite solve with a vector right-hand side reaches the same chain instead of staying one opaqueposvcall.The two benchmarks differ in whether the triangular factor is already available. In
given_factorit is, and dropping one substitution roughly halves the time. Inwith_choleskythe factorization is redone on every call, so itsO(n^3)cost dominates a single quadratic form and the saving shrinks to 6-8%, which is within one standard deviation except at n=3000.