Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/decl assign params #1441

Merged
merged 17 commits into from
Jul 25, 2024
Merged

Feature/decl assign params #1441

merged 17 commits into from
Jul 25, 2024

Conversation

SteveBronder
Copy link
Contributor

Adds an assignment member to the Decl record which allows for assignments made inline with the declaration to be a single line. For now this is only being done for parameters. Parameters are also given the auto type so that Eigen matrices and vectors can come in as Eigen::Map types. This will stop parameters from being copied when used in later functions.

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

Make parameters auto so that the parameter types for matrices can be Eigen maps

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)

@SteveBronder
Copy link
Contributor Author

@WardBrian this seems to be failing because of a failed formatting, but I ran the formatter locally and seems fine? Tried to update all my stuff from opam and the scripts but I'm still getting the same formatting.

Copy link
Collaborator

@nhuurre nhuurre left a comment

Choose a reason for hiding this comment

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

The failure is in Debug_data_generation_tests.ml. Some of the randomly generated numbers are off, but only in the least significant bit. Floating-point numbers are notoriously finicky. Could be some difference in rounding mode or whatever?

Running locally, I see the same results as Jenkins. You can just revert Debug_data_generation_tests.ml, this PR shouldn't affect that file anyway.

src/middle/Stmt.ml Outdated Show resolved Hide resolved
@SteveBronder
Copy link
Contributor Author

The failure is in Debug_data_generation_tests.ml. Some of the randomly generated numbers are off, but only in the least significant bit. Floating-point numbers are notoriously finicky. Could be some difference in rounding mode or whatever?

Thanks, fixed!

Copy link

codecov bot commented Jul 19, 2024

Codecov Report

Attention: Patch coverage is 85.36585% with 12 lines in your changes missing coverage. Please review.

Project coverage is 89.56%. Comparing base (606a395) to head (36271ca).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1441      +/-   ##
==========================================
- Coverage   89.62%   89.56%   -0.06%     
==========================================
  Files          63       63              
  Lines       10548    10593      +45     
==========================================
+ Hits         9454     9488      +34     
- Misses       1094     1105      +11     
Files Coverage Δ
src/frontend/Ast_to_Mir.ml 94.62% <ø> (ø)
src/stan_math_backend/Lower_stmt.ml 95.65% <100.00%> (+0.15%) ⬆️
src/stan_math_backend/Transform_Mir.ml 95.77% <100.00%> (+0.04%) ⬆️
src/analysis_and_optimization/Optimize.ml 92.25% <71.42%> (-0.28%) ⬇️
src/analysis_and_optimization/Memory_patterns.ml 88.77% <88.00%> (-1.05%) ⬇️
...rc/analysis_and_optimization/Monotone_framework.ml 88.19% <40.00%> (-0.16%) ⬇️
src/middle/Stmt.ml 77.43% <50.00%> (-1.10%) ⬇️

@SteveBronder
Copy link
Contributor Author

So I absolutely need a thorough set of eyes on the optimizer code. I think I got the lazy code motion correct

src/stan_math_backend/Lower_stmt.ml Outdated Show resolved Hide resolved
@@ -458,7 +458,8 @@ let create_decl_with_assign decl_id declc decl_type initial_value transform
() } in
let decl =
Stmt.
{ Fixed.pattern= Decl {decl_adtype; decl_id; decl_type; initialize= true}
{ Fixed.pattern=
Decl {decl_adtype; decl_id; decl_type; initialize= Default}
Copy link
Member

Choose a reason for hiding this comment

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

I think this should use the logic on the next line which inspects the rhs_assignment to set Initialize

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at this code it's not modifying the params. Making changes in places that do no modify params is out of the scope of this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good -- I think we would really want to fix #1295 before doing this -- probably by writing a generic-ish check_size function in Stan which we can call after the assignment is completed.

src/stan_math_backend/Transform_Mir.ml Outdated Show resolved Hide resolved
Copy link
Member

@WardBrian WardBrian left a comment

Choose a reason for hiding this comment

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

Ok @SteveBronder, assuming you don't take issue with any of the changes I just pushed this should be good to merge after Jenkins is done

@SteveBronder SteveBronder merged commit 4f0d26c into master Jul 25, 2024
3 checks passed
@WardBrian WardBrian deleted the feature/decl-assign-params branch July 25, 2024 15:54
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.

3 participants