From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch  Thu Jun 10 09:13:09 2021
From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler)
Date: Thu, 10 Jun 2021 09:13:09 +0200
Subject: [Rd] dgTMatrix Segmentation Fault
In-Reply-To: <d8ed920a-d993-eae0-8229-699846849b74@gmail.com>
References: <SYBPR01MB4761C684F1CA43CA4945FA25CD389@SYBPR01MB4761.ausprd01.prod.outlook.com>
 <91d30364-998a-c783-b9c5-9b05405d30b2@insa-toulouse.fr>
 <SYBPR01MB4761A3436511885B1346831ACD379@SYBPR01MB4761.ausprd01.prod.outlook.com>
 <24767.39822.987117.724657@stat.math.ethz.ch>
 <661d72aa-655e-68ac-edfe-e37e9d39c6b8@insa-toulouse.fr>
 <SYBPR01MB4761734287C9B00F00B2BD9ACD369@SYBPR01MB4761.ausprd01.prod.outlook.com>
 <d8ed920a-d993-eae0-8229-699846849b74@gmail.com>
Message-ID: <24769.48005.562512.857009@stat.math.ethz.ch>

>>>>> Ben Bolker 
>>>>>     on Wed, 9 Jun 2021 21:11:18 -0400 writes:

    > Nice!

Indeed -- and thanks a lot, Dario (and Martin Morgan !) for
getting down to the root problem.

so, indeed a bug in Matrix (though "far away" from 'dgTMatrix').

Thank you once more!

Martin Maechler

    > On 6/9/21 9:00 PM, Dario Strbenac via R-devel wrote:
    >> Good day,
    >> 
    >> Thanks to handy hints from Martin Morgan, I ran R under gdb and checked for any numeric overflow. We pinpointed the cause:
    >> 
    >> (gdb) info locals
    >> i = 0
    >> j = 10738
    >> m = 200000
    >> n = 50000
    >> ans = 0x55555b332790
    >> aa = 0x55555b3327c0
    >> 
    >> There is a line of C code in dgeMatrix.c for (i = 0; i < m; i++) aa[i] += xx[i + j * m];
    >> 
    >> i  + j * m are all int, and overflow
    >> (lldb) print 0 + 10738 * 200000
    >> (int) $5 = -2147367296
    >> 
    >> So, either the code should check that this doesn't occur, or be adjusted to allow for large indexes.
    >> 
    >> If anyone is interested, this is in the context of single-cell ATAC-seq data, which typically has about 200000 genomic regions (rows) and perhaps 100000 biological cells (columns).
    >> 
    >> --------------------------------------
    >> Dario Strbenac
    >> University of Sydney
    >> Camperdown NSW 2050
    >> Australia
    >> ______________________________________________
    >> R-devel at r-project.org mailing list
    >> https://stat.ethz.ch/mailman/listinfo/r-devel
    >> 

    > ______________________________________________
    > R-devel at r-project.org mailing list
    > https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] dgTMatrix Segmentation Fault
Martin Maechler