<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"Comic Sans MS";
panose-1:3 15 7 2 3 3 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Greetings and Salutations,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">The operation that you are using here:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal">exp(alpha1(0)+beta1(1));<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Returns a double instead of an arma::vec. Hence,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal">from ‘double’ to ‘arma::vec {aka arma::Col<double>}’<span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">To fix this, use:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> arma::vec temp(1);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> temp << exp(alpha1(0)+beta1(1)); // assumes 1 element in alpha1 and 2 elements in beta1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> return temp;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><br>
In addition, you should supply a return at the end of the function…<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> return arma::zeros<arma::vec>(0);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Returns a vector of length 0.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Sincerely,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">JJB<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> rcpp-devel-bounces@lists.r-forge.r-project.org [mailto:rcpp-devel-bounces@lists.r-forge.r-project.org]
<b>On Behalf Of </b>Amina Shahzadi<br>
<b>Sent:</b> Sunday, September 11, 2016 10:30 PM<br>
<b>To:</b> rcpp-devel@lists.r-forge.r-project.org<br>
<b>Subject:</b> [Rcpp-devel] Error for exp() using RcppArmadillo<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Hello Dear<o:p></o:p></p>
</div>
<p class="MsoNormal">I am new user of RcppArmadillo and Rcpp.<o:p></o:p></p>
</div>
<p class="MsoNormal">I am using a sample function pasted here. I am haivng error given below: Any can help in this regard.<br>
<br>
In function ‘arma::vec sample(arma::vec, arma::vec)’:<br>
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>}’<br>
return exp(alpha1(0)+beta1(1));<br>
^<br>
sample.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]<br>
}<br>
<o:p></o:p></p>
</div>
<p class="MsoNormal">My function sample.cpp is below.<o:p></o:p></p>
<div>
<p class="MsoNormal"><br>
<br>
<br>
#include <RcppArmadillo.h><br>
using namespace Rcpp;<br>
using namespace RcppArmadillo;<br>
//[[Rcpp::depends(RcppArmadillo)]]<br>
//[[Rcpp::export]]<br>
<br>
arma::vec sample(arma::vec alpha, arma::vec beta)<br>
{<br>
int m = alpha.size();<br>
arma::uvec index(m);<br>
for(int i=0; i<m; i++)<br>
{<br>
index(i) = i;<br>
}<br>
for(int i=0; i<m; i++)<br>
{<br>
for(int j=0; j<m; j++)<br>
{<br>
if(i==j)<br>
{<br>
arma::vec alpha1 = alpha.elem(find(index !=j));<br>
arma::vec beta1 = beta.elem(find(index!=j));<br>
return exp(alpha1(0)+beta1(1));<br>
}<br>
else<br>
{<br>
arma::vec alpha2 = alpha.elem(find(index !=i && index !=j));<br>
arma::vec beta2 = beta.elem(find(index !=i && index !=j));<br>
return exp(alpha2+beta2);<br>
}<br>
}<br>
}<br>
<br>
}<br>
<br>
<br>
<br clear="all">
<o:p></o:p></p>
<div>
<div>
<div>
<p class="MsoNormal"><br>
-- <o:p></o:p></p>
<div>
<p class="MsoNormal"><i><span style="font-family:"Comic Sans MS"">Amina Shahzadi</span></i><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>