Skip to content

Stanc.Std: Move over Analysis module - #1661

Open
WardBrian wants to merge 1 commit into
std/stan_math_backendfrom
std/analysis
Open

Stanc.Std: Move over Analysis module#1661
WardBrian wants to merge 1 commit into
std/stan_math_backendfrom
std/analysis

Conversation

@WardBrian

@WardBrian WardBrian commented Aug 10, 2026

Copy link
Copy Markdown
Member

The most notable change here is the addition of our own vendored polymorphic set. This is based on OCaml's set implementation, but with polymorphic comparison swapped in. Remarkably, I've found that it is dramatically faster than Base.Set.Poly in our uses, presumably because Base.Set.Poly is storing the comparison function in the runtime representation still, even though it never changes

Submission Checklist

  • Run unit tests
  • Documentation
    • If a user-facing facing change was made, the documentation PR is here:
    • OR, no user-facing changes were made

Release notes

Copyright and Licensing

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)


Stack created with GitHub Stacks CLIGive Feedback 💬

@WardBrian
WardBrian force-pushed the std/analysis branch 2 times, most recently from 60fbb2b to 76c1fb4 Compare August 12, 2026 16:03
@WardBrian
WardBrian requested a review from nhuurre August 12, 2026 16:51
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.12%. Comparing base (c2093d3) to head (76c1fb4).

Files with missing lines Patch % Lines
src/analysis_and_optimization/Factor_graph.ml 78.26% 10 Missing ⚠️
src/analysis_and_optimization/Memory_patterns.ml 90.90% 4 Missing ⚠️
src/analysis_and_optimization/Mir_utils.ml 81.81% 4 Missing ⚠️
...rc/analysis_and_optimization/Monotone_framework.ml 97.58% 3 Missing ⚠️
src/analysis_and_optimization/Optimize.ml 94.82% 3 Missing ⚠️
src/analysis_and_optimization/Pedantic_analysis.ml 95.91% 2 Missing ⚠️
src/analysis_and_optimization/Partial_evaluator.ml 83.33% 1 Missing ⚠️
src/std/std.ml 85.71% 1 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                    @@
##           std/stan_math_backend    #1661      +/-   ##
=========================================================
- Coverage                  92.17%   92.12%   -0.05%     
=========================================================
  Files                         70       70              
  Lines                      10128    10141      +13     
=========================================================
+ Hits                        9335     9342       +7     
- Misses                       793      799       +6     
Files with missing lines Coverage Δ
src/analysis_and_optimization/Dataflow_types.ml 25.00% <100.00%> (+25.00%) ⬆️
src/analysis_and_optimization/Dataflow_utils.ml 100.00% <100.00%> (ø)
...analysis_and_optimization/Debug_data_generation.ml 81.63% <100.00%> (ø)
...c/analysis_and_optimization/Dependence_analysis.ml 100.00% <100.00%> (ø)
...nalysis_and_optimization/Pedantic_dist_warnings.ml 91.70% <100.00%> (ø)
src/middle/Index.ml 85.18% <ø> (ø)
src/stan_math_backend/Transform_Mir.ml 95.54% <100.00%> (ø)
src/analysis_and_optimization/Partial_evaluator.ml 90.95% <83.33%> (+0.02%) ⬆️
src/std/std.ml 90.65% <85.71%> (+0.55%) ⬆️
src/analysis_and_optimization/Pedantic_analysis.ml 96.08% <95.91%> (+0.49%) ⬆️
... and 5 more

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines -34943 to +34941
stan::model::assign(psi_con, lcm_sym19__,
"assigning variable psi_con", stan::model::index_uni(i));
stan::model::assign(psi_con, 1, "assigning variable psi_con",
stan::model::index_uni(i));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like constant propagation got a bit smarter, but why?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent a few hours on trying to debug this and I couldn’t pinpoint the change.

I also threw whatever free credits of Claude github gives me, and it spun in circles but couldn’t identify anything either after spending the entire month’s allocation.

In the end, I think the fact that this wasn’t being propagated in master was a bug, and the relevant optimizations are only turned on for Oexperimental, so I gave up looking for the cause… if you can find anything without wasting too much time, I would still be curious!

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.

2 participants