bugGNU Octave - Bugs: bug #66488, qr( sparse, 0) isn't equal to qr(...

 
 

bug #66488: qr( sparse, 0) isn't equal to qr( sparse, 'econ', 'vector')

Submitter:  None
Submitted:  Thu 28 Nov 2024 01:52:53 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Andy Adler Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 9.2.0
Operating System:  * GNU/Linux Fixed Release:  10.1.0 (current default)
Planned Release:  10.1.0 (current default)
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 03 Dec 2024 09:50:05 PM UTC, comment #19: 

I think this is bug report is settled so I'm marking as Fixed and closing report.

Rik <rik5>
Group administrator
Mon 02 Dec 2024 06:27:34 PM UTC, comment #18: 

Well, apparently CXSPARSE does compute QR decomposition with two outputs, but not with three outputs.


[q,r,p] = qr (speye (3))
q =

  -1   0   0
   0  -1   0
   0   0  -1

r =

Compressed Column Sparse (rows = 3, cols = 3, nnz = 3 [33%])

  (1, 1) -> -1
  (2, 2) -> -1
  (3, 3) -> -1

p = Compressed Column Sparse (rows = 0, cols = 0, nnz = 0)


This is a whole different issue from the one here and I will open a new bug report for that.

Rik <rik5>
Group administrator
Mon 02 Dec 2024 05:33:44 PM UTC, comment #17: 

I see the same on Centos 9.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 02 Dec 2024 05:27:29 PM UTC, comment #16: 

Oops, a typo.  I meant without SPQR.

Interestingly, there is a subtle difference.

With SPQR & CHOLMOD:


octave:1> [q,r] = qr (speye (3))
q =

   1   0   0
   0   1   0
   0   0   1

r =

Compressed Column Sparse (rows = 3, cols = 3, nnz = 3 [33%])

  (1, 1) -> 1
  (2, 2) -> 1
  (3, 3) -> 1


With CXSPARSE


octave:1> [q,r] = qr (speye (3))
q =

  -1   0   0
   0  -1   0
   0   0  -1

r =

Compressed Column Sparse (rows = 3, cols = 3, nnz = 3 [33%])

  (1, 1) -> -1
  (2, 2) -> -1
  (3, 3) -> -1


The multiplication of Q and R recovers the original matrix, but with CXSPARSE each of the matrices has been multiplied by -1.

Rik <rik5>
Group administrator
Mon 02 Dec 2024 05:15:11 PM UTC, comment #15: 

Ah. Now I got your previous question:

For our CI with Clang on Linux:

The buildbots build with SPQR and with CXSparse on Debian. They don't show that issue.
The GitHub runners build without SPQR but with CXSparse on Ubuntu. They return the odd results for p.

Markus Mützel <mmuetzel>
Group administrator
Mon 02 Dec 2024 05:12:08 PM UTC, comment #14: 


> I'll try building my local version with SPQR and see if it picks up CXSPARSE instead.


I might be misunderstanding that sentence. But to try to reproduce, you might need to configure with `--without-spqr`.

Markus Mützel <mmuetzel>
Group administrator
Mon 02 Dec 2024 05:07:49 PM UTC, comment #13: 

The test was failing with a return value for p of [0, 0] which implies to me that the external library didn't work at all.  If it was merely an orientation issue it should have returned either a column vector or a row vector.

When using SPQR the CHOLMOD library is also required.  Alternatively, CXSPARSE is required.  But maybe this is a corner case where SPQR was installed and our code only checked that one prerequisite and didn't check for CHOLMOD.

I'll try building my local version with SPQR and see if it picks up CXSPARSE instead.

Rik <rik5>
Group administrator
Mon 02 Dec 2024 04:48:43 PM UTC, comment #12: 

AFAICT, the buildbots that are compiling with clang++ are still using the C++ library from GCC (i.e., libstdc++). So, there is no issue with linking to C++ libraries that are packaged by Debian.
And SPQR is appearing in the configure summary:
https://buildbot.octave.org/#/builders/19/builds/1134/steps/5/logs/stdio

  SPQR CPPFLAGS:                 -I/usr/include/suitesparse
  SPQR LDFLAGS:
  SPQR libraries:                -lspqr


I seem to recall that we intentionally configured the GitHub CI to use the C++ library from LLVM (i.e., libc++) instead to get better coverage.

That GitHub runner should have used CXSparse instead:
https://github.com/gnu-octave/octave/actions/runs/12092031603/job/33721233088#step:8:1171

    CXSPARSE CPPFLAGS:
    CXSPARSE LDFLAGS:
    CXSPARSE libraries:            -lcxsparse


Is it expected that `qr` gives different results depending on whether the internal implementation happens to use SPQR or CXSparse?

Markus Mützel <mmuetzel>
Group administrator
Mon 02 Dec 2024 04:37:37 PM UTC, comment #11: 

The problem is the lack of SPQR.  Either SPQR or CXSPARSE is required for the qr operation on sparse matrices.  I will break this test into two and protect the sparse tests with a %!testif.

Do you know if the Clang buildbots are also building without CXSPARSE?

I checked in an update for the BIST tests here (https://hg.savannah.gnu.org/hgweb/octave/rev/306a5e05f366).

Rik <rik5>
Group administrator
Mon 02 Dec 2024 09:08:12 AM UTC, comment #10: 

It looks like this caused (or revealed?) test errors on the Ubuntu runners using Clang:
https://github.com/gnu-octave/octave/actions/runs/12092031603/job/33721233088#step:13:65340

>>>>> processing /home/runner/work/octave/octave/.build/libinterp/corefcn/qr.cc-tst
***** test <*66488>
 ## Orientation of 'p' output
 [q, r, p] = qr (eye (3));
 assert (size (p), [3, 3]);
 [q, r, p] = qr (speye (3));
 assert (size (p), [3, 3]);
 [q, r, p] = qr (eye (3), 'vector');
 assert (size (p), [1, 3]);
 [q, r, p] = qr (speye (3), 'vector');
 assert (size (p), [1, 3]);
 [q, r, p] = qr (eye (3), 'econ');
 assert (size (p), [3, 3]);
 [q, r, p] = qr (speye (3), 'econ');
 assert (size (p), [3, 3]);
 [q, r, p] = qr (eye (3), 0);
 assert (size (p), [1, 3]);
 [q, r, p] = qr (speye (3), 0);
 assert (size (p), [1, 3]);
!!!!! regression: https://octave.org/testfailure/?66488
ASSERT errors for:  assert (size (p),([3, 3]))

  Location  |  Observed  |  Expected  |  Reason
    (1)           0            3         Abs err 3 exceeds tol 0 by 3
    (2)           0            3         Abs err 3 exceeds tol 0 by 3


Maybe relevant: These runners build without SPQR (because of incompatibilities between libstdc++ that is used by the SPQR library distributed by Ubuntu and libc++ that is used to build Octave on that runner configuration).

Markus Mützel <mmuetzel>
Group administrator
Sat 30 Nov 2024 12:30:10 AM UTC, comment #9: 

This turned into quite the project.  I checked in a changeset (https://hg.savannah.gnu.org/hgweb/octave/rev/5cf01b10fe10) which overhauls the qr function.  It now treats argument '0' as the equivalent of "econ" + "vector".  When a permutation vector is requested, it is now always a row vector for compatibility with Matlab.  The documentation has been updated.  I also added a BIST test for this bug report.

Marking as Ready For Test.

Rik <rik5>
Group administrator
Fri 29 Nov 2024 06:16:38 PM UTC, comment #8: 

With Matlab R2024b:

>> [q,r,p] = qr(speye(3),'econ')

q =

  3×3 sparse double matrix (3 nonzeros)

   (1,1)        1
   (2,2)        1
   (3,3)        1


r =

  3×3 sparse double matrix (3 nonzeros)

   (1,1)        1
   (2,2)        1
   (3,3)        1


p =

  3×3 sparse double matrix (3 nonzeros)

   (1,1)        1
   (2,2)        1
   (3,3)        1

>> [q,r,p] = qr(eye(3),'econ')

q =

     1     0     0
     0     1     0
     0     0     1


r =

     1     0     0
     0     1     0
     0     0     1


p =

     1     0     0
     0     1     0
     0     0     1

>>


Markus Mützel <mmuetzel>
Group administrator
Fri 29 Nov 2024 09:47:20 AM UTC, comment #7: 

R2019b (which doesn't support an 'econ' option) reports the below.

The 'econ' argument was introduced in R2022a. qr( ... , 0) is apparently equivalent to qr(.., 'econ', 'vector') according to TMW documentation, so ,0) not exactly the same as ,'econ')


>> version
ans =
    '9.7.0.1190202 (R2019b)'
>> [q,r,p] = qr(speye(3),0)
q =
   (1,1)        1
   (2,2)        1
   (3,3)        1
r =
   (1,1)        1
   (2,2)        1
   (3,3)        1
p =
     1     2     3
>> [q,r,p] = qr(eye(3),0)
q =
     1     0     0
     0     1     0
     0     0     1
r =
     1     0     0
     0     1     0
     0     0     1
p =
     1     2     3


A.R. Burgers <arb>
Thu 28 Nov 2024 10:25:06 PM UTC, comment #6: 

Under R2024b:

>> [q,r,p] = qr(eye(3),'econ')

q =
     1     0     0
     0     1     0
     0     0     1
r =
     1     0     0
     0     1     0
     0     0     1
p =
     1     0     0
     0     1     0
     0     0     1

Anonymous
Thu 28 Nov 2024 10:20:06 PM UTC, comment #5: 

I need the same test I requested in comment #4 with a dense matrix.


[q,r,p] = qr(eye(3),'econ')


Rik <rik5>
Group administrator
Thu 28 Nov 2024 10:15:43 PM UTC, comment #4: 

Could someone test the following code in Matlab?


[q,r,p] = qr(speye(3),'econ')



Rik <rik5>
Group administrator
Thu 28 Nov 2024 07:10:24 PM UTC, comment #3: 

There does seem to be some inconsistencies here.  First, the argument "0" is not equivalent to "vector".  For Octave, "0" is equivalent to "econ".  However, for Matlab "0" is equivalent to the two additional arguments "econ" and "vector".  I've changed the Item Group to "Matlab Compatibility" to reflect that.

Second, Octave's input validation is bad because it throws an error when trying to use more than one additional string argument.


[q3,r3,p3] = qr(speye(3),'econ', 'vector')
error: invalid conversion from string to real matrix


I expect that fixes will need to go on the development branch.

Rik <rik5>
Group administrator
Thu 28 Nov 2024 11:28:39 AM UTC, comment #2: 

Matlab reports:

>> size(zzz)                                                  

ans =                                                         
     3     3  

The main issue I'm worried about is that
  qr( ..., 0) is supposed to be the same as qr( ..., 'vector')
It is for full matrices, but not for sparse.

This lead to a bug in eidors, which we fixed by using the 'vector' form. However, the documentation says they're the same.

Anonymous
Thu 28 Nov 2024 02:56:38 AM UTC, comment #1: 

What does matlab report for:

zzz = speye(3)
size(zzz)


?

Dmitri.
--


Dmitri A. Sergatskov <dasergatskov>
Thu 28 Nov 2024 01:52:53 AM UTC, original submission:  

qr( ...,0) should be equal to qr( ..., 'vector').
But we have
 [q,r,p]= qr(speye(3),'vector'); size(p) % 3x1, but matlab is 1x3
 [q,r,p]= qr(speye(3),0); size(p)        % 3x3, but matlab is 1x3
However, this is OK for non-sparse qr
 [q,r,p]= qr(eye(3),'vector'); size(p) % 3x1, correct
 [q,r,p]= qr(eye(3),0); size(p)        % 3x1, correct
Tests in octave 9.2:
 [q,r,p]= qr(speye(3)); % correct
 [q,r,p]= qr(eye(3)); % correct

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 mmuetzel (Posted a comment)
  • -email is unavailable- added by arb (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by None (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 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-12-03 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2024-11-30 rik5 StatusConfirmed Ready For Test
        Fixed ReleaseNone 10.1.0 (current default)
    2024-11-28 rik5 Planned ReleaseNone 10.1.0 (current default)
        Summaryqr( sparse, 0) isn't equal to qr( sparse, 'vector') qr( sparse, 0) isn't equal to qr( sparse, 'econ', 'vector')
        Item GroupIncorrect Result Matlab Compatibility
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.14-f13d.
    Corresponding source code