Slice the system operator to the active set once per outer step (fixes #72)#73
Merged
Conversation
The operator adoption (#71) built full-universe operators and called apply_free(active_idx, v) inside the CG matvec, which re-gathers the columns of X (and the target blocks) on every iteration: ~10 MB of memcpy per iteration against ~50 us of useful GEMV, an ~8x wall-clock regression at identical iteration counts (16x without shrinkage). _system_operator now takes the active mask and builds the SumOperator on pre-sliced contiguous factors (X[:, active], U_k[active, :], the dense target block), restoring the pre-#71 hoisting; the per-iteration matvec is a plain operator product. Fixes #72. Benchmark (S&P 500, n=494, T=1213, LW alpha=0.5, best of 3): before 0.0475 s / 82 iters after 0.0063 s / 83 iters parent of #71: 0.0058 s / 82 iters Full suite: 379 passed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR restores pre-#71 performance for CG/PCG inner solves by hoisting active-set slicing out of the per-iteration matvec and into a once-per-outer-step _system_operator(active) construction, so CG iterations run on pre-sliced contiguous factors.
Changes:
- Change
_system_operatorto accept the active mask and build operators over pre-slicedX[:, active]/ target blocks once per outer step. - Update
_cg_stepand_pcg_stepto usesigma.matvec(v)directly (removingapply_free(active_idx, v)from the CG loop). - Expand
_system_operatordocstring to document the performance motivation for hoisting slicing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+210
to
+211
| Nothing is formed at ``n_a x n_a``; without a target the data term | ||
| carries the full weight. |
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.
Summary
#71 moved the active-set restriction inside the CG matvec: full-universe operators plus `apply_free(active_idx, v)` per iteration re-gather `X[:, active]` on every iteration (two fancy-indexed copies of the 1213x494 data per matvec). Iteration counts were unchanged, wall clock regressed ~8x with shrinkage and ~16x without (Jebel-Quant/mean_variance_solvers benchmarks; see #72).
This PR keeps the cvx-linalg operator design but restores the pre-#71 hoisting: `_system_operator(active)` builds the `SumOperator` on pre-sliced contiguous factors once per outer step, and the matvec is a plain `sigma.matvec(v)`.
Notes
🤖 Generated with Claude Code