[Rcpp-devel] Error for exp() using RcppArmadillo
Amina Shahzadi
aminashahzadi at gmail.com
Mon Sep 12 05:29:57 CEST 2016
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*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20160912/18536092/attachment.html>
More information about the Rcpp-devel
mailing list