You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compilation error on simple Stan model only when using --O stanc flag.
Description:
The --O flag generates a model header including a stan::model::assign call that doesn't appear to have a matching implementation.
Reproducible Steps:
For the simple model bug.stan
parameters {
vector[1] x;
}
transformed parameters {
vector[1] theta = 1 * x;
}
model {
target += theta[1]; # using theta here seems necessary for the bug
}
the build
make bug # works
works as expected, whereas
rm bug # start from fresh
make bug STANCFLAGS=--O # fails
fails with (partial) output
g++ -std=c++17 -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -Wno-class-memaccess -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.84.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -DBOOST_DISABLE_ASSERTS -c -Wno-ignored-attributes -x c++ -o bug.o bug.hpp
bug.hpp: In instantiation of ‘stan::scalar_type_t<T2> bug_model_namespace::bug_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix<stan::math::var_value<double>, -1, 1>; VecI = Eigen::Matrix<int, -1, 1>; stan::require_vector_like_t<VecR>* <anonymous> = 0; stan::require_vector_like_vt<std::is_integral, VecI>* <anonymous> = 0; stan::require_st_var<VecR>* <anonymous> = 0; stan::scalar_type_t<T2> = stan::math::var_value<double>; std::ostream = std::basic_ostream<char>]’:
bug.hpp:371:0: required from ‘T_ bug_model_namespace::bug_model::log_prob(Eigen::Matrix<T_a, -1, 1>&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value<double>; std::ostream = std::basic_ostream<char>]’
stan/src/stan/model/model_base_crtp.hpp:98:0: required from ‘stan::math::var stan::model::model_base_crtp<M>::log_prob(Eigen::Matrix<stan::math::var_value<double>, -1, 1>&, std::ostream*) const [with M = bug_model_namespace::bug_model; stan::math::var = stan::math::var_value<double>; std::ostream = std::basic_ostream<char>]’
stan/src/stan/model/model_base_crtp.hpp:96:0: required from here
bug.hpp:129: error: no matching function for call to ‘assign(Eigen::Matrix<stan::math::var_value<double>, -1, 1>&, stan::math::var_value<Eigen::Matrix<double, -1, 1> >, const char [30])’
129 | stan::model::assign(lcm_sym7__, stan::math::multiply(1, x),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130 | "assigning variable lcm_sym7__");
|
In file included from stan/src/stan/model/indexing.hpp:9,
from stan/src/stan/model/model_header.hpp:13:
Expected Output:
I don't know whether my Stan program contains some undefined behavior such that it should never compile, or if this is a bug with the --O flag.
I understand that the --O flag enables experimental optimization features, that may or may not yield performance benefits, but I didn't expect it to fail to build such a simple program.
If it's just the case that we should expect that --O sometimes fails to build valid Stan programs, please make that clearer in the documents.
Current Version:
v2.35.0
The text was updated successfully, but these errors were encountered:
We will investigate, but I do want to say that yes, regular users should basically never use this flag. We renamed it to —Oexperimental for a reason, and if not for worrying about people already using it we probably would have removed it
Summary:
Compilation error on simple Stan model only when using
--O
stanc flag.Description:
The
--O
flag generates a model header including astan::model::assign
call that doesn't appear to have a matching implementation.Reproducible Steps:
For the simple model
bug.stan
the build
works as expected, whereas
fails with (partial) output
Expected Output:
I don't know whether my Stan program contains some undefined behavior such that it should never compile, or if this is a bug with the
--O
flag.I understand that the
--O
flag enables experimental optimization features, that may or may not yield performance benefits, but I didn't expect it to fail to build such a simple program.If it's just the case that we should expect that
--O
sometimes fails to build valid Stan programs, please make that clearer in the documents.Current Version:
v2.35.0
The text was updated successfully, but these errors were encountered: