[is there a reason this isn't on stan-dev?]
Sebastian's e-mail seems to missing the juicy bits.
I would really rather not expose a pass-by-value vs. pass-by-reference
distinction in Stan --- it's one of the things users find really
confusing.
Regexes are not the long-term solution here --- we need to either
1. generate wrapper functions
2. code generate what's needed inside language/generator.hpp
Regexes are very very very brittle and will make it hard to put tests
into Stan to make sure we don't break them on the R side.
As a wise man (Jamie Zawinski apparently), once said,
If you have a problem and think regexes are the solution,
now you have two problems.
http://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/
- Bob
> On Mar 5, 2015, at 2:54 AM, Ben Goodrich <goodri...@gmail.com> wrote:
>
> I still think this would be hard, but perhaps as a first step in that direction, is it feasible to liberalize the syntax for functions so that they could take non-const references (perhaps with an explicit & in the Stan program) to arguments, as in
>
> void foo(matrix& x, matrix& y, matrix z) {
> // modify x and y but not z
> }
>
> Then the user could implement their transformed parameters block as
>
> transformed parameters {
> matrix[K,K] x; matrix[J,J] y;
> foo(x, y, z);
> }
>
> I'm not sure within the Stan language how we could catch / prevent someone from passing a const thing like data or parameters to a non-const argument of a user-defined function, but then again I'm not sure how the parser currently catches / prevents a lot of things.
>
> Ben
>
>
> On Tue, Mar 3, 2015 at 7:32 AM, Weber, Sebastian <sebasti...@novartis.com> wrote:
> Hi Bob!
>
>
>
> I saw the expose Stan functions thing is being reconsidered – this is a great feature, really! When you redesign this, could you consider to include functions like
>
>
>
> Transformed_data
>
> Transformed_parameters
>
> Model
>
>
>
> As output of these specially parsed Stan models? Ben said this is close to impossible by the regex approach, but if you think it would be easily possible when you parse the program, then this would be a great thing (Aki liked the approach a lot).
>
>
>
> I see that this might be difficult, as the functions would need to return a ragged structure, but if there is a way to do it, I think it would be fanatastic.
>
>
>
> Best,
>
>
>
> Sebastian Weber
>
> Senior Statistical Methodologist, Novartis Oncology
>
> Biometrics and Data Management
>
> Novartis Pharma AG
>
> Postfach
>
> CH-4002 Basel
>
> SWITZERLAND
>
>
>
> Phone +41 61 3246217
>
> Fax +41 61 6961710
>
> sebasti...@novartis.com
>
> www.novartis.com
>
>
>
>
> The next question is whether you can somehow make the entirety of the transformed parameters block, the model block, etc. into a function defined in the functions block so that you can then call it exactly in R?
Maybe. They'd have to run on an instantiated model though
with initialized parameters, because
* transformed data depends on data
* transformed params depend on data, transformed data, parameters
* model depends on everything
> But you pass the arguments to the user-defined functions back from the interface. So couldn't you just call your functions in the correct sequence?
I'm afraid I don't understand what you mean. What signature(s)
do you need from C++?
Ben
OK, I think I see waht you're asking for. Is it for
testing purposes? That'd make sense.
We could expose those functions in C++ using const refs
for the inputs and non-const refs for the outputs.
Is that enough to get them through to R?