Wrong results of SparseQR for non-square matrices
Submitted by Henrik Friberg
Assigned to Nobody
Link to original bugzilla bug (#836)
Version: 3.2
Description
I suspect the SparseQR module was never tested for non-square matrices.
Example 1:
Take the code at end of this bugreport with
A << 1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 1;
Not only is AP not equal to QR in code below, but I also get
QR.matrixQ().rows() = 3,
QR.matrixQ().cols() = 4,
while,
Q.rows() = 3,
Q.cols() = 3,
and
QR.matrixR().rows() = 4,
QR.matrixR().cols() = 4.
This is the example should be easy to debug because there should essentially be nothing going on. The MATLAB solution is P = I [4x4], Q = I [3x3], R = A [3 x 4].
Example 2:
Take the code at end of this bugreport with
A << 1, 1, 0, 0,
0, 1, 0, 0,
0, 0, 1, 1;
The same thing happens as above, only this time the QR.rank() is 2 which is wrong unless it is another definition than I am use to.
SparseQR<SparseMatrix<double, ColMajor>, COLAMDOrdering<int> > QR;
MatrixXd A(3, 4);
A << 1, ?, 0, 0,
0, 1, 0, 0,
0, 0, 1, 1;
QR.compute(A.sparseView());
//
// QR rank
//
printf(", %d", QR.rank());
//
// AP matrix
//
printf("=[%d x %d]", AP.rows(), AP.cols());
for (i = 0; i < AP.outerSize(); ++i) {
for (SparseMatrix<double>::InnerIterator it(AP, i); it; ++it) {
printf("(%d %d %g)", it.row(), it.col(), it.value());
}
}
//
// Q matrix
//
printf("[%d x %d]", QR.matrixQ().rows(), QR.matrixQ().cols());
Q = QR.matrixQ();
printf("=[%d x %d]", Q.rows(), Q.cols());
for (i = 0; i < Q.outerSize(); ++i) {
for (SparseMatrix<double>::InnerIterator it(Q, i); it; ++it) {
printf("(%d %d %g)", it.row(), it.col(), it.value());
}
}