<div dir="ltr">Hi, Alessandro,<div><br></div><div>I have confirmed and reproduced your error. </div><div><br></div><div>It should be a bug and it is in <a href="https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/vector/MatrixColumn.h#L39">https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/vector/MatrixColumn.h#L39</a></div><div><br></div><div>In your case, i and n both are integers, but i * n caused an overflow. We will fix this soon.</div><div><br></div><div>Thank you for the test on big vector and matrix. More test will be truly appreciated.</div><div><br></div><div>Best wishes,</div><div><br></div><div>KK</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 1, 2015 at 5: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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I got another error when using the Matrix.column() function, as in the<br>
code below:<br>
<br>
#include <Rcpp.h><br>
#include "array.cpp"<br>
// [[Rcpp::export]]<br>
Rcpp::IntegerMatrix makeMat(int nrow=18, int ncol=136633572){<br>
        Rcpp::IntegerMatrix mat(nrow, ncol);<br>
        for (int i = 0; i < ncol; ++i) {<br>
                Rcpp::MatrixColumn<INTSXP> col = mat.column(i);<br>
                for (int j = 0; j < nrow; ++j){<br>
                        col[j] = 1;<br>
                }<br>
        }<br>
        return mat;<br>
}<br>
<br>
Then in R:<br>
<br>
> library(Rcpp)<br>
> sourceCpp("makeMat.cpp")<br>
> mat <- makeMat()<br>
<br>
 *** caught segfault ***<br>
address 0x7f4c1e825088, cause 'memory not mapped'<br>
<br>
Traceback:<br>
 1: .Primitive(".Call")(<pointer: 0x7f5068e0cee0>, nrow, ncol)<br>
 2: makeMat()<br>
<br>
<br>
If I had to guess, the column function is doing the multiplication<br>
i*nrow and storing it as an int, which overflows when i is big. I am<br>
sorry that I cannot point to the Rcpp code where this happens and<br>
propose the fix, I am sitting on a chair with my laptop on my legs,<br>
not quite convenient for programming :D.<br>
<br>
Best,<br>
Alessandro<br>
<br>
On Sun, Nov 1, 2015 at 7:35 PM, Alessandro Mammana<br>
<div class="HOEnZb"><div class="h5"><<a href="mailto:mammana@molgen.mpg.de">mammana@molgen.mpg.de</a>> wrote:<br>
> As Sean O'Riordain correctly pointed out, I used the install_github<br>
> command improperly. Doing<br>
><br>
> devtools::install_github("RcppCore/Rcpp")<br>
><br>
> works and the big matrix is allocated correctly.<br>
><br>
> Thanks for the help and for the great work you are doing!<br>
> Ale<br>
><br>
> On Sun, Nov 1, 2015 at 6:30 PM, Alessandro Mammana<br>
> <<a href="mailto:mammana@molgen.mpg.de">mammana@molgen.mpg.de</a>> wrote:<br>
>> It's great that R and Rcpp have support for long vectors! that makes<br>
>> my life so much easier!<br>
>><br>
>> So I installed Rcpp version 0.12.1 and the error is still there (see<br>
>> end of the email). If I interpret the commit history correctly, the<br>
>> commit that fixes the bug was done shortly after the 0.12.1 release<br>
>> right? Is there an easy way of getting the latest version of the<br>
>> master branch?<br>
>> I tried:<br>
>><br>
>> devtools::install_github("<a href="https://github.com/RcppCore/Rcpp" rel="noreferrer" target="_blank">https://github.com/RcppCore/Rcpp</a>")<br>
>><br>
>> But I got:<br>
>><br>
>> Error in username %||% getOption("github.user") %||% stop("Unknown username.") :<br>
>>   Unknown username.<br>
>><br>
>>> sourceCpp("makeMat.cpp")<br>
>>> makeMat(18, 136633572)<br>
>> Error in .Primitive(".Call")(<pointer: 0x7f57d1c73ee0>, nrow, ncol) :<br>
>>   negative length vectors are not allowed<br>
>>> sesssionInfo()<br>
>> Error: could not find function "sesssionInfo"<br>
>>> sessionInfo()<br>
>> R version 3.2.0 (2015-04-16)<br>
>> Platform: x86_64-unknown-linux-gnu (64-bit)<br>
>> Running under: MarIuX64 2.0 GNU/Linux 2010-2012<br>
>><br>
>> locale:<br>
>>  [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C<br>
>>  [4] LC_COLLATE=C         LC_MONETARY=C        LC_MESSAGES=C<br>
>>  [7] LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C<br>
>> [10] LC_TELEPHONE=C       LC_MEASUREMENT=C     LC_IDENTIFICATION=C<br>
>><br>
>> attached base packages:<br>
>> [1] stats     graphics  grDevices utils     datasets  methods   base<br>
>><br>
>> other attached packages:<br>
>> [1] Rcpp_0.12.1<br>
>><br>
>> On Sun, Nov 1, 2015 at 3:37 PM, Florian Plaza Oñate<br>
>> <<a href="mailto:florian.plaza@jouy.inra.fr">florian.plaza@jouy.inra.fr</a>> wrote:<br>
>>> The bug is probably fixed by this commit:<br>
>>> <a href="https://github.com/RcppCore/Rcpp/commit/eb069bf5c20aaa4d38e0ca2897bf04e956cb8c4c" rel="noreferrer" target="_blank">https://github.com/RcppCore/Rcpp/commit/eb069bf5c20aaa4d38e0ca2897bf04e956cb8c4c</a><br>
>>><br>
>>><br>
>>> Le 31/10/2015 20:08, Alessandro Mammana a écrit :<br>
>>>><br>
>>>> 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>
>>>><br>
>>>> Questions:<br>
>>>> 1. why is the behaviour different between R and Rcpp in the allocation<br>
>>>> of a matrix?<br>
>>>> 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?<br>
>>>><br>
>>>> Thanks a lot and best regards,<br>
>>>> Alessandro<br>
>>>><br>
>>><br>
>><br>
>><br>
>><br>
>> --<br>
>> Alessandro Mammana, PhD Student<br>
>> Max Planck Institute for Molecular Genetics<br>
>> Ihnestraße 63-73<br>
>> D-14195 Berlin, Germany<br>
><br>
><br>
><br>
> --<br>
> Alessandro Mammana, PhD Student<br>
> Max Planck Institute for Molecular Genetics<br>
> Ihnestraße 63-73<br>
> D-14195 Berlin, Germany<br>
<br>
<br>
<br>
--<br>
Alessandro Mammana, PhD Student<br>
Max Planck Institute for Molecular Genetics<br>
Ihnestraße 63-73<br>
D-14195 Berlin, Germany<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Qiang Kou<div><a href="mailto:qkou@umail.iu.edu" target="_blank">qkou@umail.iu.edu</a><br><div>School of Informatics and Computing, Indiana University</div><div><br></div></div></div></div>
</div>