Skip to content

hstack: form the Hessian with sum_n_matrices - #161

Merged
dance858 merged 1 commit into
mainfrom
hstack-fill-add
Oct 13, 2026
Merged

dance858 merged 1 commit into
mainfrom
hstack-fill-add

Conversation

@dance858

Copy link
Copy Markdown
Collaborator

Summary

  • hstack's Hessian is the sum of its children's Hessians. The pattern now comes from sum_n_matrices_alloc. Values are filled with sum_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.
  • This replaces the running sum_csr_alloc / sum_csr_fill_values over a CSR_work copy. 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 a child_hess pointer array instead.
  • hstack was the last engine caller of sum_csr_*, so a library follow-up can make them private.

No pin bump: main already pins cba21ac.

Tests

  • New 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.
  • All 302 tests pass in Debug and Release.

🤖 Generated with Claude Code

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>
@dance858
dance858 merged commit ec584e4 into main Oct 13, 2026
14 checks passed
@dance858
dance858 deleted the hstack-fill-add branch October 15, 2026 05:39
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