Greetings and Salutations, The operation that you are using here:
exp(alpha1(0)+beta1(1)); Returns a double instead of an arma::vec. Hence, from ‘double’ to ‘arma::vec {aka arma::Col<double>}’ To fix this, use: arma::vec temp(1); temp << exp(alpha1(0)+beta1(1)); // assumes 1 element in alpha1 and 2 elements in beta1 return temp; In addition, you should supply a return at the end of the function… return arma::zeros<arma::vec>(0); Returns a vector of length 0. Sincerely, JJB From: rcpp-devel-boun...@lists.r-forge.r-project.org [mailto:rcpp-devel-boun...@lists.r-forge.r-project.org] On Behalf Of Amina Shahzadi Sent: Sunday, September 11, 2016 10:30 PM To: rcpp-devel@lists.r-forge.r-project.org Subject: [Rcpp-devel] Error for exp() using RcppArmadillo Hello Dear I am new user of RcppArmadillo and Rcpp. I am using a sample function pasted here. I am haivng error given below: Any can help in this regard. In function ‘arma::vec sample(arma::vec, arma::vec)’: sample.cpp:23:35: error: could not convert ‘exp((alpha1.arma::Col<double>::<anonymous>.arma::Mat<eT>::operator()<double>(0u) + beta1.arma::Col<double>::<anonymous>.arma::Mat<eT>::operator()<double>(1u)))’ from ‘double’ to ‘arma::vec {aka arma::Col<double>}’ return exp(alpha1(0)+beta1(1)); ^ sample.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type] } My function sample.cpp is below. #include <RcppArmadillo.h> using namespace Rcpp; using namespace RcppArmadillo; //[[Rcpp::depends(RcppArmadillo)]] //[[Rcpp::export]] arma::vec sample(arma::vec alpha, arma::vec beta) { int m = alpha.size(); arma::uvec index(m); for(int i=0; i<m; i++) { index(i) = i; } for(int i=0; i<m; i++) { for(int j=0; j<m; j++) { if(i==j) { arma::vec alpha1 = alpha.elem(find(index !=j)); arma::vec beta1 = beta.elem(find(index!=j)); return exp(alpha1(0)+beta1(1)); } else { arma::vec alpha2 = alpha.elem(find(index !=i && index !=j)); arma::vec beta2 = beta.elem(find(index !=i && index !=j)); return exp(alpha2+beta2); } } } } -- Amina Shahzadi
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel