Hi folks, so I’m working with a model that compiles fine with the latest rstan
, but I would like to take advantage of the reduce_sum
capabilities in available in cmdstan
.
I am running this on a more or less “fresh” install of R, cmdstan, etc, on a new Mac I got running Catalina (10.15.4). Rstan works fine. I haven’t done anything to the C++ toolchain (haven’t added a Makevars file or anything like that). I just installed cmdstanr
today.
> cmdstan_version()
[1] "2.23.0"
However, the model will not compile. I get this error:
Compiling Stan program...
In file included from /var/folders/vz/4l1x57s13_b33rh17_qqhzdw0000gn/T/RtmpJl6dV0/model-84751e3c16fa.hpp:1:
In file included from stan/src/stan/model/model_header.hpp:4:
In file included from /Users/thomasvladeck/.cmdstanr/cmdstan-2.23.0/stan/lib/stan_math/stan/math.hpp:19:
In file included from /Users/thomasvladeck/.cmdstanr/cmdstan-2.23.0/stan/lib/stan_math/stan/math/rev.hpp:9:
In file included from /Users/thomasvladeck/.cmdstanr/cmdstan-2.23.0/stan/lib/stan_math/stan/math/prim.hpp:8:
In file included from /Users/thomasvladeck/.cmdstanr/cmdstan-2.23.0/stan/lib/stan_math/stan/math/prim/err.hpp:4:
In file included from /Users/thomasvladeck/.cmdstanr/cmdstan-2.23.0/stan/lib/stan_math/stan/math/prim/err/check_2F1_converges.hpp:6:
/Users/thomasvladeck/.cmdstanr/cmdstan-2.23.0/stan/lib/stan_math/stan/math/prim/fun/fabs.hpp:37:10: error: implicit instantiation of undefined template 'stan::math::apply_scalar_unary<stan::math::fabs_fun, unsigned long, void>'
return apply_scalar_unary<fabs_fun, Container>::apply(x);
^
/var/folders/vz/4l1x57s13_b33rh17_qqhzdw0000gn/T/RtmpJl6dV0/model-84751e3c16fa.hpp:509:42: note: in instantiation of function template specialization 'stan::math::fabs<unsigned long, nullptr>' requested here
stan::math::fabs((x - xprime))) / p)), 2)) /
^
/var/folders/vz/4l1x57s13_b33rh17_qqhzdw0000gn/T/RtmpJl6dV0/model-84751e3c16fa.hpp:1074:13: note: in instantiation of function template specialization 'reduce_sum_model_namespace::locally_periodic_kernel<unsigned long, unsigned long, double, double, double, double>' requested here
locally_periodic_kernel(i, j, sigma, p, l1, l2, pstream__),
^
/Users/thomasvladeck/.cmdstanr/cmdstan-2.23.0/stan/lib/stan_math/stan/math/prim/meta/apply_scalar_unary.hpp:38:8: note: template is declared here
struct apply_scalar_unary;
^
1 error generated.
make: *** [/var/folders/vz/4l1x57s13_b33rh17_qqhzdw0000gn/T/RtmpJl6dV0/model-84751e3c16fa] Error 1
Error: An error occured during compilation! See the message above for more information.
It appears to be a problem with fabs
which is called in this function:
real locally_periodic_kernel(real x, real xprime, real sigma, real p, real l1, real l2) {
real cov_val;
cov_val = sigma^2 * exp(-2 * sin(pi() * fabs(x-xprime)/p)^2 / l1^2) *
exp(-(x-xprime)^2 / (2 * l2^2));
return(cov_val);
}
I haven’t been able to find a similar error anywhere. Any ideas what I need to do to get this to compile with cmdstanr
?