Repository navigation
Stack constraint and hstack Jacobians with vstack_matrices_* - #165
Merged
Merged
Conversation
- problem.c: the global constraint Jacobian is a vstack of the constraint Jacobians (jac_stack over jac_ops); prob->jacobian becomes its CSR view. The fill copies only constraints whose values_version changed, which replaces constraint_jac_seen and both hand-written to_csr loops. With no constraints, jac_stack is an empty 0 x n_vars sparse matrix. - hstack.c: the Jacobian is a vstack of the children's Jacobians (child_jac), so unchanged children are no longer recopied on each eval. - Both read each operand's own storage: a stacked_pd Jacobian is copied once per change instead of twice through a to_csr view, and no CSR cache is created for it. - left_matmul: drop Jchild_CSC / J_CSC / csc_to_csr_work and the kron-only workspace, dead since the kron branch moved to BA_sparse_kron_matrices_*. subexpr.h no longer needs CSC_matrix.h. - New test test_jacobian_hstack_stacked_pd_child: hstack with a stacked_pd child, checked against finite differences at two points (refill). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dance858
force-pushed
the
linalg-vstack-adoption
branch
from
October 13, 2026 14:20
5234565 to
575ff78
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.
Stacked on #164. Its base is
bump-linalg-v0.5.0; retarget it tomainonce #164 merges.Summary
This PR adopts the library's
vstack_matrices_*(sparsediff_linalg #25) and finishes theleft_matmulcleanup from #27.problem.c: the constraint Jacobian is nowjac_stack = vstack_matrices_alloc(jac_ops, n_constraints), andprob->jacobianis its CSR view, so SparseDiffPy andjacobian_cooare unchanged.problem_jacobianevaluates the constraints and callsvstack_matrices_fill_values, which copies only the Jacobians whosevalues_versionchanged. This replacesconstraint_jac_seenand both hand-writtento_csrloops. With no constraints,jac_stackis an empty 0 × n_vars sparse matrix, because vstack needs at least one operand.hstack.c: the Jacobian is a vstack of the children's Jacobians (new fieldchild_jac), so children whose values didn't change are no longer recopied on every eval.left_matmul: removesJchild_CSC,J_CSC,csc_to_csr_workand the kron-only workspace. All of them have been dead since the kron branch moved toBA_sparse_kron_matrices_*.subexpr.hno longer includesCSC_matrix.h.Testing
test_jacobian_hstack_stacked_pd_childbuilds hstack(A @ exp(X), sin(X)). The left_matmul child's Jacobian is a stacked_pd, and the test checks the result against finite differences at two points, so the refill is exercised.test_problem_jacobian_memcpy_skipstill passes. It writes into the affine slice directly and checks that it isn't recopied.test_problem_jacobian_spd_constraint_interleaved.PROFILE_ONLY=ONbuilds, the warnings are the same 5 as onmain, and clang-format is clean.scopefixture that isn't defined anywhere in the repo.🤖 Generated with Claude Code