bugGNU Octave - Bugs: bug #60859, sparse matrix problem with float

 
 

bug #60859: sparse matrix problem with float

Submitter:  Dmitri A. Sergatskov <dasergatskov>
Submitted:  Wed 30 Jun 2021 09:12:39 AM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Assigned to:  None
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
   

Thu 01 Jul 2021 08:34:34 PM UTC, comment #4: 

Seems like there is a potential for unexpected results here.  But, from the point of view of a developer, having the LHS fixed does make it easier.

Matlab does allow assigning of integers to sparse arrays.  I'm not that bothered about implementing it because I think this is probably a low-probability coding event that can always be solved by casting to double on the part of the programmer.

Marking the bug as fixed since the issue with floats has been dealt with.  Up to you whether you want to also implement integer assignment.

Closing report.

Rik <rik5>
Group administrator
Thu 01 Jul 2021 07:35:17 PM UTC, comment #3: 

Operations like addition with mixed double/single arguments do produce single results, but indexed assignment of single to double leaves the result as double and doesn't generate a warning.  So the behavior is consistent with what Octave and Matlab already do for full matrices.  Indexed assignment of {u,}int{8,16,32,64} values to single and double arrays is also allowed without changing the type of the LHS, and the same is true for all mixed integer assignments.

I think Matlab also allows assignment of integers to sparse arrays but I didn't add those operations in my changeset.

John W. Eaton <jwe>
Group administrator
Thu 01 Jul 2021 06:02:51 PM UTC, comment #2: 

This is expected.  Sparse matrices are only implemented for double values.

Is the expectation that the single value will be automatically converted to double?  This is what Matlab does, but I don't like that it does it without any sort of warning.

The normal rules for mathematical operations are that the result type is most restrictive possible.  So when combining singles with doubles the result is of type single.  And when combining integers with floating point the result is of type integer.


octave:5> x = double (1)
x = 1
octave:6> class (x)
ans = double
octave:7> x = x + single (2)
x = 3
octave:8> class (x)
ans = single
octave:9> x = x + uint8 (3)
x = 6
octave:10> class (x)
ans = uint8


Neither Matlab nor Octave allow the creation of a single sparse matrices.  It seems to me that an error is appropriate.  This forces the programmer to add a call to double() around the assigned value thereby reminding them that calculations will occur with doubles going forward.

Rik <rik5>
Group administrator
Thu 01 Jul 2021 05:55:24 PM UTC, comment #1: 

I pushed the following change on the default branch:

http://hg.savannah.gnu.org/hgweb/octave/rev/2ef9080ca017

Marking as ready for test.

John W. Eaton <jwe>
Group administrator
Wed 30 Jun 2021 09:12:39 AM UTC, original submission:  

As per comment 16 in https://savannah.gnu.org/bugs/?60818


octave:1> a=sparse(1)
a = Compressed Column Sparse (rows = 1, cols = 1, nnz = 1 [100%])

  (1, 1) -> 1
octave:octave:1> a=sparse(1)
a = Compressed Column Sparse (rows = 1, cols = 1, nnz = 1 [100%])

  (1, 1) -> 1
octave:2> a(1) = single(20)
error: operator =: no conversion for assignment of 'float scalar' to indexed 'sparse matrix'
2> a(1) = single(20)
error: operator =: no conversion for assignment of 'float scalar' to indexed 'sparse matrix'


This is both with 6.2.93 and with current dev tip.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>

 

(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 rik5 (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by dasergatskov (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
    2021-07-01 rik5 StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2021-07-01 rik5 StatusReady For Test Need Info
    2021-07-01 jwe StatusNone Ready For Test

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code