stan-dev / stan

Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
2.57k stars 368 forks source link

Expose new base class method 'unconstrain_array' #3179

Closed WardBrian closed 1 year ago

WardBrian commented 1 year ago

Submission Checklist

Summary

This exposes the method added in https://github.com/stan-dev/stanc3/pull/1305 as a direct inverse function for write_array. unconstrain_array takes in a vector of parameters on the constrained scale _in the same order that write_array produced them_ and produces a vector of parameters on the unconstrained scale in the same order that write_array and log_prob expect.

This allows us to write what we want to write in almost all cases where we are using array_var_context followed by transform_inits at the moment (standalone generated quantities, the log_prob service function, etc). This is very useful for new features like tuples, ragged arrays, etc, since it weakens the reliance on the model.get_dims() function which fundamentally assumes that parameters are rectangular.

Intended Effect

Exposes unconstrain_array to the model base class. This function is already generated by the compiler.

How to Verify

Tests are added for the function directly and the standalone generated quantities service has been updated to use this new code.

Side Effects

None

Documentation

Copyright and Licensing

Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): Simons Foundation

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses: