<div dir="ltr">Hi guys,<div><br></div><div>Here's what I think is going on. RcppArmadillo has the following 'InputParameter' class to handle 'as':</div><div><br></div><div><div>template <typename T, typename VEC, typename REF></div>
<div>    class ArmaVec_InputParameter {</div><div>    public:</div><div>        ArmaVec_InputParameter( SEXP x_ ) : v(x_), vec( reinterpret_cast<T*>( v.begin() ), v.size(), false ){}</div><div>                        </div>
<div>        inline operator REF(){</div><div>            return vec ;        </div><div>        }</div><div>                        </div><div>    private:</div><div>        Rcpp::Vector< Rcpp::traits::r_sexptype_traits<T>::rtype > v ;</div>
<div>        VEC vec ;</div><div>    } ;</div></div><div><br></div><div>We are trying to re-use memory from an R vector, and here we are just reinterpreting the 'int' contents of the R vector as 'unsigned int' without any coercion. This won't work.</div>
<div><br></div><div>(Interestingly, in the 'base' case (ie, arma::uvec vs. const or ref-qualified arma::uvec), we are just dispatching to an internal Rcpp as, not any of the RcppArmadillo 'as'es. That's why we don't see it here -- that dispatch explicitly uses 'as')<br>
</div><div><br></div><div>To fix this, we need to coerce when necessary. I believe the r_sexptype_traits class has a bit of 'does this fit in an R vector, or does it need coercion?' in it, so maybe we can leverage that.</div>
<div><br></div><div>I have a fix that I will submit to RcppArmadillo as a pull request in a few moments.</div><div><br></div><div>Thanks for the bug report!</div><div><br></div><div>Kevin</div><div class="gmail_extra"><br>
<br><div class="gmail_quote">On Sun, Apr 20, 2014 at 11:36 AM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class=""><br>
On 20 April 2014 at 20:18, Mitov Venelin wrote:<br>
| Hi Dirk,<br>
|<br>
| Had a look at your example (function named venelin). It seems to me that the problem is not only the const qualifier but also the passing of an argument by reference.<br>
|<br>
| uvec touvec(uvec& v) {    //fails!<br>
|    return v;<br>
| }<br>
|<br>
| uvec touvec(uvec v) {     // works!<br>
|   return v;<br>
| }<br>
|<br>
| Don’t know if this helps….<br>
<br>
</div>It seems the combination of either/or/both const and & AND use of uvec<br>
triggers this.  A base uvec vector seems to pass in fine, as does const ref<br>
use of a normal int vector.<br>
<br>
I think we are being tripped up by a partial conversion. We will try to get<br>
to it.  In the meantime, maybe just avoid 'uvec' which has no direct R<br>
counterpart.<br>
<div class="HOEnZb"><div class="h5"><br>
Dirk<br>
<br>
--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></div></div></blockquote></div><br></div></div>