Skip to content

compact: reduce unmerged sums horizontally, like LLVM's SLP reductions - #33

Draft
Transurgeon wants to merge 7 commits into
scalar-perffrom
compact-reduction
Draft

Transurgeon wants to merge 7 commits into
scalar-perffrom
compact-reduction

Conversation

@Transurgeon

Copy link
Copy Markdown
Member

A term that merges with no other term may be a long chain of adds, e.g. an objective accumulated as f = f + term_k in a loop. Its operands are flattened (iteratively, so deep chains work), compacted and summed, and the result is kept only if the graph gets smaller.

20000-term loop objective: Problem build 32 s -> 5 ms, objective + gradient + Hessian 10.5 s -> 4 ms, same value.

Transurgeon and others added 7 commits November 8, 2026 17:02
A term that merges with no other term may be a long chain of adds, e.g.
an objective accumulated as f = f + term_k in a loop. Its operands are
flattened (iteratively, so deep chains work), compacted and summed, and
the result is kept only if the graph gets smaller.

20000-term loop objective: Problem build 32 s -> 5 ms, objective +
gradient + Hessian 10.5 s -> 4 ms, same value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rename insts -> instructions and lanes -> rows, and document compact and
its helpers with Parameters/Returns sections, following CVXPY.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
compact stacks scalar expressions into rows; it does not sum them, so
"term" was misleading. Rename UnsupportedTermError to match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Like an LLVM pass pipeline, Problem now runs compact on the objective
(merging a loop-built sum(terms)) and on each run of consecutive scalar
constraints. Merged rows are gathered back into the given order with one
index node, so constraint values, Jacobian rows and Lagrange multipliers
keep their order. test_vectorize_problems now builds the scalar problems
directly with Problem.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant