dimanche 19 juin 2016

Rcpp compiler error (with pointers?)

I am new into Rcpp package and I have one problem when I am trying to compile the following code. It is notver ycompilacated, but I think I am missing somethng fundamental:

src<-'
Rcpp::IntegerVector Itau(It);
Rcpp::NumericVector Dist_inter_tau(gamma);
double rho = Rcpp::as<double>(ro);
double Part = Rcpp::as<double>(Par);
Rcpp::Environment stats("package:stats");
Rcpp::Function rpois = stats["rpois"];
Rcpp::Function dbinom = stats["dbinom"];
double sigma_lambda = Rcpp::as<double>(sl);
double sigma_Rt = Rcpp::as<double>(sRt);
double log_likelihood = Rcpp::as<double>(loglik);
Rcpp::NumericVector Final_R_t(frt);
Rcpp::NumericVector Final_lambda_t(flt);
Rcpp::IntegerVector Final_R_I(fri);

const int Ttau=778;

double* force_inf=new double [Ttau*Part];   
for(int i=0;i<(Part*Ttau);i++){
force_inf[i]=0;
};
unsigned int* R_I=new unsigned int [Ttau*Part]; 
for(int i=0;i<(Part*Ttau);i++){
R_I[i]=0;
};
double* R_t=new double [Ttau*Part]; 
for(int i=0;i<(Part*Ttau);i++){
R_t[i]=0;
};
double* lambda_t=new double [Ttau*Part];    
for(int i=0;i<(Part*Ttau);i++){
lambda_t[i]=0;
};
double* weight=new double [Ttau*Part];  
for(int i=0;i<(Part*Ttau);i++){
weight[i]=0;
};
unsigned int* Anc=new unsigned int [Ttau*Part]; 
for(int i=0;i<(Part*Ttau);i++){
Anc[i]=0;
};

return Rcpp::wrap(Ttau);
'
SMC_c<-cxxfunction(signature(It="vector",
                             gamma="vector",
                             ro="numeric",
                             Par="numeric",
                             sl="numeric",
                             sRt="numeric",
                             loglik="numeric",
                             frt="vector",
                             flt="vector",
                             fri="vector"
                             )
                   ,src,plugin="Rcpp")
SMC_c(Itau,Dist_inter_tau,rho,Part,sigma_lambda,sigma_Rt,log_likelihood,result_Rt[,1],
      result_lambda[,1],result_RI[,1])

and I get the following error:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! file19261bf0f08c.cpp: In function ‘SEXPREC* file19261bf0f08c(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)’:
file19261bf0f08c.cpp:49:30: error: expression in new-declarator must have integral or enumeration type
 double force_inf=new double [Ttau*Part]; 
                              ^
file19261bf0f08c.cpp:49:39: error: cannot convert ‘double*’ to ‘double’ in initialization
 double force_inf=new double [Ttau*Part]; 
                                       ^
file19261bf0f08c.cpp:51:12: error: invalid types ‘double[int]’ for array subscript
 force_inf[i]=0;
            ^
file19261bf0f08c.cpp:53:37: error: expression in new-declarator must have integral or enumeration type
 unsigned int* R_I=new unsigned int [Ttau*Part]; 
                                     ^
file19261bf0f08c.cpp:57:25: error: expression in new-declarator must have integral or enumeration type
 double* R_t=new double [Ttau*Part];
In addition: Warning message:
running command '/usr/lib/R/bin/R CMD SHLIB file19261bf0f08c.cpp 2> file19261bf0f08c.cpp.err.txt' had status 1 

Why is this happening?

Aucun commentaire:

Enregistrer un commentaire