Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Subsetter indexing uses int, breaks for matrices with > MAXINT elements #919

Closed
@nolanw123

Description

@nolanw123

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.cc

Results 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp