Repository navigation
hstack: form the Hessian with sum_n_matrices - #161
Merged
Merged
Conversation
The Hessian is the sum of the children's Hessians. Build its pattern with sum_n_matrices_alloc and fill it with sum_n_matrices_fill_zero / fill_add, adding each child right after it is evaluated (args may share a subexpression). This replaces the running sum_csr_alloc / sum_csr_fill_values over a CSR_work copy, so eval is one scatter per child instead of a copy and merge of the whole Hessian per child. hstack was the last engine caller of sum_csr_*. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
sum_n_matrices_alloc. Values are filled withsum_n_matrices_fill_zero/sum_n_matrices_fill_add, adding each child's Hessian right after that child is evaluated. That keeps hstack correct when args share a subexpression, as it already was.sum_csr_alloc/sum_csr_fill_valuesover aCSR_workcopy. Each eval is now one scatter per child, instead of a copy and merge of the whole Hessian per child.CSR_work, the copy loops and the trims are gone; the struct holds achild_hesspointer array instead.sum_csr_*, so a library follow-up can make them private.No pin bump: main already pins
cba21ac.Tests
test_wsum_hess_hstack_shared_arg:hstack([log x, log x])with the same node in both slots, checked against explicit values. The version that evaluated all children and then summed fails it (-8 vs -5). This one passes, as did the old code.🤖 Generated with Claude Code