octave-bug-tracker
[Top][All Lists]

## [Octave-bug-tracker] [bug #50575] Integer overflow in whos when calculat

 From: Colin Macdonald Subject: [Octave-bug-tracker] [bug #50575] Integer overflow in whos when calculating total elements in sparse matrices Date: Thu, 23 Aug 2018 13:38:43 -0400 (EDT) User-agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0

```Follow-up Comment #6, bug #50575 (project octave):

Matlab 2014a:

>> [a, maxint] = computer()
a =
GLNXA64
maxint =
2.8147e+14

>> A = sprand(1e13, 1e7, 1e-15);

>> nnz(A)
ans =
100000

>> size(A)
ans =
1e+13        1e+07

>> numel(A)
Warning: Number of elements exceeds maximum flint 2^53-1.
The result may be inaccurate.
ans =
1e+20

>> whos
Name                   Size                     Bytes  Class     Attributes

A         10000000000000x10000000            81600008  double    sparse

(Notice they warn in numel when > flintmax.  This seems like a good idea,
especially with 64-bit indexing: I will file different issue.)

Note, they can linear index into such a large matrix, the condition is just
that that linear index itself cannot be larger than maxint:

>> A(10,10)
ans =
All zero sparse: 1-by-1

>> A(100)
ans =
All zero sparse: 1-by-1

>> A(1234567)
ans =
All zero sparse: 1-by-1

>> i = 282*int64(1000)^4 + 123
i =
282000000000123

>> A(i)
Maximum variable size allowed by the program is exceeded.

>> # note i is just slightly larger than maxint
>> double(i)
ans =
2.82e+14
>> maxint
maxint =
2.8147e+14

_______________________________________________________

<http://savannah.gnu.org/bugs/?50575>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

```