<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Oct 31, 2015 at 3:08 PM, Alessandro Mammana <span dir="ltr"><<a href="mailto:mammana@molgen.mpg.de" target="_blank">mammana@molgen.mpg.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Dear All,<br>
When creating a large matrix with the follwing code:<br>
<br>
#include <Rcpp.h><br>
// [[Rcpp::export]]<br>
Rcpp::IntegerMatrix makeMat(int nrow, int ncol){<br>
        Rcpp::IntegerMatrix mat(nrow, ncol);<br>
        return mat;<br>
}<br>
<br>
I get the error:<br>
<br>
Error in .Primitive(".Call")(<pointer: 0x7f86936d3ea0>, nrow, ncol) :<br>
  negative length vectors are not allowed<br>
<br>
Where nrow*ncol is a very large number (about 3*10^9). I understand<br>
that such a number cannot be represented by an int type, but this does<br>
not seem to be a problem when in R I do:<br>
<br>
> mat <- matrix(0, nrow=nrow, ncol=ncol)<br>
<br></blockquote><div><br></div><div>Can you post a reproducible example? I will look into it.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Questions:<br>
1. why is the behaviour different between R and Rcpp in the allocation<br>
of a matrix?</blockquote><div><br></div><div>It should be the same (at least we want to make them same).</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
2. In a 64 bits machine, what is actually the maximum allowed length<br>
of a vector/matrix? does the length of a vector/matrix need to be<br>
represented by an int?</blockquote><div><br></div><div>The length limit is R_xlen_t, which is defined in [1]. For matrix, this limit is for the number of all elements ( nrow * ncol).</div><div><br></div><div>Best wishes,</div><div><br></div><div>KK</div><div><br></div><div>[1] <a href="https://github.com/wch/r-source/blob/trunk/src/include/Rinternals.h#L68">https://github.com/wch/r-source/blob/trunk/src/include/Rinternals.h#L68</a></div><div><br></div></div>
</div></div>