<div dir="ltr"><div><div>Hello Dirk, Adler and Rcpp Colleagues<br><br></div>Would you please guide me why the following code is giving the error of "<br><pre style="font-family:"lucida console";font-size:10pt;outline:medium none;border-width:medium;border-style:none;border-color:-moz-use-text-color;word-break:break-all;margin:0px;white-space:pre-wrap;line-height:11.5385px;color:rgb(0,0,0);font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255)" id="gmail-rstudio_console_output" class="gmail-GCWXI2KCJKB" tabindex="0">cannot convert 'arma::subview_elem1<double, arma::mtOp<unsigned int, arma::mtGlue<unsigned int, arma::mtOp<unsigned int, arma::Col<unsigned int>, arma::op_rel_noteq>, arma::mtOp<unsigned int, arma::Col<unsigned int>, arma::op_rel_noteq>, arma::glue_rel_and>, arma::op_find_simple> >' to 'double' in initialization"</pre><br>The problem is in double alpha1 and double beta1.<br><br><br><br>The code is:<br><br>#include <RcppArmadillo.h><br>using namespace Rcpp;<br>using namespace RcppArmadillo;<br>//[[Rcpp::depends(RcppArmadillo)]]<br>//[[Rcpp::export]]<br><br>// A example of indexing some elements of a vector <br><br>arma::vec Vec_Index(arma::vec alpha, arma::vec beta)<br>{<br> int m = alpha.size();<br> arma::uvec index(m);<br> arma::vec a(m);<br> for(int i=0; i<m; i++)<br> {<br> index(i) = i;<br> }<br> for(int i=0; i<m; i++){<br> for(int j=0; j<m; j++){<br> double alpha1 = alpha.elem(find(index !=i && index !=j));<br> double beta1 = beta.elem(find(index !=j && index !=j));<br> a(i) = exp(alpha1+beta1);<br> }<br> }<br> return a;<br>}<br><br></div><br><br><br><div><br><br><br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 15, 2016 at 2:52 AM, Avraham Adler <span dir="ltr"><<a href="mailto:avraham.adler@gmail.com" target="_blank">avraham.adler@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Amina and I continued the conversation off list, but for closure purposes, the "multiple" version was tweaked a bit as there was comparison between signed and unsigned ints which did not throw an error for me, but did for Amina. Final multiple version posted below.<br><br></div>Thanks,<br><br></div>Avi<br><div><div><br><br><span style="font-family:monospace,monospace"><span class="">#include <RcppArmadillo.h><br>using namespace Rcpp;<br>using namespace RcppArmadillo;<br>using namespace arma;<br>//[[Rcpp::depends(<wbr>RcppArmadillo)]]<br><br>//[[Rcpp::export]]<br></span>vec Sample_Exp_Multi(size_t n, vec alpha, vec beta) {<br> size_t m = alpha.size();<br> vec answers(n);<br> uvec2 S;<br> for (size_t i = 0; i < n; ++i){<br> do {<span class=""><br> S = randi<uvec>(2, distr_param(0, m - 1));<br> } while (S(0) == S(1));<br> answers(i) = exp(alpha(S(0)) + beta(S(1)));<br> }<br> return(answers);<br>}</span></span><br></div></div></div>
<br>______________________________<wbr>_________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-<wbr>project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-<wbr>project.org/cgi-bin/mailman/<wbr>listinfo/rcpp-devel</a><br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><em><font face="comic sans ms,sans-serif">Amina Shahzadi</font></em></div>
</div>