I am trying to compile the basic Bernoulli model with an external C++ function.
I have just downloaded the latest CmdStan from GitHub.
Added make_odds.hpp
with the following content:
namespace bernoulli_model_namespace {
template <typename T0__>
stan::promote_args_t<T0__>
make_odds(const T0__& theta, std::ostream* pstream__) {
return theta / (1 - theta);
};
}
and modified bernoulli.stan
:
functions {
real make_odds(real theta);
}
data {
int<lower=0> N;
int<lower=0,upper=1> y[N];
}
parameters {
real<lower=0,upper=1> theta;
real theta2;
}
model {
real out = make_odds(theta2); // ADDED THIS LINE
theta ~ beta(1,1); // uniform prior on interval 0,1
y ~ bernoulli(theta);
}
Now I’m trying to compile the model with USER_HEADER=examples/bernoulli/make_odds.hpp STANCFLAGS=--allow-undefined make examples/bernoulli/bernoulli
and I get the error
Undefined symbols for architecture x86_64:
"boost::math::tools::promote_args<stan::math::var, float, float, float, float, float>::type bernoulli_model_namespace::make_odds<stan::math::var>(stan::math::var const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*)", referenced from:
stan::math::var bernoulli_model_namespace::bernoulli_model::log_prob<false, false, stan::math::var>(std::__1::vector<stan::math::var, std::__1::allocator<stan::math::var> >&, std::__1::vector<int, std::__1::allocator<int> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*) const in bernoulli.o
stan::math::var bernoulli_model_namespace::bernoulli_model::log_prob<false, true, stan::math::var>(std::__1::vector<stan::math::var, std::__1::allocator<stan::math::var> >&, std::__1::vector<int, std::__1::allocator<int> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*) const in bernoulli.o
stan::math::var bernoulli_model_namespace::bernoulli_model::log_prob<true, false, stan::math::var>(std::__1::vector<stan::math::var, std::__1::allocator<stan::math::var> >&, std::__1::vector<int, std::__1::allocator<int> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*) const in bernoulli.o
stan::math::var bernoulli_model_namespace::bernoulli_model::log_prob<true, true, stan::math::var>(std::__1::vector<stan::math::var, std::__1::allocator<stan::math::var> >&, std::__1::vector<int, std::__1::allocator<int> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*) const in bernoulli.o
"boost::math::tools::promote_args<double, float, float, float, float, float>::type bernoulli_model_namespace::make_odds<double>(double const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*)", referenced from:
double bernoulli_model_namespace::bernoulli_model::log_prob<false, false, double>(std::__1::vector<double, std::__1::allocator<double> >&, std::__1::vector<int, std::__1::allocator<int> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*) const in bernoulli.o
double bernoulli_model_namespace::bernoulli_model::log_prob<false, true, double>(std::__1::vector<double, std::__1::allocator<double> >&, std::__1::vector<int, std::__1::allocator<int> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*) const in bernoulli.o
double bernoulli_model_namespace::bernoulli_model::log_prob<true, false, double>(std::__1::vector<double, std::__1::allocator<double> >&, std::__1::vector<int, std::__1::allocator<int> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*) const in bernoulli.o
double bernoulli_model_namespace::bernoulli_model::log_prob<true, true, double>(std::__1::vector<double, std::__1::allocator<double> >&, std::__1::vector<int, std::__1::allocator<int> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*) const in bernoulli.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [examples/bernoulli/bernoulli] Error 1
What has changed now with how external headers are handled? It was working before.
What am I doing wrong?