Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork219
Closed
Description
Various parts of Subsetter use int for indexing instead of R_xlen_t, causing it to break for matrices with > MAXINT elements (x86_64 arch).
Example (subset.cc) below:
//// Reproduce subsetting error caused by use of int type for indexing.// NB requires > 16GB of memory to execute.//#include<Rcpp.h>#include<RInside.h>usingnamespaceRcpp;voidtestMat(size_t nrow_,size_t ncol_){ std::cout <<"Testing" << nrow_ <<" x" << ncol_ <<" matrix subsetting." << std::endl;if(static_cast<int>(nrow_ * ncol_) <0) std::cout <<"Should throw exception as total # of elements exceeds MAXINT on this system." << std::endl; NumericMatrixm(nrow_, ncol_); std::cout <<"Allocated" << m.nrow() <<" x" << m.ncol() <<" matrix." << std::endl;auto sz = m.size();if(sz != nrow_ * ncol_)throwstd::runtime_error("Total # of elements incorrect"); std::cout <<"Matrix size is" << sz << std::endl; IntegerVectorsub(1);// all we need is one attempt to subset for it to fail sub[0] =0;static_cast<NumericVector &>(m)[sub] =0; std::cout <<"Completed test of" << m.nrow() <<" x" << m.ncol() <<" matrix." << std::endl;}intmain(int argc_,char **argv_){ RInside R;try {testMat(10,10); }catch(std::exception &e) { std::cerr <<"Caught exception '" << e.what() <<"', exiting." << std::endl; }try {testMat(65536,32768); }catch(std::exception &e) { std::cerr <<"Caught exception '" << e.what() <<"', exiting." << std::endl; }}
Compiled via:
g++ -g --std=c++11 $(R CMD config --cppflags) $(R CMD config --ldflags) $(echo 'Rcpp:::CxxFlags()' | $(R RHOME)/bin/R --vanilla --slave) $(echo 'Rcpp:::LdFlags()' | $(R RHOME)/bin/R --vanilla --slave) $(echo 'RInside:::CxxFlags()' | $(R RHOME)/bin/R --vanilla --slave) $(echo 'RInside:::LdFlags()' | $(R RHOME)/bin/R --vanilla --slave) subset.ccResults from running a.out:
[nolanw@jerry ~]$ ./a.outTesting 10 x 10 matrix subsetting.Allocated 10 x 10 matrix.Matrix size is 100Completed test of 10 x 10 matrix.Testing 65536 x 32768 matrix subsetting.Should throw exception as total # of elements exceeds MAXINT on this system.Allocated 65536 x 32768 matrix.Matrix size is 2147483648Caught exception 'index error', exiting.Will try to put together a fix to revamp Subsetter to use the R_xlen_t internally.
Metadata
Metadata
Assignees
Labels
No labels