I was able to compile the binomial example model and models that I use that do not have map_rect
however when I try to compile map_rect
models in CmdStan they fail even though they compile fine in Rstan. For example, the model from rmcelreath’s repo https://github.com/rmcelreath/cmdstan_map_rect_tutorial/blob/master/logistic1.stan compiles fine in Rstan but gives the following error in cmdstan:
--- Compiling, linking C++ code ---
g++ -DSTAN_THREADS -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -I stan/lib/stan_math/lib/tbb_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.3 -I stan/lib/stan_math/lib/boost_1.69.0 -I stan/lib/stan_math/lib/sundials_4.1.0/include -D_USE_MATH_DEFINES -DBOOST_DISABLE_ASSERTS -c -x c++ -o model/test.o model/test.hpp
In file included from stan/lib/stan_math/stan/math/prim/arr/fun/promote_elements.hpp:5:0,
from stan/lib/stan_math/stan/math/prim/mat/fun/promote_elements.hpp:4,
from stan/lib/stan_math/stan/math/prim/mat/fun/promote_common.hpp:5,
from stan/lib/stan_math/stan/math/prim/mat/fun/mdivide_left_tri.hpp:6,
from stan/lib/stan_math/stan/math/prim/mat/fun/mdivide_left_tri_low.hpp:6,
from stan/lib/stan_math/stan/math/prim/mat/fun/chol2inv.hpp:7,
from stan/lib/stan_math/stan/math/prim/mat.hpp:71,
from stan/lib/stan_math/stan/math/rev/mat.hpp:12,
from stan/lib/stan_math/stan/math.hpp:4,
from stan/src/stan/model/model_header.hpp:4,
from model/test.hpp:3:
stan/lib/stan_math/stan/math/prim/scal/fun/promote_elements.hpp: In instantiation of 'static T stan::math::promote_elements<T, S>::promote(const S&) [with T = double; S = stan::math::var]':
stan/lib/stan_math/stan/math/prim/arr/fun/array_builder.hpp:38:51: required from 'stan::math::array_builder<T>& stan::math::array_builder<T>::add(const S&) [with S = stan::math::var; T = double]'
model/test.hpp:125:60: required from 'Eigen::Matrix<typename boost::math::tools::promote_args<RT1, RT2, A>::type, -1, 1> test_model_namespace::lp_reduce(const Eigen::Matrix<Scalar, -1, 1>&, const Eigen::Matrix<RhsScalar, -1, 1>&, const std::vector<T_l>&, const std::vector<int>&, std::ostream*) [with T0__ = stan::math::var; T1__ = double; T2__ = double; typename boost::math::tools::promote_args<RT1, RT2, A>::type = stan::math::var; std::ostream = std::basic_ostream<char>]'
model/test.hpp:143:48: required from 'Eigen::Matrix<typename boost::math::tools::promote_args<RT1, RT2, A>::type, -1, 1> test_model_namespace::lp_reduce_functor__::operator()(const Eigen::Matrix<Scalar, -1, 1>&, const Eigen::Matrix<RhsScalar, -1, 1>&, const std::vector<T_l>&, const std::vector<int>&, std::ostream*) const [with T0__ = stan::math::var; T1__ = double; T2__ = double; typename boost::math::tools::promote_args<RT1, RT2, A>::type = stan::math::var; std::ostream = std::basic_ostream<char>]'
stan/lib/stan_math/stan/math/rev/mat/functor/map_rect_reduce.hpp:112:79: required from 'stan::math::matrix_d stan::math::internal::map_rect_reduce<F, stan::math::var, double>::operator()(const vector_d&, const vector_d&, const std::vector<double>&, const std::vector<int>&, std::ostream*) const [with F = test_model_namespace::lp_reduce_functor__; stan::math::matrix_d = Eigen::Matrix<double, -1, -1>; stan::math::vector_d = Eigen::Matrix<double, -1, 1>; std::ostream = std::basic_ostream<char>]'
stan/lib/stan_math/stan/math/rev/mat/functor/map_rect_concurrent.hpp:42:53: required from 'stan::math::internal::map_rect_concurrent(const Eigen::Matrix<T_shared_param, -1, 1>&, const std::vector<Eigen::Matrix<T_job_param, -1, 1> >&, const std::vector<std::vector<double> >&, const std::vector<std::vector<int> >&, std::ostream*)::<lambda(std::size_t, std::size_t)> [with int call_id = 1; F = test_model_namespace::lp_reduce_functor__; T_shared_param = stan::math::var; T_job_param = double; std::size_t = long long unsigned int]'
stan/lib/stan_math/stan/math/rev/mat/functor/map_rect_concurrent.hpp:43:7: required from 'struct stan::math::internal::map_rect_concurrent(const Eigen::Matrix<T_shared_param, -1, 1>&, const std::vector<Eigen::Matrix<T_job_param, -1, 1> >&, const std::vector<std::vector<double> >&, const std::vector<std::vector<int> >&, std::ostream*) [with int call_id = 1; F = test_model_namespace::lp_reduce_functor__; T_shared_param = stan::math::var; T_job_param = double; typename stan::return_type<T1, T2>::type = stan::math::var; std::ostream = std::basic_ostream<char>]::<lambda(std::size_t, std::size_t)>'
stan/lib/stan_math/stan/math/rev/mat/functor/map_rect_concurrent.hpp:45:3: required from 'Eigen::Matrix<typename stan::return_type<T1, T2>::type, -1, 1> stan::math::internal::map_rect_concurrent(const Eigen::Matrix<T_shared_param, -1, 1>&, const std::vector<Eigen::Matrix<T_job_param, -1, 1> >&, const std::vector<std::vector<double> >&, const std::vector<std::vector<int> >&, std::ostream*) [with int call_id = 1; F = test_model_namespace::lp_reduce_functor__; T_shared_param = stan::math::var; T_job_param = double; typename stan::return_type<T1, T2>::type = stan::math::var; std::ostream = std::basic_ostream<char>]'
stan/lib/stan_math/stan/math/prim/mat/functor/map_rect.hpp:175:48: required from 'Eigen::Matrix<typename stan::return_type<T1, T2>::type, -1, 1> stan::math::map_rect(const Eigen::Matrix<T_shared_param, -1, 1>&, const std::vector<Eigen::Matrix<T_job_param, -1, 1> >&, const std::vector<std::vector<double> >&, const std::vector<std::vector<int> >&, std::ostream*) [with int call_id = 1; F = test_model_namespace::lp_reduce_functor__; T_shared_param = stan::math::var; T_job_param = double; typename stan::return_type<T1, T2>::type = stan::math::var; std::ostream = std::basic_ostream<char>]'
model/test.hpp:289:74: required from 'T__ test_model_namespace::test_model::log_prob(std::vector<T_l>&, std::vector<int>&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T__ = stan::math::var; std::ostream = std::basic_ostream<char>]'
stan/src/stan/model/model_base_crtp.hpp:153:29: required from 'stan::math::var stan::model::model_base_crtp<M>::log_prob(std::vector<stan::math::var>&, std::vector<int>&, std::ostream*) const [with M = test_model_namespace::test_model; std::ostream = std::basic_ostream<char>]'
model/test.hpp:489:1: required from here
stan/lib/stan_math/stan/math/prim/scal/fun/promote_elements.hpp:24:48: error: cannot convert 'const stan::math::var' to 'double' in return
inline static T promote(const S& u) { return u; }
^
stan/lib/stan_math/stan/math/prim/scal/fun/promote_elements.hpp: In static member function 'static T stan::math::promote_elements<T, S>::promote(const S&) [with T = double; S = stan::math::var]':
stan/lib/stan_math/stan/math/prim/scal/fun/promote_elements.hpp:24:51: warning: control reaches end of non-void function [-Wreturn-type]
inline static T promote(const S& u) { return u; }
^
make: *** [make/program:43: model\test.exe] Error 1