WPILibC++ 2023.4.3
Eigen::SparseQR< _MatrixType, _OrderingType > Class Template Reference

Sparse left-looking QR factorization with numerical column pivoting. More...

#include </home/runner/work/allwpilib/allwpilib/wpimath/src/main/native/thirdparty/eigen/include/Eigen/src/SparseQR/SparseQR.h>

Inheritance diagram for Eigen::SparseQR< _MatrixType, _OrderingType >:
Eigen::SparseSolverBase< SparseQR< _MatrixType, _OrderingType > > Eigen::internal::noncopyable

Public Types

enum  { ColsAtCompileTime = MatrixType::ColsAtCompileTime , MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime }
 
typedef _MatrixType MatrixType
 
typedef _OrderingType OrderingType
 
typedef MatrixType::Scalar Scalar
 
typedef MatrixType::RealScalar RealScalar
 
typedef MatrixType::StorageIndex StorageIndex
 
typedef SparseMatrix< Scalar, ColMajor, StorageIndexQRMatrixType
 
typedef Matrix< StorageIndex, Dynamic, 1 > IndexVector
 
typedef Matrix< Scalar, Dynamic, 1 > ScalarVector
 
typedef PermutationMatrix< Dynamic, Dynamic, StorageIndexPermutationType
 

Public Member Functions

 SparseQR ()
 
 SparseQR (const MatrixType &mat)
 Construct a QR factorization of the matrix mat. More...
 
void compute (const MatrixType &mat)
 Computes the QR factorization of the sparse matrix mat. More...
 
void analyzePattern (const MatrixType &mat)
 Preprocessing step of a QR factorization. More...
 
void factorize (const MatrixType &mat)
 Performs the numerical QR factorization of the input matrix. More...
 
Index rows () const
 
Index cols () const
 
const QRMatrixTypematrixR () const
 
Index rank () const
 
SparseQRMatrixQReturnType< SparseQRmatrixQ () const
 
const PermutationTypecolsPermutation () const
 
std::string lastErrorMessage () const
 
template<typename Rhs , typename Dest >
bool _solve_impl (const MatrixBase< Rhs > &B, MatrixBase< Dest > &dest) const
 
void setPivotThreshold (const RealScalar &threshold)
 Sets the threshold that is used to determine linearly dependent columns during the factorization. More...
 
template<typename Rhs >
const Solve< SparseQR, Rhs > solve (const MatrixBase< Rhs > &B) const
 
template<typename Rhs >
const Solve< SparseQR, Rhs > solve (const SparseMatrixBase< Rhs > &B) const
 
ComputationInfo info () const
 Reports whether previous computation was successful. More...
 
void _sort_matrix_Q ()
 
- Public Member Functions inherited from Eigen::SparseSolverBase< SparseQR< _MatrixType, _OrderingType > >
 SparseSolverBase ()
 Default constructor. More...
 
 ~SparseSolverBase ()
 
SparseQR< _MatrixType, _OrderingType > & derived ()
 
const SparseQR< _MatrixType, _OrderingType > & derived () const
 
const Solve< SparseQR< _MatrixType, _OrderingType >, Rhs > solve (const MatrixBase< Rhs > &b) const
 
const Solve< SparseQR< _MatrixType, _OrderingType >, Rhs > solve (const SparseMatrixBase< Rhs > &b) const
 
void _solve_impl (const SparseMatrixBase< Rhs > &b, SparseMatrixBase< Dest > &dest) const
 

Protected Types

typedef SparseSolverBase< SparseQR< _MatrixType, _OrderingType > > Base
 

Protected Attributes

bool m_analysisIsok
 
bool m_factorizationIsok
 
ComputationInfo m_info
 
std::string m_lastError
 
QRMatrixType m_pmat
 
QRMatrixType m_R
 
QRMatrixType m_Q
 
ScalarVector m_hcoeffs
 
PermutationType m_perm_c
 
PermutationType m_pivotperm
 
PermutationType m_outputPerm_c
 
RealScalar m_threshold
 
bool m_useDefaultThreshold
 
Index m_nonzeropivots
 
IndexVector m_etree
 
IndexVector m_firstRowElt
 
bool m_isQSorted
 
bool m_isEtreeOk
 
- Protected Attributes inherited from Eigen::SparseSolverBase< SparseQR< _MatrixType, _OrderingType > >
bool m_isInitialized
 

Friends

template<typename , typename >
struct SparseQR_QProduct
 

Detailed Description

template<typename _MatrixType, typename _OrderingType>
class Eigen::SparseQR< _MatrixType, _OrderingType >

Sparse left-looking QR factorization with numerical column pivoting.

This class implements a left-looking QR decomposition of sparse matrices with numerical column pivoting. When a column has a norm less than a given tolerance it is implicitly permuted to the end. The QR factorization thus obtained is given by A*P = Q*R where R is upper triangular or trapezoidal.

P is the column permutation which is the product of the fill-reducing and the numerical permutations. Use colsPermutation() to get it.

Q is the orthogonal matrix represented as products of Householder reflectors. Use matrixQ() to get an expression and matrixQ().adjoint() to get the adjoint. You can then apply it to a vector.

R is the sparse triangular or trapezoidal matrix. The later occurs when A is rank-deficient. matrixR().topLeftCorner(rank(), rank()) always returns a triangular factor of full rank.

Template Parameters
_MatrixTypeThe type of the sparse matrix A, must be a column-major SparseMatrix<>
_OrderingTypeThe fill-reducing ordering method. See the OrderingMethods module for the list of built-in and external ordering methods.

\implsparsesolverconcept

The numerical pivoting strategy and default threshold are the same as in SuiteSparse QR, and detailed in the following paper: Tim Davis, "Algorithm 915, SuiteSparseQR: Multifrontal Multithreaded Rank-Revealing Sparse QR Factorization, ACM Trans. on Math. Soft. 38(1), 2011. </i> Even though it is qualified as "rank-revealing", this strategy might fail for some rank deficient problems. When this class is used to solve linear or least-square problems it is thus strongly recommended to check the accuracy of the computed solution. If it failed, it usually helps to increase the threshold with setPivotThreshold.

Warning
The input sparse matrix A must be in compressed mode (see SparseMatrix::makeCompressed()).
For complex matrices matrixQ().transpose() will actually return the adjoint matrix.

Member Typedef Documentation

◆ Base

template<typename _MatrixType , typename _OrderingType >
typedef SparseSolverBase<SparseQR<_MatrixType,_OrderingType> > Eigen::SparseQR< _MatrixType, _OrderingType >::Base
protected

◆ IndexVector

template<typename _MatrixType , typename _OrderingType >
typedef Matrix<StorageIndex, Dynamic, 1> Eigen::SparseQR< _MatrixType, _OrderingType >::IndexVector

◆ MatrixType

template<typename _MatrixType , typename _OrderingType >
typedef _MatrixType Eigen::SparseQR< _MatrixType, _OrderingType >::MatrixType

◆ OrderingType

template<typename _MatrixType , typename _OrderingType >
typedef _OrderingType Eigen::SparseQR< _MatrixType, _OrderingType >::OrderingType

◆ PermutationType

template<typename _MatrixType , typename _OrderingType >
typedef PermutationMatrix<Dynamic, Dynamic, StorageIndex> Eigen::SparseQR< _MatrixType, _OrderingType >::PermutationType

◆ QRMatrixType

template<typename _MatrixType , typename _OrderingType >
typedef SparseMatrix<Scalar,ColMajor,StorageIndex> Eigen::SparseQR< _MatrixType, _OrderingType >::QRMatrixType

◆ RealScalar

template<typename _MatrixType , typename _OrderingType >
typedef MatrixType::RealScalar Eigen::SparseQR< _MatrixType, _OrderingType >::RealScalar

◆ Scalar

template<typename _MatrixType , typename _OrderingType >
typedef MatrixType::Scalar Eigen::SparseQR< _MatrixType, _OrderingType >::Scalar

◆ ScalarVector

template<typename _MatrixType , typename _OrderingType >
typedef Matrix<Scalar, Dynamic, 1> Eigen::SparseQR< _MatrixType, _OrderingType >::ScalarVector

◆ StorageIndex

template<typename _MatrixType , typename _OrderingType >
typedef MatrixType::StorageIndex Eigen::SparseQR< _MatrixType, _OrderingType >::StorageIndex

Member Enumeration Documentation

◆ anonymous enum

template<typename _MatrixType , typename _OrderingType >
anonymous enum
Enumerator
ColsAtCompileTime 
MaxColsAtCompileTime 

Constructor & Destructor Documentation

◆ SparseQR() [1/2]

template<typename _MatrixType , typename _OrderingType >
Eigen::SparseQR< _MatrixType, _OrderingType >::SparseQR ( )
inline

◆ SparseQR() [2/2]

template<typename _MatrixType , typename _OrderingType >
Eigen::SparseQR< _MatrixType, _OrderingType >::SparseQR ( const MatrixType mat)
inlineexplicit

Construct a QR factorization of the matrix mat.

Warning
The matrix mat must be in compressed mode (see SparseMatrix::makeCompressed()).
See also
compute()

Member Function Documentation

◆ _solve_impl()

template<typename _MatrixType , typename _OrderingType >
template<typename Rhs , typename Dest >
bool Eigen::SparseQR< _MatrixType, _OrderingType >::_solve_impl ( const MatrixBase< Rhs > &  B,
MatrixBase< Dest > &  dest 
) const
inline

◆ _sort_matrix_Q()

template<typename _MatrixType , typename _OrderingType >
void Eigen::SparseQR< _MatrixType, _OrderingType >::_sort_matrix_Q ( )
inline

◆ analyzePattern()

template<typename MatrixType , typename OrderingType >
void Eigen::SparseQR< MatrixType, OrderingType >::analyzePattern ( const MatrixType mat)

Preprocessing step of a QR factorization.

Warning
The matrix mat must be in compressed mode (see SparseMatrix::makeCompressed()).

In this step, the fill-reducing permutation is computed and applied to the columns of A and the column elimination tree is computed as well. Only the sparsity pattern of mat is exploited.

Note
In this step it is assumed that there is no empty row in the matrix mat.

◆ cols()

template<typename _MatrixType , typename _OrderingType >
Index Eigen::SparseQR< _MatrixType, _OrderingType >::cols ( ) const
inline
Returns
the number of columns of the represented matrix.

◆ colsPermutation()

template<typename _MatrixType , typename _OrderingType >
const PermutationType & Eigen::SparseQR< _MatrixType, _OrderingType >::colsPermutation ( ) const
inline
Returns
a const reference to the column permutation P that was applied to A such that A*P = Q*R It is the combination of the fill-in reducing permutation and numerical column pivoting.

◆ compute()

template<typename _MatrixType , typename _OrderingType >
void Eigen::SparseQR< _MatrixType, _OrderingType >::compute ( const MatrixType mat)
inline

Computes the QR factorization of the sparse matrix mat.

Warning
The matrix mat must be in compressed mode (see SparseMatrix::makeCompressed()).
See also
analyzePattern(), factorize()

◆ factorize()

template<typename MatrixType , typename OrderingType >
void Eigen::SparseQR< MatrixType, OrderingType >::factorize ( const MatrixType mat)

Performs the numerical QR factorization of the input matrix.

The function SparseQR::analyzePattern(const MatrixType&) must have been called beforehand with a matrix having the same sparsity pattern than mat.

Parameters
matThe sparse column-major matrix

◆ info()

template<typename _MatrixType , typename _OrderingType >
ComputationInfo Eigen::SparseQR< _MatrixType, _OrderingType >::info ( ) const
inline

Reports whether previous computation was successful.

Returns
Success if computation was successful, NumericalIssue if the QR factorization reports a numerical problem InvalidInput if the input matrix is invalid
See also
iparm()

◆ lastErrorMessage()

template<typename _MatrixType , typename _OrderingType >
std::string Eigen::SparseQR< _MatrixType, _OrderingType >::lastErrorMessage ( ) const
inline
Returns
A string describing the type of error. This method is provided to ease debugging, not to handle errors.

◆ matrixQ()

template<typename _MatrixType , typename _OrderingType >
SparseQRMatrixQReturnType< SparseQR > Eigen::SparseQR< _MatrixType, _OrderingType >::matrixQ ( ) const
inline
Returns
an expression of the matrix Q as products of sparse Householder reflectors. The common usage of this function is to apply it to a dense matrix or vector
VectorXd B1, B2;
// Initialize B1
B2 = matrixQ() * B1;
SparseQRMatrixQReturnType< SparseQR > matrixQ() const
Definition: SparseQR.h:186

To get a plain SparseMatrix representation of Q:

A versatible sparse matrix representation.
Definition: SparseMatrix.h:98
Sparse left-looking QR factorization with numerical column pivoting.
Definition: SparseQR.h:85

Internally, this call simply performs a sparse product between the matrix Q and a sparse identity matrix. However, due to the fact that the sparse reflectors are stored unsorted, two transpositions are needed to sort them before performing the product.

◆ matrixR()

template<typename _MatrixType , typename _OrderingType >
const QRMatrixType & Eigen::SparseQR< _MatrixType, _OrderingType >::matrixR ( ) const
inline
Returns
a const reference to the sparse upper triangular matrix R of the QR factorization.
Warning
The entries of the returned matrix are not sorted. This means that using it in algorithms expecting sorted entries will fail. This include random coefficient accesses (SpaseMatrix::coeff()), and coefficient-wise operations. Matrix products and triangular solves are fine though.

To sort the entries, you can assign it to a row-major matrix, and if a column-major matrix is required, you can copy it again:

SparseMatrix<double> R = qr.matrixR(); // column-major, not sorted!
SparseMatrix<double,RowMajor> Rr = qr.matrixR(); // row-major, sorted
SparseMatrix<double> Rc = Rr; // column-major, sorted
static constexpr const unit_t< compound_unit< energy::joules, inverse< temperature::kelvin >, inverse< substance::moles > > > R(8.3144598)
Gas constant.

◆ rank()

template<typename _MatrixType , typename _OrderingType >
Index Eigen::SparseQR< _MatrixType, _OrderingType >::rank ( ) const
inline
Returns
the number of non linearly dependent columns as determined by the pivoting threshold.
See also
setPivotThreshold()

◆ rows()

template<typename _MatrixType , typename _OrderingType >
Index Eigen::SparseQR< _MatrixType, _OrderingType >::rows ( ) const
inline
Returns
the number of rows of the represented matrix.

◆ setPivotThreshold()

template<typename _MatrixType , typename _OrderingType >
void Eigen::SparseQR< _MatrixType, _OrderingType >::setPivotThreshold ( const RealScalar threshold)
inline

Sets the threshold that is used to determine linearly dependent columns during the factorization.

In practice, if during the factorization the norm of the column that has to be eliminated is below this threshold, then the entire column is treated as zero, and it is moved at the end.

◆ solve() [1/2]

template<typename _MatrixType , typename _OrderingType >
template<typename Rhs >
const Solve< SparseQR, Rhs > Eigen::SparseQR< _MatrixType, _OrderingType >::solve ( const MatrixBase< Rhs > &  B) const
inline
Returns
the solution X of \( A X = B \) using the current decomposition of A.
See also
compute()

◆ solve() [2/2]

template<typename _MatrixType , typename _OrderingType >
template<typename Rhs >
const Solve< SparseQR, Rhs > Eigen::SparseQR< _MatrixType, _OrderingType >::solve ( const SparseMatrixBase< Rhs > &  B) const
inline

Friends And Related Function Documentation

◆ SparseQR_QProduct

template<typename _MatrixType , typename _OrderingType >
template<typename , typename >
friend struct SparseQR_QProduct
friend

Member Data Documentation

◆ m_analysisIsok

template<typename _MatrixType , typename _OrderingType >
bool Eigen::SparseQR< _MatrixType, _OrderingType >::m_analysisIsok
protected

◆ m_etree

template<typename _MatrixType , typename _OrderingType >
IndexVector Eigen::SparseQR< _MatrixType, _OrderingType >::m_etree
protected

◆ m_factorizationIsok

template<typename _MatrixType , typename _OrderingType >
bool Eigen::SparseQR< _MatrixType, _OrderingType >::m_factorizationIsok
protected

◆ m_firstRowElt

template<typename _MatrixType , typename _OrderingType >
IndexVector Eigen::SparseQR< _MatrixType, _OrderingType >::m_firstRowElt
protected

◆ m_hcoeffs

template<typename _MatrixType , typename _OrderingType >
ScalarVector Eigen::SparseQR< _MatrixType, _OrderingType >::m_hcoeffs
protected

◆ m_info

template<typename _MatrixType , typename _OrderingType >
ComputationInfo Eigen::SparseQR< _MatrixType, _OrderingType >::m_info
mutableprotected

◆ m_isEtreeOk

template<typename _MatrixType , typename _OrderingType >
bool Eigen::SparseQR< _MatrixType, _OrderingType >::m_isEtreeOk
protected

◆ m_isQSorted

template<typename _MatrixType , typename _OrderingType >
bool Eigen::SparseQR< _MatrixType, _OrderingType >::m_isQSorted
protected

◆ m_lastError

template<typename _MatrixType , typename _OrderingType >
std::string Eigen::SparseQR< _MatrixType, _OrderingType >::m_lastError
protected

◆ m_nonzeropivots

template<typename _MatrixType , typename _OrderingType >
Index Eigen::SparseQR< _MatrixType, _OrderingType >::m_nonzeropivots
protected

◆ m_outputPerm_c

template<typename _MatrixType , typename _OrderingType >
PermutationType Eigen::SparseQR< _MatrixType, _OrderingType >::m_outputPerm_c
protected

◆ m_perm_c

template<typename _MatrixType , typename _OrderingType >
PermutationType Eigen::SparseQR< _MatrixType, _OrderingType >::m_perm_c
protected

◆ m_pivotperm

template<typename _MatrixType , typename _OrderingType >
PermutationType Eigen::SparseQR< _MatrixType, _OrderingType >::m_pivotperm
protected

◆ m_pmat

template<typename _MatrixType , typename _OrderingType >
QRMatrixType Eigen::SparseQR< _MatrixType, _OrderingType >::m_pmat
protected

◆ m_Q

template<typename _MatrixType , typename _OrderingType >
QRMatrixType Eigen::SparseQR< _MatrixType, _OrderingType >::m_Q
protected

◆ m_R

template<typename _MatrixType , typename _OrderingType >
QRMatrixType Eigen::SparseQR< _MatrixType, _OrderingType >::m_R
protected

◆ m_threshold

template<typename _MatrixType , typename _OrderingType >
RealScalar Eigen::SparseQR< _MatrixType, _OrderingType >::m_threshold
protected

◆ m_useDefaultThreshold

template<typename _MatrixType , typename _OrderingType >
bool Eigen::SparseQR< _MatrixType, _OrderingType >::m_useDefaultThreshold
protected

The documentation for this class was generated from the following file: