Inline convolution index bookkeeping in Stan hot path#1404
Conversation
Co-authored-by: Codex <noreply@openai.com>
WalkthroughThe PR refactors ChangesConvolution index inlining
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if abe5767 is merged into main:
|
Co-authored-by: Codex <noreply@openai.com>
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 7859a14 is merged into main:
|
Description
This PR follows #1273 with a focused cleanup in
convolve_with_rev_pmf().The convolution loop previously called small helper functions on every output element to build a temporary 4-integer index array before taking each dot product. This change keeps the convolution logic the same but computes those loop-local indices directly where they are used, avoiding repeated helper-call and temporary-array overhead inside the hot loop.
Benchmarks
I benchmarked the change locally with paired CmdStan runs on the package's infection-estimation workflow (
example_confirmed[1:60], fixed generation time, standard incubation/reporting delays, 2 chains, 250 warmup + 250 sampling draws, seeds 101/202/303/404, order balanced across baseline and branch runs).reportsStan profile blockThe
reportsprofile block improved in all four paired runs (-25.78%to-53.59%). Total runtime was directionally slightly lower on average but noisy across seeds, so I view the main result here as a targeted reduction in convolution hot-path overhead rather than a strong claim about end-to-end runtime.Validation
git diff --checkNOT_CRAN=true Rscript -e 'pkgload::load_all(".", quiet = TRUE); testthat::test_file("tests/testthat/test-stan-convole.R")'AI assistance disclosure
Codex helped identify the optimization seam, benchmark the candidate change, and prepare this PR. I reviewed the final patch and benchmark results before submission.
Initial submission checklist
devtools::test()anddevtools::check()).devtools::document()).lintr::lint_package()).After the initial Pull Request
Summary by CodeRabbit