# Compilation error in model (possible from Eigen?)

Hi,

I am trying to build a model in stan and running in to an error when compiling the stan source.

``````functions {
real wt_integrand(real t, real tc, real[] theta, real[] x_r, int[] x_i) {
//w[t] = o*(1-c) * [(1-I) + (I*(1-d)) ]
real it_a = theta[1];
real it_b = theta[2];
real ot_a = theta[3];
real ot_b = theta[4];
real T = theta[5];
real p_c = theta[6];
real p_d = theta[7];
real likelihood;
real I;
real o;
I = gamma_lcdf(T-t | it_a, it_b);
o = gamma_lpdf(t | ot_a, ot_b);
likelihood = o+p_c + log_diff_exp(0,p_c) + log_sum_exp(log_diff_exp(0,I), I+log_diff_exp(0,p_d));
return(likelihood);
}

real wt_prob(real T, real it_a, real it_b, real ot_a, real ot_b, real c, real d) {
real NO = log_diff_exp(0,gamma_lcdf(T | ot_a, ot_b));
return(log_sum_exp(NO, integrate_1d(wt_integrand, 0, T, {it_a,it_b,ot_a,ot_b,T,c,d}, {1.0}, {1}, 0.001)));
}

real yt_integrand(real t, real tc, real[] theta, real[] x_r, int[] x_i) {
real it_a = theta[1];
real it_b = theta[2];
real ot_a = theta[3];
real ot_b = theta[4];
real t_star = theta[5];
real p_c = theta[6];
real p_d = theta[7];
real likelihood;

likelihood =  gamma_lpdf(t | ot_a, ot_b) + log_sum_exp(0,p_c) + gamma_lpdf(t_star-t | it_a, it_b) + p_d ;
return(likelihood);
}

real yt_prob(real t_star, real it_a, real it_b, real ot_a, real ot_b, real T, real c, real d) {
real ON = gamma_lpdf(t_star | ot_a, ot_b) + c;
return(log_sum_exp(ON, integrate_1d(yt_integrand, 0, T, {it_a,it_b,ot_a,ot_b,t_star,c,d}, {1.0}, {1}, 0.001)));
}

}

data {
int N_T_NR_T; // no response starting at target - not a glitch
int N_T_NR_F; // no response starting at nontarget - onset/no response + onset/identity/no response
int N_T_F_F;  // glitch
int N_T_T_F;  // glitch
int N_T_F_T;  // onset + identity + glitch

int N_F_NR_F;
int N_F_NR_N;
int N_F_N_F;
int N_F_N_N;
int C; // number of columns

matrix[N_T_NR_T,C] T_no_T ;
matrix[N_T_NR_F,C] T_no_F ;
matrix[N_T_F_F,C] T_F_to_F;
matrix[N_T_T_F,C] T_T_to_F;
matrix[N_T_F_T,C] T_F_to_T;

matrix[N_F_NR_F,C] F_no_F;
matrix[N_F_NR_N,C] F_no_N;
matrix[N_F_N_F,C]  F_N_to_F;
matrix[N_F_N_N,C]  F_N_to_N;
}

parameters {
// glitch response
real<lower=0,upper=200> gt_a;
real<lower=0,upper=2> gt_b;
real<lower=0, upper=1> p_e;

// change detection
real<lower=0,upper=200> ot_a;
real<lower=0,upper=2> ot_b;
real<lower=0, upper=1> p_c;

// identity detection
real<lower=0,upper=200> it_a;
real<lower=0,upper=2> it_b;
real<lower=0, upper=1> p_d;

// hyperparameters
// real<lower=0,upper=200> it_a_hyper;
// real<lower=0,upper=200> gt_a_hyper;
// real<lower=0,upper=200> ot_a_hyper;
// real<lower=0, upper=10> pc_a;
// real<lower=0, upper=10> pd_a;
// real<lower=0, upper=10> pe_a;
}

model {
real y;
real T;
real G;
real O;
real y_pdf;

// it_a ~ gamma(it_a_hyper, 1);
// it_b ~ gamma(1, 1);
// gt_a ~ gamma(gt_a_hyper, 1);
// gt_b ~ gamma(1, 1);
// ot_a ~ gamma(ot_a_hyper, 1);
// ot_b ~ gamma(1,1);

// p_c ~ beta(pc_a, 1);
// p_d ~ beta(pd_a, 1);
// p_e ~ beta(pd_a, 1);

// targets
for(i in 1:N_T_NR_T) {
T = T_no_T[i,1];
G = gamma_lcdf(T | gt_a, gt_b) + p_e;
target += log_diff_exp(0,G);
}

for(i in 1:N_T_NR_F) {
T = T_no_T[i,1];
G = gamma_lcdf(T | gt_a, gt_b) + p_e;
target += log_diff_exp(0,G) + wt_prob(T, it_a, it_b, ot_a, ot_b, p_c, p_d);
}

for(i in 1:N_T_F_F) {
y = T_F_to_F[i,3];
target += gamma_lpdf(y | gt_a, gt_b) + p_e;
}

for(i in 1:N_T_T_F) {
y = T_T_to_F[i,3];
target += gamma_lpdf(y | gt_a, gt_b) + p_e;
}

for(i in 1:N_T_F_T) {
y = T_F_to_T[i,3];
T = T_F_to_T[i,1];
G = gamma_lcdf(T | gt_a, gt_b) + p_e;
y_pdf = log_sum_exp(gamma_lpdf(y | ot_a, ot_b)+p_c,  yt_prob(y, it_a, it_b, ot_a, ot_b, T, p_c, p_d));
target += log_diff_exp(0,G) + log_diff_exp(log_sum_exp( gamma_lpdf(y | gt_a, gt_b)+p_e, y_pdf), gamma_lpdf(y | gt_a, gt_b)+p_e+y_pdf);
}

// foils
for(i in 1:N_F_NR_F) {
T = F_no_F[i,1];
G = gamma_lcdf(T | gt_a, gt_b) + p_e;
target += log_diff_exp(0,G);
}

for(i in 1:N_F_NR_N) {
T = F_no_N[i,1];
G = gamma_lcdf(T | gt_a, gt_b) + p_e;
O = gamma_lcdf(T | ot_a, ot_b);
// use the expected onset time log(ot_a/ot_b), because there is no response
target += log_diff_exp(0,G) + log_sum_exp(log_diff_exp(0,O), log(ot_a/ot_b)+log_diff_exp(0,p_c) ) ;
}

for(i in 1:N_F_N_F) {
y = F_N_to_F[i,3];
target += gamma_lpdf(y | gt_a, gt_b) + p_e;
}

for(i in 1:N_F_N_N) {
y = F_N_to_N[i,3];
G = gamma_lcdf(T | gt_a, gt_b) + p_e;
target += log_sum_exp(gamma_lpdf(y | gt_a, gt_b)+p_e, log_diff_exp(0,G)) + gamma_lpdf(y | ot_a, ot_b) + p_c;
}

}
``````

The error which the compiler spits out is

``````g++  -I/usr/share/R/include -DNDEBUG   -I"/home/kiran/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/"  -I"/home/kiran/R/x86_64-pc-linux-gnu-library/3.4/RcppEigen/include/"  -I"/home/kiran/R/x86_64-pc-linux-gnu-library/3.4/RcppEigen/include/unsupported"  -I"/home/kiran/R/x86_64-pc-linux-gnu-library/3.4/BH/include" -I"/home/kiran/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/src/"  -I"/home/kiran/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/"  -I"/home/kiran/R/x86_64-pc-linux-gnu-library/3.4/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS     -fpic  -O3 -march=native -mtune=native -fPIC -c file31d04280f59c.cpp -o file31d04280f59c.o
/usr/lib/R/etc/Makeconf:168: recipe for target 'file31d04280f59c.o' failed
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from /home/kiran/R/x86_64-pc-linux-gnu-library/3.4/RcppEigen/include/Eigen/Core:383:0,
from /home/kiran/R/x86_64-pc-linux-gnu-library/3.4/RcppEigen/include/Eigen/Dense:1,
from
``````

This error does not give me a great idea of where the error occurs but from the looks of where the verbose output stops it might be in Eigen?

Please let me know if I am missing something or if more information can be provided to highlight some issues.

You need to compile it with the `verbose = TRUE` argument to see the real error message.

@bgoodri The verbose output says

``````make: *** [file3bf06e8c8186.o] Error 1

ERROR(s) during compilation: source code errors or compiler configuration errors!
``````

and shows me about 1300 lines of c++ wrappers its creating. I am not sure how to proceed, would appreciate your guidance on the next steps to resolve this.

The source code generated is below for reference

https://gist.github.com/knkumar/5fa1d255f508308aaafb731ffda057f3

You want to search for the line of output that starts with `error:` (including the colon).

Hi @bgoodri, thanks for your tip. I started using cmdstan and figured that the error was in the parser generating the template functors specified in this issue - https://github.com/stan-dev/stan/issues/2787

I am now facing issues in numerical integration, hoping the folks on other topics can help.

Best,
Kiran