<div dir="ltr"><div><div><div>Hello, <br><br></div>I have a dynamic library with C++ functions built using Rcpp. I've recently updated to the newest version of R/Rcpp/RcppArmadillo and after rebuilding my library it lost its expected behavior. After some debugging I found that one of possibly several problems is the following:<br>
<br></div>I have an exported cpp function with the following signature:<br></div><div>uvec shift(const uvec& idx, int dshift, int n, int i=1);<br><br></div><div>In my R-code I call this function as follows: <br></div>
<div>shifted_idx <- shift(1:10, 5, 10, 1). <br></div><div>This is a detail, but let me mension that all this function does is to rotate the vector of indices idx left by 5 positions, so the result should be the vector: c(6,7,8,9,10,1,2,3,4,5). <br>
</div><div><div><div><div><div><div class="gmail_extra"><br></div><div class="gmail_extra">This is the wrapper for the same function generated with the older Rcpp-version:<br>RcppExport SEXP sourceCpp_28368_shift(SEXP idxSEXP, SEXP dshiftSEXP, SEXP nSEXP, SEXP iSEXP) {<br>
BEGIN_RCPP<br>    SEXP __sexp_result;<br>    {<br>        Rcpp::RNGScope __rngScope;<br>        <b>uvec idx = Rcpp::as<uvec >(idxSEXP);</b><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><div>This is the wrapper for this function generated with the newer Rcpp-version:<br></div>RcppExport SEXP sourceCpp_85322_shift(SEXP idxSEXP, SEXP dshiftSEXP, SEXP nSEXP, SEXP iSEXP) {<br>BEGIN_RCPP<br>    SEXP __sexp_result;<br>
    {<br>        Rcpp::RNGScope __rngScope;<br>        <b>Rcpp::traits::input_parameter< const uvec& >::type idx(idxSEXP );</b><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></div><div class="gmail_extra">The result is that the converted array idx in the newer version has apparently different values than the the passed argument which is simply 1:10. If, for debugging purpose, I modify the function to simply return its first argument this is the value I'm getting:<br>
<br>
<span class="" style="border-collapse:separate;color:rgb(0,0,0);font-family:'Lucida Console';font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:12px;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;background-color:rgb(225,226,229)"><pre tabindex="0" class="" 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 class="" style="white-space:pre;color:blue">> </span><span class="" style="color:blue">shift(1:10,5,10,1)
</span>            [,1]
 [1,]          0
 [2,] 1072693248
 [3,]          0
 [4,] 1073741824
 [5,]          0
 [6,] 1074266112
 [7,]          0
 [8,] 1074790400
 [9,]          0
[10,] 1075052544<br><br></pre><pre tabindex="0" class="" 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">
I'm running this on a 64 bit computer and I could reproduce it on Ubuntu as well. <br></pre><pre tabindex="0" class="" 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">
I guess that this behaviour is wrong.<br></pre><pre tabindex="0" class="" 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">
To check versions, here is the output of sessionInfo():<br><span class="" style="border-collapse:separate;color:rgb(0,0,0);font-family:'Lucida Console';font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:12px;text-indent:0px;text-transform:none;white-space:pre-wrap;word-spacing:0px;background-color:rgb(225,226,229)"><pre tabindex="0" class="" 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">
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Rcpp_0.11.1

loaded via a namespace (and not attached):
[1] RcppArmadillo_0.4.200.0 tools_3.0.1   <br><br></pre></span><br></pre><pre tabindex="0" class="" 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 tabindex="0" class="" 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></div></div></div></div></div></div></div>