stan-dev / stanc3

The Stan transpiler (from Stan to C++ and beyond).
BSD 3-Clause "New" or "Revised" License
140 stars 44 forks source link

Add get_param_sizes function to generated C++ #1326

Closed WardBrian closed 10 months ago

WardBrian commented 1 year ago

This PR splits off some small changes from #1100 and adds a new function called get_param_sizes with signature:

std::vector<size_t> get_param_sizes(const bool emit_transformed_parameters__ = true,
                                    const bool emit_generated_quantities__ = true)

This function is forward-compatible with all future types we have discussed for Stan (they will always have a size), and makes it possible to re-write things like random_var_context to not depend on get_dims, which is not forward compatible and assumes rectangular dimensions.

Submission Checklist

Release notes

Added code-generation for a new function get_param_sizes

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 commented 1 year ago

There is a corresponding C++ branch here: https://github.com/stan-dev/stan/tree/model-base-get-sizes/

This isn't strictly necessary for tuples (this final usage of get_dims can be hacked around) so I'm happy to avoid it for the time being.