<div dir="ltr"><div><div>Hi again, <br><br>The following code worked:<br>// [[Rcpp::depends(RcppArmadillo)]]<br>#include <RcppArmadillo.h><br>#include <Rcpp.h><br><br>using namespace Rcpp ;<br>using namespace arma ;<br>
using namespace std ;<br><br>// [[Rcpp::export]]<br>uvec touvec(<b>uvec v</b>) {<br>  return v;<br>}<br><br></div>So maybe something goes wrong if i pass const & as an argument :(.<br><br></div>Best, <br>Venelin<br></div>
<div class="gmail_extra"><br><br><div class="gmail_quote">2014-04-20 15:46 GMT+02:00 Venelin Mitov <span dir="ltr"><<a href="mailto:vmitov@gmail.com" target="_blank">vmitov@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>Hi again, <br><br>Here is an example:<br><br></div><div>my c++ file:<br>// [[Rcpp::depends(RcppArmadillo)]]<br>#include <RcppArmadillo.h><br>#include <Rcpp.h><br><br>using namespace Rcpp ;<br>

using namespace arma ;<br>using namespace std ;<br><br>// [[Rcpp::export]]<br>uvec touvec(const uvec& v) {<br>  return v;<br>}<br><br></div><div>Save to "example.cpp" and call the following in R-console:<br>

<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;font-style:normal;background-color:rgb(225,226,229);font-weight:normal;line-height:12px;border-collapse:separate;text-transform:none;font-size:11px;white-space:pre-wrap;font-family:'Lucida Console';word-spacing:0px"><pre style="font-family:'Lucida Console';font-size:8pt!important;outline-style:none;outline-width:initial;outline-color:initial;border-style:none;border-width:initial;border-color:initial;white-space:pre-wrap!important;word-break:break-all;margin:0px;line-height:1.2">
<span style="white-space:pre-wrap;color:blue">> </span><span style="color:blue">Rcpp::sourceCpp('example.cpp')</span><span style="white-space:pre-wrap;color:blue"></span><span style="color:blue"><br>
</span><span style="text-indent:0px;letter-spacing:normal;font-variant:normal;font-style:normal;background-color:rgb(225,226,229);font-weight:normal;line-height:12px;border-collapse:separate;text-transform:none;font-size:11px;white-space:pre-wrap;font-family:'Lucida Console';word-spacing:0px"><pre style="font-family:'Lucida Console';font-size:8pt!important;outline-style:none;outline-width:initial;outline-color:initial;border-style:none;border-width:initial;border-color:initial;white-space:pre-wrap!important;word-break:break-all;margin:0px;line-height:1.2">
<span style="white-space:pre-wrap;color:blue">> </span><span style="color:blue">touvec(1:10)
</span><div class="">            [,1]
 [1,]          0
 [2,] 1072693248
 [3,]          0
 [4,] 1073741824
 [5,]          0
 [6,] 1074266112
 [7,]          0
 [8,] 1074790400
 [9,]          0
[10,] 1075052544<br><br></div></pre></span></pre><pre style="font-family:'Lucida Console';font-size:8pt!important;outline-style:none;outline-width:initial;outline-color:initial;border-style:none;border-width:initial;border-color:initial;white-space:pre-wrap!important;word-break:break-all;margin:0px;line-height:1.2">
Best, <br></pre><pre style="font-family:'Lucida Console';font-size:8pt!important;outline-style:none;outline-width:initial;outline-color:initial;border-style:none;border-width:initial;border-color:initial;white-space:pre-wrap!important;word-break:break-all;margin:0px;line-height:1.2">
Venelin<br></pre></span><br><br></div><div><br></div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-04-20 15:34 GMT+02:00 Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span>:<div>
<div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi Venelin,<br>
<div><div><br>
On 20 April 2014 at 15:18, Venelin Mitov wrote:<br>
| Hello,<br>
|<br>
| I have a dynamic library with C++ functions built using Rcpp. I've recently<br>
| updated to the newest version of R/Rcpp/RcppArmadillo and after rebuilding my<br>
| library it lost its expected behavior. After some debugging I found that one of<br>
| possibly several problems is the following:<br>
|<br>
| I have an exported cpp function with the following signature:<br>
| uvec shift(const uvec& idx, int dshift, int n, int i=1);<br>
|<br>
| In my R-code I call this function as follows:<br>
| shifted_idx <- shift(1:10, 5, 10, 1).<br>
| This is a detail, but let me mension that all this function does is to rotate<br>
| the vector of indices idx left by 5 positions, so the result should be the<br>
| vector: c(6,7,8,9,10,1,2,3,4,5).<br>
|<br>
| This is the wrapper for the same function generated with the older<br>
| Rcpp-version:<br>
| RcppExport SEXP sourceCpp_28368_shift(SEXP idxSEXP, SEXP dshiftSEXP, SEXP<br>
| nSEXP, SEXP iSEXP) {<br>
| BEGIN_RCPP<br>
|     SEXP __sexp_result;<br>
|     {<br>
|         Rcpp::RNGScope __rngScope;<br>
|         uvec idx = Rcpp::as<uvec >(idxSEXP);<br>
|         int dshift = Rcpp::as<int >(dshiftSEXP);<br>
|         int n = Rcpp::as<int >(nSEXP);<br>
|         int i = Rcpp::as<int >(iSEXP);<br>
|         uvec __result = shift(idx, dshift, n, i);<br>
|         PROTECT(__sexp_result = Rcpp::wrap(__result));<br>
|     }<br>
|     UNPROTECT(1);<br>
|     return __sexp_result;<br>
| END_RCPP<br>
| }<br>
|<br>
| This is the wrapper for this function generated with the newer Rcpp-version:<br>
| RcppExport SEXP sourceCpp_85322_shift(SEXP idxSEXP, SEXP dshiftSEXP, SEXP<br>
| nSEXP, SEXP iSEXP) {<br>
| BEGIN_RCPP<br>
|     SEXP __sexp_result;<br>
|     {<br>
|         Rcpp::RNGScope __rngScope;<br>
|         Rcpp::traits::input_parameter< const uvec& >::type idx(idxSEXP );<br>
|         Rcpp::traits::input_parameter< int >::type dshift(dshiftSEXP );<br>
|         Rcpp::traits::input_parameter< int >::type n(nSEXP );<br>
|         Rcpp::traits::input_parameter< int >::type i(iSEXP );<br>
|         uvec __result = shift(idx, dshift, n, i);<br>
|         PROTECT(__sexp_result = Rcpp::wrap(__result));<br>
|     }<br>
|     UNPROTECT(1);<br>
|     return __sexp_result;<br>
| END_RCPP<br>
| }<br>
|<br>
| The result is that the converted array idx in the newer version has apparently<br>
| different values than the the passed argument which is simply 1:10. If, for<br>
| debugging purpose, I modify the function to simply return its first argument<br>
| this is the value I'm getting:<br>
|<br>
|<br>
| > shift(1:10,5,10,1)<br>
|             [,1]<br>
|  [1,]          0<br>
|  [2,] 1072693248<br>
|  [3,]          0<br>
|  [4,] 1073741824<br>
|  [5,]          0<br>
|  [6,] 1074266112<br>
|  [7,]          0<br>
|  [8,] 1074790400<br>
|  [9,]          0<br>
| [10,] 1075052544<br>
|<br>
|<br>
| I'm running this on a 64 bit computer and I could reproduce it on Ubuntu as well.<br>
|<br>
| I guess that this behaviour is wrong.<br>
|<br>
| To check versions, here is the output of sessionInfo():<br>
|<br>
| R version 3.0.1 (2013-05-16)<br>
| Platform: x86_64-w64-mingw32/x64 (64-bit)<br>
|<br>
| locale:<br>
| [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252<br>
| [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C<br>
| [5] LC_TIME=English_United States.1252<br>
|<br>
| attached base packages:<br>
| [1] stats     graphics  grDevices utils     datasets  methods   base<br>
|<br>
| other attached packages:<br>
| [1] Rcpp_0.11.1<br>
|<br>
| loaded via a namespace (and not attached):<br>
| [1] RcppArmadillo_0.4.200.0 tools_3.0.1<br>
<br>
</div></div>It is entirely possible that something is wrong, and while you provided an<br>
appreciable level of detail, you have not provided a small, self-contained,<br>
reproducible piece of code.<br>
<br>
That would help.<br>
<br>
Below are two conversions from Armadillo 'uvec' and 'ivec'.  They work for me.<br>
<br>
<br>
R> cppFunction("SEXP uvec(int n) { arma::uvec v = arma::conv_to<arma::uvec>::from(arma::ones(n)); return(wrap(v)); }", depends="RcppArmadillo")<br>
R> uvec(3)<br>
     [,1]<br>
[1,]    1<br>
[2,]    1<br>
[3,]    1<br>
R> cppFunction("SEXP ivec(int n) { arma::ivec v = arma::conv_to<arma::ivec>::from(arma::ones(n)); return(wrap(v)); }", depends="RcppArmadillo")<br>
R> ivec(3)<br>
     [,1]<br>
[1,]    1<br>
[2,]    1<br>
[3,]    1<br>
R><br>
<br>
In both cases I use ones() to generate (double-valued) vector which I cast<br>
using Armadillo's converter function.  The resulting integer, and unsigned<br>
integer, vectors are then converted via wrap().  In both cases do the correct<br>
values appear.<br>
<br>
I probably missed a key aspect of your bug report.  Can you provide a simple example?<br>
<br>
Thanks!<br>
<br>
Dirk<br>
<br>
<br>
|<br>
|<br>
| Best,<br>
|<br>
| Venelin<br>
|<br>
|<br>
| ----------------------------------------------------------------------<br>
| _______________________________________________<br>
| Rcpp-devel mailing list<br>
| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">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><br>
<span><font color="#888888">--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
</font></span></blockquote></div></div></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><br>-- <br>Venelin MITOV<br>
</font></span></div>
</blockquote></div><br><br clear="all"><br>-- <br>Venelin MITOV<br>
</div>