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

Add get_param_names overload with flag arguments #1241

Merged
merged 2 commits into from
Aug 25, 2022

Conversation

WardBrian
Copy link
Member

This would be the first part of #1240. After this is merged, we can safely update Stan's model_base to require these arguments, then delete the original overload, then fix the bug @SteveBronder noticed by setting the flags to false during initialization.

While we are at it, would we want to make the same change to get_dims?

Submission Checklist

  • Run unit tests
  • Documentation
    • OR, no user-facing changes were made

Release notes

Added a new version of the model method get_param_names which allows specifiying if the transformed parameters or generated quantities should be emitted.

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)

@WardBrian
Copy link
Member Author

Discussed in the weekly Stan meeting, @bob-carpenter confirmed it was fine to add the new arguments with defaults in model_base for backwards compatibility purposes.

After this is merged we can update the model_base signatures to be

  virtual void get_param_names(std::vector<std::string>& names,
                                bool include_tparams = true,
                                bool include_gqs = true) const = 0;
  virtual void get_dims(std::vector<std::vector<size_t> >& dimss,
                        bool include_tparams = true,
                        bool include_gqs = true) const = 0;

@WardBrian
Copy link
Member Author

@SteveBronder this is ready for review and should be relatively quick, if you have a moment

Copy link
Contributor

@SteveBronder SteveBronder left a comment

Choose a reason for hiding this comment

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

lgtm!

(** Print the [get_param_names] method of the model class
@param ppf A pretty printer.
*)
let pp_get_param_names ppf {Program.output_vars; _} =
let add_param = fmt "%S" in
(* old -- kept as overload for compat until model_base changes *)
Copy link
Contributor

Choose a reason for hiding this comment

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

del this and the other new comment tho'

Copy link
Member Author

Choose a reason for hiding this comment

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

After the change to model_base I plan on deleting the old code, and those comments

Copy link
Contributor

Choose a reason for hiding this comment

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

Lets not delete the old code since we want to keep backwards compatibility (C++ sees these as two different virtual function signatures)

Copy link
Member Author

Choose a reason for hiding this comment

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

We cannot expose both

virtual void get_param_names(std::vector<std::string>& names) const = 0;

and

virtual void get_param_names(std::vector<std::string>& names, const bool emit_transformed_parameters = true, const bool emit_generated_quantities = true) const = 0;

since it makes calls with only the vector argument ambiguous. Because we're providing default values for the arguments which match previous behavior, we should just keep the second

@WardBrian WardBrian merged commit 8139ab1 into master Aug 25, 2022
@WardBrian WardBrian deleted the feature/1240-controllable-param-names branch August 25, 2022 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants