In C++ interface of SuiteSparse, I can use
SuiteSparseQR_factorization <double> *QR;
QR = SuiteSparseQR_factorize(A) ;
to calculate QR decomposition of matrix A so that I can reuse QR for further calculation. But I wonder can I get the real Q,R directly from this QR object?
SuiteSparse is awesome, but the interface can be confusing. Unfortunately, the methods that involve the
SuiteSparseQR_factorizationstruct, which appear to be the most convenient, haven't worked so well for me in practice. For instance, usingSuiteSparseQR_factorizeand thenSuiteSparseQR_qmultwith a sparse matrix input argument actually converts it to a dense matrix first, which seems completely unnecessary!Instead, use
This method will perform the factorization and then, optionally, output (among other things) R, the matrix product Z = Q^T * B (or its transpose -- B^T * Q), or the solution of a linear system. To get Q, define B as the identity matrix. Here's an example to get Q and R.
If you want any of the other outputs to perform subsequent operations without the use of an explicitly formed Q and/or R, then you need to substitute the NULL's for additional pointers and then make calls to
SuiteSparseQR_qmult.