Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Eigen::SPQR< _MatrixType > Class Template Reference

Sparse QR factorization based on SuiteSparseQR library. More...

#include <src/eigen/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h>

+ Inheritance diagram for Eigen::SPQR< _MatrixType >:
+ Collaboration diagram for Eigen::SPQR< _MatrixType >:

Public Types

enum  { ColsAtCompileTime = Dynamic , MaxColsAtCompileTime = Dynamic }
 
typedef _MatrixType::Scalar Scalar
 
typedef _MatrixType::RealScalar RealScalar
 
typedef SuiteSparse_long StorageIndex
 
typedef SparseMatrix< Scalar, ColMajor, StorageIndexMatrixType
 
typedef Map< PermutationMatrix< Dynamic, Dynamic, StorageIndex > > PermutationType
 

Public Member Functions

 SPQR ()
 
 SPQR (const _MatrixType &matrix)
 
 ~SPQR ()
 
void SPQR_free ()
 
void compute (const _MatrixType &matrix)
 
Index rows () const
 
Index cols () const
 
template<typename Rhs , typename Dest >
void _solve_impl (const MatrixBase< Rhs > &b, MatrixBase< Dest > &dest) const
 
const MatrixType matrixR () const
 
SPQRMatrixQReturnType< SPQRmatrixQ () const
 Get an expression of the matrix Q.
 
PermutationType colsPermutation () const
 Get the permutation that was applied to columns of A.
 
Index rank () const
 
void setSPQROrdering (int ord)
 Set the fill-reducing ordering method to be used.
 
void setPivotThreshold (const RealScalar &tol)
 Set the tolerance tol to treat columns with 2-norm < =tol as zero.
 
cholmod_common * cholmodCommon () const
 
ComputationInfo info () const
 Reports whether previous computation was successful.
 
SPQR< _MatrixType > & derived ()
 
const SPQR< _MatrixType > & derived () const
 
const Solve< SPQR< _MatrixType >, Rhs > solve (const MatrixBase< Rhs > &b) const
 
const Solve< SPQR< _MatrixType >, Rhs > solve (const SparseMatrixBase< Rhs > &b) const
 
void _solve_impl (const SparseMatrixBase< Rhs > &b, SparseMatrixBase< Dest > &dest) const
 

Protected Types

typedef SparseSolverBase< SPQR< _MatrixType > > Base
 

Protected Attributes

bool m_analysisIsOk
 
bool m_factorizationIsOk
 
bool m_isRUpToDate
 
ComputationInfo m_info
 
int m_ordering
 
int m_allow_tol
 
RealScalar m_tolerance
 
cholmod_sparse * m_cR
 
MatrixType m_R
 
StorageIndexm_E
 
cholmod_sparse * m_H
 
StorageIndexm_HPinv
 
cholmod_dense * m_HTau
 
Index m_rank
 
cholmod_common m_cc
 
bool m_useDefaultThreshold
 
Index m_rows
 
bool m_isInitialized
 

Friends

template<typename , typename >
struct SPQR_QProduct
 

Detailed Description

template<typename _MatrixType>
class Eigen::SPQR< _MatrixType >

Sparse QR factorization based on SuiteSparseQR library.

This class is used to perform a multithreaded and multifrontal rank-revealing QR decomposition of sparse matrices. The result is then used to solve linear leasts_square systems. Clearly, a QR factorization is returned such that A*P = Q*R where :

P is the column permutation. Use colsPermutation() to get it.

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

R is the sparse triangular factor. Use matrixQR() to get it as SparseMatrix. NOTE : The Index type of R is always SuiteSparse_long. You can get it with SPQR::Index

Template Parameters
_MatrixTypeThe type of the sparse matrix A, must be a column-major SparseMatrix<>

\implsparsesolverconcept

Member Typedef Documentation

◆ Base

template<typename _MatrixType >
typedef SparseSolverBase<SPQR<_MatrixType> > Eigen::SPQR< _MatrixType >::Base
protected

◆ MatrixType

template<typename _MatrixType >
typedef SparseMatrix<Scalar, ColMajor, StorageIndex> Eigen::SPQR< _MatrixType >::MatrixType

◆ PermutationType

template<typename _MatrixType >
typedef Map<PermutationMatrix<Dynamic, Dynamic, StorageIndex> > Eigen::SPQR< _MatrixType >::PermutationType

◆ RealScalar

template<typename _MatrixType >
typedef _MatrixType::RealScalar Eigen::SPQR< _MatrixType >::RealScalar

◆ Scalar

template<typename _MatrixType >
typedef _MatrixType::Scalar Eigen::SPQR< _MatrixType >::Scalar

◆ StorageIndex

template<typename _MatrixType >
typedef SuiteSparse_long Eigen::SPQR< _MatrixType >::StorageIndex

Member Enumeration Documentation

◆ anonymous enum

template<typename _MatrixType >
anonymous enum
Enumerator
ColsAtCompileTime 
MaxColsAtCompileTime 
71 {
74 };
@ MaxColsAtCompileTime
Definition SuiteSparseQRSupport.h:73
@ ColsAtCompileTime
Definition SuiteSparseQRSupport.h:72
const int Dynamic
Definition Constants.h:21

Constructor & Destructor Documentation

◆ SPQR() [1/2]

template<typename _MatrixType >
Eigen::SPQR< _MatrixType >::SPQR ( )
inline
77 : m_ordering(SPQR_ORDERING_DEFAULT), m_allow_tol(SPQR_DEFAULT_TOL), m_tolerance (NumTraits<Scalar>::epsilon()), m_useDefaultThreshold(true)
78 {
79 cholmod_l_start(&m_cc);
80 }
cholmod_common m_cc
Definition SuiteSparseQRSupport.h:246
bool m_useDefaultThreshold
Definition SuiteSparseQRSupport.h:247
int m_allow_tol
Definition SuiteSparseQRSupport.h:237
RealScalar m_tolerance
Definition SuiteSparseQRSupport.h:238
int m_ordering
Definition SuiteSparseQRSupport.h:236

References Eigen::SPQR< _MatrixType >::m_cc.

◆ SPQR() [2/2]

template<typename _MatrixType >
Eigen::SPQR< _MatrixType >::SPQR ( const _MatrixType &  matrix)
inlineexplicit
83 : m_ordering(SPQR_ORDERING_DEFAULT), m_allow_tol(SPQR_DEFAULT_TOL), m_tolerance (NumTraits<Scalar>::epsilon()), m_useDefaultThreshold(true)
84 {
85 cholmod_l_start(&m_cc);
86 compute(matrix);
87 }
void compute(const _MatrixType &matrix)
Definition SuiteSparseQRSupport.h:103

References Eigen::SPQR< _MatrixType >::compute(), and Eigen::SPQR< _MatrixType >::m_cc.

+ Here is the call graph for this function:

◆ ~SPQR()

template<typename _MatrixType >
Eigen::SPQR< _MatrixType >::~SPQR ( )
inline
90 {
91 SPQR_free();
92 cholmod_l_finish(&m_cc);
93 }
void SPQR_free()
Definition SuiteSparseQRSupport.h:94

References Eigen::SPQR< _MatrixType >::m_cc, and Eigen::SPQR< _MatrixType >::SPQR_free().

+ Here is the call graph for this function:

Member Function Documentation

◆ _solve_impl() [1/2]

template<typename _MatrixType >
template<typename Rhs , typename Dest >
void Eigen::SPQR< _MatrixType >::_solve_impl ( const MatrixBase< Rhs > &  b,
MatrixBase< Dest > &  dest 
) const
inline
151 {
152 eigen_assert(m_isInitialized && " The QR factorization should be computed first, call compute()");
153 eigen_assert(b.cols()==1 && "This method is for vectors only");
154
155 //Compute Q^T * b
156 typename Dest::PlainObject y, y2;
157 y = matrixQ().transpose() * b;
158
159 // Solves with the triangular matrix R
160 Index rk = this->rank();
161 y2 = y;
162 y.resize((std::max)(cols(),Index(y.rows())),y.cols());
163 y.topRows(rk) = this->matrixR().topLeftCorner(rk, rk).template triangularView<Upper>().solve(y2.topRows(rk));
164
165 // Apply the column permutation
166 // colsPermutation() performs a copy of the permutation,
167 // so let's apply it manually:
168 for(Index i = 0; i < rk; ++i) dest.row(m_E[i]) = y.row(i);
169 for(Index i = rk; i < cols(); ++i) dest.row(m_E[i]).setZero();
170
171// y.bottomRows(y.rows()-rk).setZero();
172// dest = colsPermutation() * y.topRows(cols());
173
174 m_info = Success;
175 }
#define eigen_assert(x)
Definition Macros.h:579
StorageIndex * m_E
Definition SuiteSparseQRSupport.h:241
Index rank() const
Definition SuiteSparseQRSupport.h:203
ComputationInfo m_info
Definition SuiteSparseQRSupport.h:235
Index cols() const
Definition SuiteSparseQRSupport.h:147
SPQRMatrixQReturnType< SPQR > matrixQ() const
Get an expression of the matrix Q.
Definition SuiteSparseQRSupport.h:189
const MatrixType matrixR() const
Definition SuiteSparseQRSupport.h:179
bool m_isInitialized
Definition SparseSolverBase.h:119
@ Success
Definition Constants.h:432
const Scalar & y
Definition MathFunctions.h:552
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:33

References Eigen::SPQR< _MatrixType >::cols(), eigen_assert, Eigen::SPQR< _MatrixType >::m_E, Eigen::SPQR< _MatrixType >::m_info, Eigen::SparseSolverBase< SPQR< _MatrixType > >::m_isInitialized, Eigen::SPQR< _MatrixType >::matrixQ(), Eigen::SPQR< _MatrixType >::matrixR(), Eigen::SPQR< _MatrixType >::rank(), Eigen::DenseBase< Derived >::setZero(), and Eigen::Success.

+ Here is the call graph for this function:

◆ _solve_impl() [2/2]

void Eigen::SparseSolverBase< SPQR< _MatrixType > >::_solve_impl ( const SparseMatrixBase< Rhs > &  b,
SparseMatrixBase< Dest > &  dest 
) const
inlineinherited
112 {
113 internal::solve_sparse_through_dense_panels(derived(), b.derived(), dest.derived());
114 }
SPQR< _MatrixType > & derived()
Definition SparseSolverBase.h:79

◆ cholmodCommon()

template<typename _MatrixType >
cholmod_common * Eigen::SPQR< _MatrixType >::cholmodCommon ( ) const
inline
Returns
a pointer to the SPQR workspace
218{ return &m_cc; }

References Eigen::SPQR< _MatrixType >::m_cc.

◆ cols()

template<typename _MatrixType >
Index Eigen::SPQR< _MatrixType >::cols ( ) const
inline

Get the number of columns of the input matrix.

147{ return m_cR->ncol; }
cholmod_sparse * m_cR
Definition SuiteSparseQRSupport.h:239

References Eigen::SPQR< _MatrixType >::m_cR.

Referenced by Eigen::SPQR< _MatrixType >::_solve_impl().

+ Here is the caller graph for this function:

◆ colsPermutation()

template<typename _MatrixType >
PermutationType Eigen::SPQR< _MatrixType >::colsPermutation ( ) const
inline

Get the permutation that was applied to columns of A.

195 {
196 eigen_assert(m_isInitialized && "Decomposition is not initialized.");
197 return PermutationType(m_E, m_cR->ncol);
198 }
Map< PermutationMatrix< Dynamic, Dynamic, StorageIndex > > PermutationType
Definition SuiteSparseQRSupport.h:70

References eigen_assert, Eigen::SPQR< _MatrixType >::m_cR, Eigen::SPQR< _MatrixType >::m_E, and Eigen::SparseSolverBase< SPQR< _MatrixType > >::m_isInitialized.

◆ compute()

template<typename _MatrixType >
void Eigen::SPQR< _MatrixType >::compute ( const _MatrixType &  matrix)
inline
104 {
106
107 MatrixType mat(matrix);
108
109 /* Compute the default threshold as in MatLab, see:
110 * Tim Davis, "Algorithm 915, SuiteSparseQR: Multifrontal Multithreaded Rank-Revealing
111 * Sparse QR Factorization, ACM Trans. on Math. Soft. 38(1), 2011, Page 8:3
112 */
113 RealScalar pivotThreshold = m_tolerance;
115 {
116 RealScalar max2Norm = 0.0;
117 for (int j = 0; j < mat.cols(); j++) max2Norm = numext::maxi(max2Norm, mat.col(j).norm());
118 if(max2Norm==RealScalar(0))
119 max2Norm = RealScalar(1);
120 pivotThreshold = 20 * (mat.rows() + mat.cols()) * max2Norm * NumTraits<RealScalar>::epsilon();
121 }
122 cholmod_sparse A;
123 A = viewAsCholmod(mat);
124 m_rows = matrix.rows();
125 Index col = matrix.cols();
126 m_rank = SuiteSparseQR<Scalar>(m_ordering, pivotThreshold, col, &A,
127 &m_cR, &m_E, &m_H, &m_HPinv, &m_HTau, &m_cc);
128
129 if (!m_cR)
130 {
132 m_isInitialized = false;
133 return;
134 }
135 m_info = Success;
136 m_isInitialized = true;
137 m_isRUpToDate = false;
138 }
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col().
Definition BlockMethods.h:838
cholmod_sparse * m_H
Definition SuiteSparseQRSupport.h:242
StorageIndex * m_HPinv
Definition SuiteSparseQRSupport.h:243
Index m_rank
Definition SuiteSparseQRSupport.h:245
cholmod_dense * m_HTau
Definition SuiteSparseQRSupport.h:244
Index m_rows
Definition SuiteSparseQRSupport.h:248
_MatrixType::RealScalar RealScalar
Definition SuiteSparseQRSupport.h:67
SparseMatrix< Scalar, ColMajor, StorageIndex > MatrixType
Definition SuiteSparseQRSupport.h:69
bool m_isRUpToDate
Definition SuiteSparseQRSupport.h:234
@ NumericalIssue
Definition Constants.h:434
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
Definition MathFunctions.h:823
cholmod_sparse viewAsCholmod(Ref< SparseMatrix< _Scalar, _Options, _StorageIndex > > mat)
Definition CholmodSupport.h:58

References col(), Eigen::SparseMatrix< _Scalar, _Options, _StorageIndex >::cols(), Eigen::SPQR< _MatrixType >::m_cc, Eigen::SPQR< _MatrixType >::m_cR, Eigen::SPQR< _MatrixType >::m_E, Eigen::SPQR< _MatrixType >::m_H, Eigen::SPQR< _MatrixType >::m_HPinv, Eigen::SPQR< _MatrixType >::m_HTau, Eigen::SPQR< _MatrixType >::m_info, Eigen::SparseSolverBase< SPQR< _MatrixType > >::m_isInitialized, Eigen::SPQR< _MatrixType >::m_isRUpToDate, Eigen::SPQR< _MatrixType >::m_ordering, Eigen::SPQR< _MatrixType >::m_rank, Eigen::SPQR< _MatrixType >::m_rows, Eigen::SPQR< _MatrixType >::m_tolerance, Eigen::SPQR< _MatrixType >::m_useDefaultThreshold, Eigen::numext::maxi(), Eigen::SparseMatrixBase< Derived >::norm(), Eigen::NumericalIssue, Eigen::SparseMatrix< _Scalar, _Options, _StorageIndex >::rows(), Eigen::SPQR< _MatrixType >::SPQR_free(), Eigen::Success, and Eigen::viewAsCholmod().

Referenced by Eigen::SPQR< _MatrixType >::SPQR().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ derived() [1/2]

SPQR< _MatrixType > & Eigen::SparseSolverBase< SPQR< _MatrixType > >::derived ( )
inlineinherited
79{ return *static_cast<Derived*>(this); }

◆ derived() [2/2]

const SPQR< _MatrixType > & Eigen::SparseSolverBase< SPQR< _MatrixType > >::derived ( ) const
inlineinherited
80{ return *static_cast<const Derived*>(this); }

◆ info()

template<typename _MatrixType >
ComputationInfo Eigen::SPQR< _MatrixType >::info ( ) const
inline

Reports whether previous computation was successful.

Returns
Success if computation was succesful, NumericalIssue if the sparse QR can not be computed
227 {
228 eigen_assert(m_isInitialized && "Decomposition is not initialized.");
229 return m_info;
230 }

References eigen_assert, Eigen::SPQR< _MatrixType >::m_info, and Eigen::SparseSolverBase< SPQR< _MatrixType > >::m_isInitialized.

◆ matrixQ()

template<typename _MatrixType >
SPQRMatrixQReturnType< SPQR > Eigen::SPQR< _MatrixType >::matrixQ ( ) const
inline

Get an expression of the matrix Q.

190 {
191 return SPQRMatrixQReturnType<SPQR>(*this);
192 }

Referenced by Eigen::SPQR< _MatrixType >::_solve_impl().

+ Here is the caller graph for this function:

◆ matrixR()

template<typename _MatrixType >
const MatrixType Eigen::SPQR< _MatrixType >::matrixR ( ) const
inline
Returns
the sparse triangular factor R. It is a sparse matrix
180 {
181 eigen_assert(m_isInitialized && " The QR factorization should be computed first, call compute()");
182 if(!m_isRUpToDate) {
183 m_R = viewAsEigen<Scalar,ColMajor, typename MatrixType::StorageIndex>(*m_cR);
184 m_isRUpToDate = true;
185 }
186 return m_R;
187 }
MatrixType m_R
Definition SuiteSparseQRSupport.h:240

References eigen_assert, Eigen::SPQR< _MatrixType >::m_cR, Eigen::SparseSolverBase< SPQR< _MatrixType > >::m_isInitialized, Eigen::SPQR< _MatrixType >::m_isRUpToDate, and Eigen::SPQR< _MatrixType >::m_R.

Referenced by Eigen::SPQR< _MatrixType >::_solve_impl().

+ Here is the caller graph for this function:

◆ rank()

template<typename _MatrixType >
Index Eigen::SPQR< _MatrixType >::rank ( ) const
inline

Gets the rank of the matrix. It should be equal to matrixQR().cols if the matrix is full-rank

204 {
205 eigen_assert(m_isInitialized && "Decomposition is not initialized.");
206 return m_cc.SPQR_istat[4];
207 }

References eigen_assert, Eigen::SPQR< _MatrixType >::m_cc, and Eigen::SparseSolverBase< SPQR< _MatrixType > >::m_isInitialized.

Referenced by Eigen::SPQR< _MatrixType >::_solve_impl().

+ Here is the caller graph for this function:

◆ rows()

template<typename _MatrixType >
Index Eigen::SPQR< _MatrixType >::rows ( ) const
inline

Get the number of rows of the input matrix and the Q matrix

142{return m_rows; }

References Eigen::SPQR< _MatrixType >::m_rows.

◆ setPivotThreshold()

template<typename _MatrixType >
void Eigen::SPQR< _MatrixType >::setPivotThreshold ( const RealScalar tol)
inline

Set the tolerance tol to treat columns with 2-norm < =tol as zero.

212 {
213 m_useDefaultThreshold = false;
214 m_tolerance = tol;
215 }

References Eigen::SPQR< _MatrixType >::m_tolerance, and Eigen::SPQR< _MatrixType >::m_useDefaultThreshold.

◆ setSPQROrdering()

template<typename _MatrixType >
void Eigen::SPQR< _MatrixType >::setSPQROrdering ( int  ord)
inline

Set the fill-reducing ordering method to be used.

209{ m_ordering = ord;}

References Eigen::SPQR< _MatrixType >::m_ordering.

◆ solve() [1/2]

const Solve< SPQR< _MatrixType > , Rhs > Eigen::SparseSolverBase< SPQR< _MatrixType > >::solve ( const MatrixBase< Rhs > &  b) const
inlineinherited
Returns
an expression of the solution x of $ A x = b $ using the current decomposition of A.
See also
compute()
89 {
90 eigen_assert(m_isInitialized && "Solver is not initialized.");
91 eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b");
92 return Solve<Derived, Rhs>(derived(), b.derived());
93 }
size_t rows(const T &raster)
Definition MarchingSquares.hpp:55

◆ solve() [2/2]

const Solve< SPQR< _MatrixType > , Rhs > Eigen::SparseSolverBase< SPQR< _MatrixType > >::solve ( const SparseMatrixBase< Rhs > &  b) const
inlineinherited
Returns
an expression of the solution x of $ A x = b $ using the current decomposition of A.
See also
compute()
102 {
103 eigen_assert(m_isInitialized && "Solver is not initialized.");
104 eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b");
105 return Solve<Derived, Rhs>(derived(), b.derived());
106 }

◆ SPQR_free()

template<typename _MatrixType >
void Eigen::SPQR< _MatrixType >::SPQR_free ( )
inline
95 {
96 cholmod_l_free_sparse(&m_H, &m_cc);
97 cholmod_l_free_sparse(&m_cR, &m_cc);
98 cholmod_l_free_dense(&m_HTau, &m_cc);
99 std::free(m_E);
100 std::free(m_HPinv);
101 }

References Eigen::SPQR< _MatrixType >::m_cc, Eigen::SPQR< _MatrixType >::m_cR, Eigen::SPQR< _MatrixType >::m_E, Eigen::SPQR< _MatrixType >::m_H, Eigen::SPQR< _MatrixType >::m_HPinv, and Eigen::SPQR< _MatrixType >::m_HTau.

Referenced by Eigen::SPQR< _MatrixType >::~SPQR(), and Eigen::SPQR< _MatrixType >::compute().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ SPQR_QProduct

template<typename _MatrixType >
template<typename , typename >
friend struct SPQR_QProduct
friend

Member Data Documentation

◆ m_allow_tol

template<typename _MatrixType >
int Eigen::SPQR< _MatrixType >::m_allow_tol
protected

◆ m_analysisIsOk

template<typename _MatrixType >
bool Eigen::SPQR< _MatrixType >::m_analysisIsOk
protected

◆ m_cc

◆ m_cR

◆ m_E

◆ m_factorizationIsOk

template<typename _MatrixType >
bool Eigen::SPQR< _MatrixType >::m_factorizationIsOk
protected

◆ m_H

template<typename _MatrixType >
cholmod_sparse* Eigen::SPQR< _MatrixType >::m_H
mutableprotected

◆ m_HPinv

template<typename _MatrixType >
StorageIndex* Eigen::SPQR< _MatrixType >::m_HPinv
mutableprotected

◆ m_HTau

template<typename _MatrixType >
cholmod_dense* Eigen::SPQR< _MatrixType >::m_HTau
mutableprotected

◆ m_info

template<typename _MatrixType >
ComputationInfo Eigen::SPQR< _MatrixType >::m_info
mutableprotected

◆ m_isInitialized

bool Eigen::SparseSolverBase< SPQR< _MatrixType > >::m_isInitialized
mutableprotectedinherited

◆ m_isRUpToDate

template<typename _MatrixType >
bool Eigen::SPQR< _MatrixType >::m_isRUpToDate
mutableprotected

◆ m_ordering

template<typename _MatrixType >
int Eigen::SPQR< _MatrixType >::m_ordering
protected

◆ m_R

template<typename _MatrixType >
MatrixType Eigen::SPQR< _MatrixType >::m_R
mutableprotected

◆ m_rank

template<typename _MatrixType >
Index Eigen::SPQR< _MatrixType >::m_rank
mutableprotected

◆ m_rows

template<typename _MatrixType >
Index Eigen::SPQR< _MatrixType >::m_rows
protected

◆ m_tolerance

template<typename _MatrixType >
RealScalar Eigen::SPQR< _MatrixType >::m_tolerance
protected

◆ m_useDefaultThreshold

template<typename _MatrixType >
bool Eigen::SPQR< _MatrixType >::m_useDefaultThreshold
protected

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