Registered Member
|
I'm trying to use the SparseQR class, but I'm having trouble extracting the Q matrix as a sparse matrix (as per the documentation).
Here's my small reproducible example:
But upon running this I get the following error from the Q = qr.matrixQ() line:
Am I calling this incorrectly? I would like to extract Q as a A.rows() by A.rows() sparse matrix. Is there another way to do it? |
Registered Member
|
Seems like it could be an issue that A is rectangular. Replacing SparseMatrix<double> A(377,1); with SparseMatrix<double> A(377,377); makes the code above work.
|
Registered Member
|
If I ignore the warning (compile with -DNDEBUG) then it seems to work. In the sense that Q * R = A. But Q seems to be effectively dense! The first rank() rows of Q are sparse numerically, but the SparseMatrix seems to be actually storing all of the zeros.
So for the example above, the following:
Prints:
|
Moderator
|
Thanks for the precise report. Both issues are fixed in the devel branch:
https://bitbucket.org/eigen/eigen/commits/bd3786d25064/ https://bitbucket.org/eigen/eigen/commits/744b1d67f0d1/ |
Registered Member
|
Thanks. This helps. However, it seems that extracting matrixQ still results in an effectively dense operation. I tracked it down to the SparseQR_QProduct::evalTo in SparseQR/SparseQR.h around line 563. There are two nested for loops and a dot product at the innermost level. This dot product (though sparse) seems effectively dense. Causing this evalTo to be O(n^3) where n is the number of cols in Q rather than what I hoped would be more like O(nnz) where nnz is the number of non zeros in Q.
Here's a concrete example (forgive the inline matrix entries, but it gives a real-world example):
|
Moderator
|
You're right. I've updated the related bug entry so that we don't forget: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=596, but I cannot say when this will be implemented.
|
Registered Member
|
Any update on this sparse Q extraction problem? Still itching for a solution. It'd be nice not to rely on external libraries for sparse QR. Thanks.
|
Registered Member
|
Hi,
I also have a problem recovering sparse Q from the solver. In my case I can't even get the assignment to compile as the SparseQR<SparseMatrix<double>, NaturalOrdering<int> >::QRMatrixType and SparseMatrix<double> are not compatible.
This line of code gives me the following error.
I work on Windows and I use MSVC 14.0. Is there any workaround for this? I tried the following:
This has a similar template incompatibility issue.
This one compiles takes forever and does not seem to finish. (I tried to let it run overnight). I really need to recover the Q matrix as I need to save it to a file for a later use as I have a big matrix (around 42000 rows and 20000 cols with quite irregular sparsity pattern) and the factorization takes a long time. |
Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]