refactor(ggm): share active<->full index traversal via for_each_active_full_pair#139
Merged
Merged
Conversation
…e_full_pair get_full_vectorized_parameters (scatter active theta -> full zero-padded vector) and get_active_inv_mass (gather full-dim inverse mass -> active layout) open-coded the same per-column index arithmetic in inverse directions. Add GraphConstraintStructure::for_each_active_full_pair(fn), which visits each active entry as (active_index, full_index); the scatter and gather become one-line lambdas over it. Behavior-preserving: identical (active,full) index pairs in identical order; the assignments are unchanged. Verified bitwise: NUTS GGM fits with mass adaptation (edge-selection exercising included_indices, and no-edge) digest-identical pre/post.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #139 +/- ##
==========================================
+ Coverage 87.71% 87.73% +0.01%
==========================================
Files 87 87
Lines 12867 12861 -6
==========================================
- Hits 11286 11283 -3
+ Misses 1581 1578 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What
get_full_vectorized_parameters(scatters active theta into the full zero-padded vector) andget_active_inv_mass(gathers the full-dim inverse mass back into the active layout) open-coded the same per-column index arithmetic in inverse directions — the sametheta_offsets/full_theta_offsets/included_indices/psi_offset/full_psi_offsetwalk, written twice.Adds
GraphConstraintStructure::for_each_active_full_pair(fn), which visits each active entry once as(active_index, full_index)— the d_q free off-diagonal entries then psi_q, per column. The scatter and gather are now one-line lambdas over it:The two are now provably exact inverses (same index pairs), which the old duplicated loops only implied.
Why this is safe
Identical
(active, full)index pairs in identical order; the assignments are unchanged.psi_offset(q) == theta_offsets[q] + d_q, so the helper's psi pair matches the old scatter'stheta_(active_offset + col.d_q).Verified bitwise:
update_method="nuts"GGM fits with diagonal mass adaptation (which is what exercises these two functions — scatter feeds Welford during warmup, gather returns the adapted mass), edge-selection (sparse active dim, exercisesincluded_indices) and no-edge.identical(main, branch) == TRUE. Harness:dev/bitwise_ggm_nuts.R.