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
calling integrate_ode_rk45 from function causes compilation error #471
Comments
You should not see a compiler error, rather a stan compiler error message. The issue is that temporaries created inside a function are automatically converted to I am not sure if this is still being fixed for the current parser, but certainly for stanc3. Thanks for the bug report. |
@wds15, were you able to reproduce the bug? It'd help if you stated that it was confirmed to be a bug. Do you know if it's a language bug or a Math bug? (meaning the C++ instantiation of the function should be valid in Math, but it currently doesn't handle it?) |
I haven't confirmed this, but these things looks familiar to me. It's a parser problem which is created due to over-propagation of just about anything to var in our functions (even temporaries which are clearly created from constants). |
The model still produces a c++ error with stanc3 and develop cmdstan:
|
The original issue has been fixed. parameters {
real x;
}
model {
real y0[2] = {0.0, 1.0}; // double rhs, stan::math::var lhs
y0 ~ normal(x, 1);
} This has been broken since stan-dev/stan#2885. |
Thanks @nhuurre |
I have a branch here in stan that fixes the lvalue code for the above, however I think this may also be a compiler issue The generated code with the branch above still throws an error (full hpp here) where the important bit that fails is
from line 154: std::vector<local_scalar_t__> y0;
y0 = std::vector<local_scalar_t__>(2, 0);
current_statement__ = 2;
y0 = stan::math::array_builder<double>().add(0.0).add(1.0).array(); So I think the solution here is to either
|
Or |
This works now on develop. Closing. |
Summary:
When I call
integrate_ode_rk45
from themodel
block, I can use literals for the mandatory real and integer data argumentsx_r
andx_i
. So for instance, I can writeintegrate_ode_rk45(ode, y0, t0, Ts, theta, {0.0}, {0})
. If I try to do this in an auxiliary function defined in thefunctions
block, compilation of the stan model fails with aCompileError
.Description:
I find it convenient to use an auxiliary function (defined in the functions block) to integrate ODEs for my stan model (for instance in combination with the
map_rect
function). However, I found that one has to be careful with the real and integer data arguments of e.g.integrate_ode_rk45
. If I use such an auxiliary function, these have to be defined in thedata
ortransformed data
blocks, and I can't pass dummy literal values (e.g.{0.0}
instead ofx_r
).The Stan "pre-compiler" does not give an error message. Instead the C compiler fails (without a clear description of the error).
Reproducible Steps:
As an example, I've included the following model. This version causes the
CompileError
.If I comment out the call to
bad_auxiliary_function
in themodel
block, and use thegood_auxiliary_function
instead, all works fine. I can also callbad_auxiliary_function
from thegenerated quantities
block without any errors.For easy reproducibility, here's my python script to compile and run the model.
Current Output:
This is the full error reported by python:
The same problem occurs when I use cmdstan to
make
the model. This error might contain more useful information:Expected Output:
The model works fine if I comment out the call to
bad_auxiliary_function
in the model block and use thegood_auxiliary_function
instead.PyStan Version:
2.18.1.0
Python Version:
Python 3.6.7
Cython 0.29.4
Operating System:
Ubuntu 18.04.2 LTS
GCC 8.2.0
The text was updated successfully, but these errors were encountered: