bugGNU Octave - Bugs: bug #45963, sparse matrices with negative size

 
 

bug #45963: sparse matrices with negative size

Submitter:  None
Submitted:  Mon 14 Sep 2015 07:32:03 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * dev
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 16 Sep 2015 12:25:53 PM UTC, comment #3: 

Yes, we should detect dimensions that are out of range properly and avoid generating negative dimensions.

However, there are some other issues with dimensions of sparse matrices that tend to annoy people and that may be harder to fix.  For example, there is no problem creating the following matrix


x = sparse (1)
x(1e6, 1e6) = 1


but the expression x(:) will fail because the linear index of the last element (1e12) is too large to be an index, at least with 32-bit indexing.

John W. Eaton <jwe>
Group administrator
Tue 15 Sep 2015 11:35:33 AM UTC, comment #2: 

The erroneous behavior of comment #1 has it roots very deep inside  liboctave/array/Spase.h . There is


SparseRep (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz = 0)
  : d (nz > 0 ? new T [nz] : 0),
    r (nz > 0 ? new octave_idx_type [nz] : 0),
    c (new octave_idx_type [nc+1]), nzmx (nz), nrows (nr),
    ncols (nc), count (1)
{
  for (octave_idx_type i = 0; i < nc + 1; i++)
    c[i] = 0;
}


When you call


>> s = sparse(1e20,1)


nr = 1e20 and nc = 1 get directly forwarded from the interpreter only with a check for nonnegativity!!! If you swapped the parameters, nc = 1e20 causes the creation of a too large array and results in a bad_alloc exception.

To my opinion this is a problem that should be addressed in the dim_vector class. It should be impossible to exceed the min and max index.

Kai Torben Ohlhus <siko1056>
Group Member
Mon 14 Sep 2015 11:19:53 PM UTC, comment #1: 

Another little bug:

>> s = sparse(1e20,1)

s = Compressed Column Sparse (rows = 2147483647, cols = 1, nnz = 0 [0%])

whereas these constructors recognize the index limit.

>> s = sparse(1e20,1,0)

error: sparse: subscript indices must be either positive integers less than 2^31 or logicals

>> s = sparse(1,1e20)

error: out of memory or dimension too large for Octave's index type


Ceral Paquet <octavebugs>
Mon 14 Sep 2015 07:32:03 PM UTC, original submission:  

In both 4.0.0 and hg tip, built with default options on x86-64, the following code makes sparse matrices with a negative number of rows:


s = sparse(2e9, 1);
[s; s]
vertcat(s, s)
repmat(s, 2, 1)


Probably expected result: "error: out of memory or dimension too large for Octave's index type" from each of the three commands.

Anonymous

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by mtmiller (Updated the item)
  • -email is unavailable- added by octavebugs (Posted a comment)
  •  

    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-09-15 mtmiller StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code