bugGNU Octave - Bugs: bug #57909, incorrect result for sparse matrix...

 
 

bug #57909: incorrect result for sparse matrix exponentiation

Submitted by:  John W. Eaton <jwe>
Submitted on:  Thu 27 Feb 2020 05:56:23 PM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Patch Submitted Assigned to:  None
Originator Name:  jwe 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 28 Feb 2020 03:39:30 PM UTC, comment #4: 

I'm attaching a patch to fix the functions in sparse-xpow.cc.  I'll need to also add tests.  I'd be glad to see any improvements in either the algorithm or the use of templates for this function.

(file #48517)

John W. Eaton <jwe>
Project Administrator
Thu 27 Feb 2020 07:30:45 PM UTC, comment #3: 

Matlab 2019a:

>> a = sparse (4, 6);
b = sparse (4, 6);
a(2,2) = 1;
b(3,3) = 2;
a(3,4) = 3; b(2,4) = 4;
a(2,5) = 5; b(3,5) = 6;
a(4,6) = 7; b(4,6) = 8;
>> full (a .^ b)
ans =
           1           1           1           1           1           1
           1           1           1           0           1           1
           1           1           0           1           0           1
           1           1           1           1           1     5764801
>> full (a) .^ full (b)
ans =
           1           1           1           1           1           1
           1           1           1           0           1           1
           1           1           0           1           0           1
           1           1           1           1           1     5764801

>> a = sparse (0)
a =
   All zero sparse: 1×1
>> b = sparse (2)
b =
   (1,1)        2
>> a.^b
ans =
   All zero sparse: 1×1
>> 0.^2
ans =
     0

Nicholas Jankowski <nrjank>
Thu 27 Feb 2020 07:26:28 PM UTC, comment #2: 

I think the attached function does the right indexing when there is no need to convert to complex.  A proper replacement for the elem_xpow function in sparse-xpow.cc also needs to handle the complex case.  And since the indexing should be the same for the real and complex cases, maybe it should be done with a template rather than duplicating the code.

(file #48511)

John W. Eaton <jwe>
Project Administrator
Thu 27 Feb 2020 06:46:58 PM UTC, comment #1: 

Confirmed.  This doesn't appear correct.  For a more vivid example, just take one of the failing entries such as a(3,3) => 0 and b(3,3) = 2.

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

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

  (1, 1) -> 2
octave:17> a.^b
ans = Compressed Column Sparse (rows = 1, cols = 1, nnz = 1 [100%])

  (1, 1) -> 1

But, when calculated in a regular manner

octave:20> 0 .^ 2
ans = 0

Rik <rik5>
Project Administrator
Thu 27 Feb 2020 05:56:23 PM UTC, original submission:  

The element-by-element sparse exponentiation functions miss the case when the LHS is 0 and the RHS is non-zero and the result should be zero.  In the following, I believe the results should agree for both sparse and full, and that the sparse result is wrong:

a = sparse (4, 6);
b = sparse (4, 6);
a(2,2) = 1;
b(3,3) = 2;
a(3,4) = 3; b(2,4) = 4;
a(2,5) = 5; b(3,5) = 6;
a(4,6) = 7; b(4,6) = 8;
full (a .^ b) =>

         1         1         1         1         1         1
         1         1         1         1         1         1
         1         1         1         1         1         1
         1         1         1         1         1   5764801

full (a) .^ full (b) =>

         1         1         1         1         1         1
         1         1         1         0         1         1
         1         1         0         1         0         1
         1         1         1         1         1   5764801

John W. Eaton <jwe>
Project Administrator

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #48517:  sparse-pow-diffs.txt added by jwe (7KiB - text/plain)
file #48511:  sparsexpow.cc added by jwe (3KiB - text/x-c++src)

 

Depends on the following items: None found

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 (Posted a comment)
  • -email is unavailable- added by jwe (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.

     

     

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-02-28 jwe Attached File- => Added sparse-pow-diffs.txt, #48517
        StatusConfirmed => Patch Submitted
    2020-02-27 jwe Attached File- => Added sparsexpow.cc, #48511
    2020-02-27 rik5 StatusNone => Confirmed

    Back to the top


    Powered by Savane 3.5