alashworth / test-issue-import

0 stars 0 forks source link

local functions block #110

Open alashworth opened 5 years ago

alashworth commented 5 years ago

Issue by bgoodri Tuesday Aug 23, 2016 at 03:19 GMT Originally opened as https://github.com/stan-dev/stan/issues/2024


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

alashworth commented 5 years ago

Comment by bob-carpenter Tuesday Aug 23, 2016 at 12:37 GMT


I take it this requires all four flavors of function:

alashworth commented 5 years ago

Comment by bgoodri Tuesday Aug 23, 2016 at 13:05 GMT


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 https://github.com/stan-dev/stan/issues/2024#issuecomment-241716731, or mute the thread https://github.com/notifications/unsubscribe-auth/ADOrqgdP7qATtcDAKQZjQtp7N4QczV5jks5qiumPgaJpZM4Jqg88 .