Skip to content

Sync headers from barry: fix support-vs-array index confusion in sampling - #9

Merged
gvegayon merged 2 commits into
mainfrom
fix/sample-support-index
Jul 16, 2026
Merged

gvegayon merged 2 commits into
mainfrom
fix/sample-support-index

Conversation

@gvegayon

Copy link
Copy Markdown
Member

Summary

Header sync of USCbiostats/barry#25 into inst/include/barry/.

keys2support maps a hash key to a support index, but the reuse branch of Model::sample(const Array_Type &, params) treated locator->second as an array index and mapped it through arrays2support a second time. The first time a conditioning state discovered mid-simulation is revisited, the sampler draws from an unrelated support. In the defm README "Example 2: A fun model" (a 10-state torus walk) the active state advances correctly through row 12 but collapses at row 13.

DEFM::simulate had the mirror-image bug: the first process of each individual was sampled with sample(arrays2support[model_num], par), passing a support index to an overload that expects an array index — giving wrong first-row draws for the 2nd+ individuals in a multi-individual simulation.

Fix

Both are keyed on the support index directly; the Array_Type overload now delegates probability computation to update_pset_probs, matching the existing sample(size_t, params) path.

Verification

  • inst/include/barry/model-meat.hpp and inst/include/barry/models/defm/defm-meat.hpp are now byte-identical to the fixed headers in barry#25.
  • barry's full test suite (including a new deterministic torus regression test) passes at 109 assertions in 21 test cases against these exact headers.
  • A standalone reproduction of the defm README Example 2 compiled against these headers now walks the torus past row 13.

The regression test itself lives in the barry repo (tests/), which is not vendored here.

🤖 Generated with Claude Code

…ling

Mirrors USCbiostats/barry#25. `keys2support` maps a hash key to a SUPPORT
index, but the reuse branch of Model::sample(const Array_Type &, params)
treated locator->second as an array index and mapped it through
arrays2support a second time; the first time a mid-simulation conditioning
state was revisited, the sampler drew from an unrelated support (e.g. the
defm "torus" example collapses at row 13). DEFM::simulate had the
mirror-image bug on the first process of each individual.

Both are keyed on the support index directly; the Array overload now
delegates to update_pset_probs, matching the sample(size_t, params) path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

Thank you for your contribution @gvegayon 🚀! The pkgdown site preview is ready for review 👉 Download here 👈!
(The artifact expires on 2026-10-13T23:48:32Z. You can re-generate it by re-running the workflow here.)

Syncs the follow-up from USCbiostats/barry#25: add a pset_probs.empty()
check to the update guard, matching sample(size_t, params). init() adds
arrays without sizing pset_probs and a prior likelihood() call sets
first_calc_done/params_last without filling it, so the cache guard alone
could index into an empty buffer. Header stays byte-identical to barry.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gvegayon
gvegayon merged commit 8ff646b into main Jul 16, 2026
12 checks passed
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