[Rcpp-devel] Overflow error when creating a large matrix
Alessandro Mammana
mammana at molgen.mpg.de
Sat Oct 31 20:08:08 CET 2015
Dear All,
When creating a large matrix with the follwing code:
#include <Rcpp.h>
// [[Rcpp::export]]
Rcpp::IntegerMatrix makeMat(int nrow, int ncol){
Rcpp::IntegerMatrix mat(nrow, ncol);
return mat;
}
I get the error:
Error in .Primitive(".Call")(<pointer: 0x7f86936d3ea0>, nrow, ncol) :
negative length vectors are not allowed
Where nrow*ncol is a very large number (about 3*10^9). I understand
that such a number cannot be represented by an int type, but this does
not seem to be a problem when in R I do:
> mat <- matrix(0, nrow=nrow, ncol=ncol)
Questions:
1. why is the behaviour different between R and Rcpp in the allocation
of a matrix?
2. In a 64 bits machine, what is actually the maximum allowed length
of a vector/matrix? does the length of a vector/matrix need to be
represented by an int?
Thanks a lot and best regards,
Alessandro
--
Alessandro Mammana, PhD Student
Max Planck Institute for Molecular Genetics
Ihnestraße 63-73
D-14195 Berlin, Germany
More information about the Rcpp-devel
mailing list