Open bgoodri opened 6 years ago
But it breaks tests in other R packages and changes the behavior of expose_stan_functions() without being readily apparent to the person calling the function in order to do something that is completely foreign in the R / Python workflow.
On Thu, Aug 23, 2018 at 9:30 PM Krzysztof Sakrejda notifications@github.com wrote:
The current pr works without any more gsub or default values, you'd just have to pass all the requires args Stan requires
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/550#issuecomment-415623145, or mute the thread https://github.com/notifications/unsubscribe-auth/ADOrquxhVd4W7I7yflstHdHXlG1wCUnNks5uT1cmgaJpZM4WDJD5 .
Sure, if somebody is relying on undocumented text munging on c++ code sometimes their code will need updating. They should've used an explicit return to begin with. As I said elsewhere I don't object to the code munging, I just don't want to take responsibility for maintaining the code munging.
RNGs maintain state, but I agree that it's unusual behavior for R and that we should maintain existing behavior.
What is the existing behavior for _lp functions? Is there a way to recover the target increment or is it just hidden?
The existing, and documented, behavior is that the user-defined function ending in _lp is passed (by value) an initial value of lp (which defaults to 0) that gets incremented from there. If users want to chain those together, then they need to return target(); from the first function call and pass the returned value to the lp argument of the next function call.
On Fri, Aug 24, 2018 at 4:56 AM Bob Carpenter notifications@github.com wrote:
RNGs maintain state, but I agree that it's unusual behavior for R and that we should maintain existing behavior.
What is the existing behavior for _lp functions? Is there a way to recover the target increment or is it just hidden?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/550#issuecomment-415697479, or mute the thread https://github.com/notifications/unsubscribe-auth/ADOrqr4YUILgMzAw3i48Xkszxu1IkP3Pks5uT7-sgaJpZM4WDJD5 .
I found this doc, but couldn't follow it.
LP functions If a user-defined Stan function ends in
_lp
, then it can modify the log-probability used by Stan to evaluate Metropolis proposals or as an objective function for optimization. When exposing such functions to R, a lp argument will be added to the formals. This `lpargument defaults to zero, but a double precision scalar may be passed to this argument when the function is called from R. Such a user-defined Stan function can terminate with return
target(); or can execute
print(target())`; to verify that the calculation is correct.
I don't see from this how I'd call the exposed function, because I dont know what "formals" are. I see there are "formal arguments" but I don't know what other kind there are (are the ...
not formal?).
Is lp__
the name of an argument, as in I'd use lp__ = x
to pass in a value?
I take it the target()
has to be inside the Stan program? I didn't see doc for it as an RStan function.
And I take it there's no persistence of target()
across multiple calls the way there is in a Stan program.
I take it the argument being passed is passed by value (I don't even know if there is pass-by-reference in R) so that it doesn't get modified the way the actual Stan function works?
The answer to all of those is "yes". And the formals of foo_lp are the arguments to the function lp. There are no informals.
On Fri, Aug 24, 2018 at 9:18 AM Bob Carpenter notifications@github.com wrote:
I found this doc, but couldn't follow it.
LP functions If a user-defined Stan function ends in _lp, then it can modify the log-probability used by Stan to evaluate Metropolis proposals or as an objective function for optimization. When exposing such functions to R, a lp argument will be added to the formals. This lp argument defaults to zero, but a double precision scalar may be passed to this argument when the function is called from R. Such a user-defined Stan function can terminate with returntarget(); or can execute print(target()); to verify that the calculation is correct.
I don't see from this how I'd call the exposed function, because I dont know what "formals" are. I see there are "formal arguments" but I don't know what other kind there are (are the ... not formal?).
Is lp the name of an argument, as in I'd use lp = x to pass in a value?
I take it the target() has to be inside the Stan program? I didn't see doc for it as an RStan function.
And I take it there's no persistence of target() across multiple calls the way there is in a Stan program.
I take it the argument being passed is passed by value (I don't even know if there is pass-by-reference in R) so that it doesn't get modified the way the actual Stan function works?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/550#issuecomment-415755941, or mute the thread https://github.com/notifications/unsubscribe-auth/ADOrqkBoUvIA5Kv4RUaQv5CBiy1Fs4n-ks5uT_0TgaJpZM4WDJD5 .
Summary:
expose_stan_functions
does not work with functions that modifytarget
, which worked previouslyDescription:
If you try, there is a compiler error
Reproducible Steps:
expose_stan_functions
thisCurrent Output:
and the relevant part of the generated C++ file is
Expected Output:
None
RStan Version:
develop (2.18) branch from GitHub
R Version:
3.5
Operating System:
Debian