bugGNU Octave - Bugs: bug #37774, Slicing sparse matrix gives wrong...

 
 

bug #37774: Slicing sparse matrix gives wrong result

Submitter:  Kim Rydhof Thor Hansen <kimhanse>
Submitted:  Mon 19 Nov 2012 06:36:39 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  dbateman
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 22 Jun 2013 10:11:54 AM UTC, comment #1: 

The two index version of the Sparse<T>:index for column vectors calls the single index method. In the case of a scalar stored as a sparse matrix the single index version of Sparse<T>::index specialised the method, and some information on the form of the desired return matrix was lost when handing the two index version happen the problem off to the single index version.

This is not the first bug report for the special cases of scalars stored as sparse matrices and I'm inclined to just treat this case the same way the octave treats the indexing of scalars, that is it casts them to matrices and then index them. In this manner the results will be automatically consistent between sparse and full matrices

As a scalar stored as a sparse matrx takes significantly more memory than a scalar stored in a matrix, we're probably better off just densifying the matrix and calling the dense index function on it and resparsifying the returned matrix in any case in terms of performance.

See the changeset

http://hg.savannah.gnu.org/hgweb/octave/rev/f4eef73b6e90

D.

David Bateman <dbateman>
Group Member
Mon 19 Nov 2012 06:36:39 PM UTC, original submission:  

"sparse(zeros(1))(false,:)" gives a 0x0 matrix, I think this it should give a 0x1 matrix.

Running the following:


zeros(0)(false,:)
zeros(1)(false,:)
zeros(2)(false,:)
zeros(3)(false,:)
sparse(zeros(0))(false,:)
sparse(zeros(1))(false,:)
sparse(zeros(2))(false,:)
sparse(zeros(3))(false,:)


gives this result on newest octave:


octave:1> zeros(0)(false,:)
ans = [](0x0)
octave:2> zeros(1)(false,:)
ans = [](0x1)
octave:3> zeros(2)(false,:)
ans = [](0x2)
octave:4> zeros(3)(false,:)
ans = [](0x3)
octave:5> sparse(zeros(0))(false,:)
ans = Compressed Column Sparse (rows = 0, cols = 0, nnz = 0)

octave:6> sparse(zeros(1))(false,:)
ans = Compressed Column Sparse (rows = 0, cols = 0, nnz = 0)   << ERROR HERE

octave:7> sparse(zeros(2))(false,:)
ans = Compressed Column Sparse (rows = 0, cols = 2, nnz = 0)

octave:8> sparse(zeros(3))(false,:)
ans = Compressed Column Sparse (rows = 0, cols = 3, nnz = 0)

octave:9>


Kim Rydhof Thor Hansen <kimhanse>

 

(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 dbateman (Posted a comment)
  • -email is unavailable- added by jordigh (Updated the item)
  • -email is unavailable- added by kimhanse (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.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-06-22 dbateman StatusConfirmed Fixed
        Assigned toNone dbateman
        Open/ClosedOpen Closed
    2012-11-19 jordigh StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code