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

local functions block #2024

Closed
bgoodri opened this issue Aug 23, 2016 · 3 comments
Closed

local functions block #2024

bgoodri opened this issue Aug 23, 2016 · 3 comments
Assignees
Labels
Milestone

Comments

@bgoodri
Copy link
Contributor

bgoodri commented Aug 23, 2016

Summary:

The Stan language should have the ability to create user-defined member functions of the model class

Description:

At the last meeting, we proposed adding a new block to the Stan language that perhaps could be called local functions that would go after transformed data. The Stan syntax would be the same as in the functions block but unlike the user-defined functions in the functions block the user-defined functions in the local functions block could refer to objects in the data and transformed data blocks without explicitly passing them as arguments. This would make such functions much easier to use than integrate_ode, which requires fixed arguments to be passed in a very clunky way. It might look like

data {
  int<lower=1> N;
}
transformed data {
  int<lower=2> two_N;
  two_N = 2 * N;
}
local functions {
  void what_is_2N() {
    print("2N = ", two_N);
  }
}

Reproducible Steps:

Does not currently exist.

Current Output:

Does not currently exist.

Expected Output:

Whatever the user-defined function returns

Additional Information:

None

Current Version:

v2.11.0

@bgoodri bgoodri added this to the Future milestone Aug 23, 2016
@bob-carpenter
Copy link
Contributor

bob-carpenter commented Aug 23, 2016

I take it this requires all four flavors of function:

  • _lp : has access to density so target += and ~ statements may be used (only callable in model block)
  • _rng: has access to PRNG, so _rng functions may be used (only callable in generated quantities block)
  • _lpdf, _lpmf, _lcdf, _lccdf : pdf and pmf may be used on right-hand side of sampling statements, called with vertical bar notation (can be used anywhere, but sampling sttements restricted to model block)
  • none-of-the-above: can't do any of the above, but may be used anywhere

@bgoodri
Copy link
Contributor Author

bgoodri commented Aug 23, 2016

I would think that the possible types would be the same as for global
functions the user defines.

On Aug 23, 2016 8:37 AM, "Bob Carpenter" notifications@github.com wrote:

I take it this requires all four flavors of function:

_lp : has access to density so target += and ~ statements may be used

_rng: has access to PRNG, so _rng functions may be used

_lpdf, _lpmf : may be used on right-hand side of sampling statements

none-of-the-above: can't do any of the above, but may be used anywhere


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#2024 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ADOrqgdP7qATtcDAKQZjQtp7N4QczV5jks5qiumPgaJpZM4Jqg88
.

@rok-cesnovar
Copy link
Member

Closing, this will be possible with closures: stan-dev/stanc3#742

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants