[Rcpp-devel] Broken conversion from R-type integer to uvec after update to newer Rcpp version
Venelin Mitov
vmitov at gmail.com
Sun Apr 20 15:18:58 CEST 2014
Hello,
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:
I have an exported cpp function with the following signature:
uvec shift(const uvec& idx, int dshift, int n, int i=1);
In my R-code I call this function as follows:
shifted_idx <- shift(1:10, 5, 10, 1).
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).
This is the wrapper for the same function generated with the older
Rcpp-version:
RcppExport SEXP sourceCpp_28368_shift(SEXP idxSEXP, SEXP dshiftSEXP, SEXP
nSEXP, SEXP iSEXP) {
BEGIN_RCPP
SEXP __sexp_result;
{
Rcpp::RNGScope __rngScope;
*uvec idx = Rcpp::as<uvec >(idxSEXP);*
int dshift = Rcpp::as<int >(dshiftSEXP);
int n = Rcpp::as<int >(nSEXP);
int i = Rcpp::as<int >(iSEXP);
uvec __result = shift(idx, dshift, n, i);
PROTECT(__sexp_result = Rcpp::wrap(__result));
}
UNPROTECT(1);
return __sexp_result;
END_RCPP
}
This is the wrapper for this function generated with the newer Rcpp-version:
RcppExport SEXP sourceCpp_85322_shift(SEXP idxSEXP, SEXP dshiftSEXP, SEXP
nSEXP, SEXP iSEXP) {
BEGIN_RCPP
SEXP __sexp_result;
{
Rcpp::RNGScope __rngScope;
*Rcpp::traits::input_parameter< const uvec& >::type idx(idxSEXP );*
Rcpp::traits::input_parameter< int >::type dshift(dshiftSEXP );
Rcpp::traits::input_parameter< int >::type n(nSEXP );
Rcpp::traits::input_parameter< int >::type i(iSEXP );
uvec __result = shift(idx, dshift, n, i);
PROTECT(__sexp_result = Rcpp::wrap(__result));
}
UNPROTECT(1);
return __sexp_result;
END_RCPP
}
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:
> shift(1:10,5,10,1) [,1]
[1,] 0
[2,] 1072693248
[3,] 0
[4,] 1073741824
[5,] 0
[6,] 1074266112
[7,] 0
[8,] 1074790400
[9,] 0
[10,] 1075052544
I'm running this on a 64 bit computer and I could reproduce it on
Ubuntu as well.
I guess that this behaviour is wrong.
To check versions, here is the output of sessionInfo():
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
Best,
Venelin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140420/7d3c2870/attachment.html>
More information about the Rcpp-devel
mailing list