bugGNU Octave - Bugs: bug #46533, numel() returns negative values...

 
 

bug #46533: numel() returns negative values for large diagonal matrices

Submitter:  Rik <rik5>
Submitted:  Wed 25 Nov 2015 08:00:05 PM UTC
   
 
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 04 Dec 2015 11:34:33 PM UTC, comment #2: 

@Nicholas: I also had the same idea.  The issue is that internally the numel() function has been defined to return octave_idx_t which is either 2^31 or 2^63 depending on whether you have 64-bit indexing compiled in.  Changing it will involve touching a lot of files and before doing that it would be good to get sign off from jwe and others on the Octave Maintainer's list.  It does seem like the easiest solution though.

Rik <rik5>
Group administrator
Fri 04 Dec 2015 10:36:59 PM UTC, comment #1: 

a quick check in both octave and matlab shows that numel output is a double. so is the issue just that the row*column step is starting with uint32 numbers and trying to keeping it that way? knowing that numel should be able to get bigger than the index limit, can numel be patched to internally class change to double before whatever arithmetic is causing a problem so this becomes a non-issue? it's coming out as a double... does it matter where the class change happens?

(I did play with matlab 2015b and created a 10000x10000x100x100 array of logicals.  numel(x) output 1e11 without error)

Nicholas Jankowski <nrjank>
Group Member
Wed 25 Nov 2015 08:00:05 PM UTC, original submission:  

Sample code:


octave:2> x = eye (1e6, 1e6);
octave:3> typeinfo (x)
ans = diagonal matrix
octave:4> numel (x)
ans = -727379968


The problem is that the simple calculation of the number of elements is rows*columns which is 1e12 in this example.  The ordinary octave_idx_type is 2^31, or ~2e9, so the value rolls over into negative numbers.

Diagonal matrices are a sort of compressed, sparse implementation of a matrix.  Perhaps they should do what the existing sparse code does which is return an error message.


octave:1> x = speye (1e6,1e6);
octave:2> numel (x)
error: out of memory or dimension too large for Octave's index type


See the related bug #42425.

Rik <rik5>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Digest:
   bug dependencies.

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by rik5 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-11-25 rik5 Dependencies- Depends on bugs #42425

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code