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


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

Submitted by:  Rik <rik5>
Submitted on:  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

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


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>
Project 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>
Wed 25 Nov 2015 08:00:05 PM UTC, original submission:

Sample code:

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.

See the related bug #42425.

Rik <rik5>
Project Administrator


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

Attach Files:

No files currently attached


   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)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project 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.4