spqr

sksparse.spqr.spqr(A, *, mode='full', order=None, tol=None)[source]

Compute the QR factorization.

This function computes the QR factorization of a sparse matrix \(A\) such that

\[Q R = A E\]

where \(Q\) is an orthogonal matrix and \(R\) is an upper-triangular matrix. \(E\) is a column permutation matrix that reduces fill-in during the factorization.

Parameters:
  • A ((M, N) array_like or sparse array) – An array convertible to a sparse matrix.

  • mode ({‘full’, ‘r’, ‘economic’, ‘householder’}, optional) – The mode of the returned Q and R matrices. Options are:

    • full: Q is size (M, M), R is size (M, N).

    • economic: Q is size (M, K), R is size (K, N), where K = min(M, N).

    • r: Only return the upper-triangular matrix R.

    • householder: Return the Householder vectors and coefficients used to build Q. This option is similar to mode='raw' in scipy.linalg.qr().

  • order (str, optional) – The column ordering strategy to use. Let \(S\) be the matrix \(A\) with singleton rows/columns removed, the ordering options are:

    • default: COLAMD(S),

    • fixed: identity permutation (i.e. no singletons removed),

    • natural: singletons removed, but no fill-reducing ordering applied,

    • colamd: COLAMD(S),

    • amd: AMD(\(S^{\top} S\)),

    • metis: METIS(\(S^{\top} S\)),

    • best: try all of amd, colamd, metis and pick the best,

    • cholmod: Same as best,

    • bestamd: try amd and colamd and pick the best.

  • tol (float, optional) – If the 2-norm of a column in A is less than tol, that column is considered to be a zero column. If tol = 0, no columns are treated as zero. If None, the default tolerance is used. The default is tol = \(20 \epsilon (M + N) \sqrt{\max{\mathrm{diag}(A^{\top} A)}}\), where \(\epsilon\) is the machine precision.

Returns:

  • Q (csc_array) – The orthogonal matrix \(Q\). Shape (M, M) or (M, K) if mode='economic'. Not returned if mode='r'. Replaced by SPQRHouseholder if mode='householder'.

  • R (csc_array) – The upper-triangular matrix \(R\). Shape (M, N) or (K, N) if mode in ['economic', 'householder'], where K = min(M, N).

  • P (ndarray of int) – The permutation vector of shape (N,).

Notes

This function is part of an interface to the SuiteSparse SPQR library [1].

Added in version 0.5.0.

References