![]() |
|
Sparse supernodal LU factorization for general matrices. More...
#include <SparseLU.h>
Public Member Functions | |
SparseLU () | |
Basic constructor of the solver. More... | |
SparseLU (const MatrixType &matrix) | |
Constructor of the solver already based on a specific matrix. More... | |
~SparseLU () | |
void | analyzePattern (const MatrixType &matrix) |
Compute the column permutation. More... | |
void | factorize (const MatrixType &matrix) |
Factorize the matrix to get the solver ready. More... | |
void | simplicialfactorize (const MatrixType &matrix) |
void | compute (const MatrixType &matrix) |
Analyze and factorize the matrix so the solver is ready to solve. More... | |
const SparseLUTransposeView< false, SparseLU< MatrixType_, OrderingType_ > > | transpose () |
Return a solver for the transposed matrix. More... | |
const SparseLUTransposeView< true, SparseLU< MatrixType_, OrderingType_ > > | adjoint () |
Return a solver for the adjointed matrix. More... | |
Index | rows () const |
Give the number of rows. More... | |
Index | cols () const |
Give the number of columns. More... | |
void | isSymmetric (bool sym) |
Let you set that the pattern of the input matrix is symmetric. More... | |
SparseLUMatrixLReturnType< SCMatrix > | matrixL () const |
Give the matrixL. More... | |
SparseLUMatrixUReturnType< SCMatrix, Map< SparseMatrix< Scalar, ColMajor, StorageIndex > > > | matrixU () const |
Give the MatrixU. More... | |
const PermutationType & | rowsPermutation () const |
Give the row matrix permutation. More... | |
const PermutationType & | colsPermutation () const |
Give the column matrix permutation. More... | |
void | setPivotThreshold (const RealScalar &thresh) |
ComputationInfo | info () const |
Reports whether previous computation was successful. More... | |
std::string | lastErrorMessage () const |
Give a human readable error. More... | |
template<typename Rhs , typename Dest > | |
bool | _solve_impl (const MatrixBase< Rhs > &B, MatrixBase< Dest > &X_base) const |
Scalar | absDeterminant () |
Give the absolute value of the determinant. More... | |
Scalar | logAbsDeterminant () const |
Give the natural log of the absolute determinant. More... | |
Scalar | signDeterminant () |
Give the sign of the determinant. More... | |
Scalar | determinant () |
Give the determinant. More... | |
Index | nnzL () const |
Give the number of non zero in matrix L. More... | |
Index | nnzU () const |
Give the number of non zero in matrix U. More... | |
![]() | |
SparseSolverBase () | |
SparseSolverBase (SparseSolverBase &&other) | |
~SparseSolverBase () | |
SparseLU< MatrixType_, OrderingType_ > & | derived () |
const SparseLU< MatrixType_, OrderingType_ > & | derived () const |
const Solve< SparseLU< MatrixType_, OrderingType_ >, Rhs > | solve (const MatrixBase< Rhs > &b) const |
const Solve< SparseLU< MatrixType_, OrderingType_ >, Rhs > | solve (const SparseMatrixBase< Rhs > &b) const |
void | _solve_impl (const SparseMatrixBase< Rhs > &b, SparseMatrixBase< Dest > &dest) const |
Protected Types | |
typedef SparseSolverBase< SparseLU< MatrixType_, OrderingType_ > > | APIBase |
Protected Member Functions | |
void | initperfvalues () |
![]() | |
Index | expand (VectorType &vec, Index &length, Index nbElts, Index keep_prev, Index &num_expansions) |
Index | memInit (Index m, Index n, Index annz, Index lwork, Index fillratio, Index panel_size, GlobalLU_t &glu) |
Allocate various working space for the numerical factorization phase. More... | |
Index | memXpand (VectorType &vec, Index &maxlen, Index nbElts, MemType memtype, Index &num_expansions) |
Expand the existing storage. More... | |
void | heap_relax_snode (const Index n, IndexVector &et, const Index relax_columns, IndexVector &descendants, IndexVector &relax_end) |
Identify the initial relaxed supernodes. More... | |
void | relax_snode (const Index n, IndexVector &et, const Index relax_columns, IndexVector &descendants, IndexVector &relax_end) |
Identify the initial relaxed supernodes. More... | |
Index | snode_dfs (const Index jcol, const Index kcol, const MatrixType &mat, IndexVector &xprune, IndexVector &marker, GlobalLU_t &glu) |
Index | snode_bmod (const Index jcol, const Index fsupc, ScalarVector &dense, GlobalLU_t &glu) |
Index | pivotL (const Index jcol, const RealScalar &diagpivotthresh, IndexVector &perm_r, IndexVector &iperm_c, Index &pivrow, GlobalLU_t &glu) |
Performs the numerical pivoting on the current column of L, and the CDIV operation. More... | |
void | dfs_kernel (const MatrixType_::StorageIndex jj, IndexVector &perm_r, Index &nseg, IndexVector &panel_lsub, IndexVector &segrep, Ref< IndexVector > repfnz_col, IndexVector &xprune, Ref< IndexVector > marker, IndexVector &parent, IndexVector &xplore, GlobalLU_t &glu, Index &nextl_col, Index krow, Traits &traits) |
void | panel_dfs (const Index m, const Index w, const Index jcol, MatrixType &A, IndexVector &perm_r, Index &nseg, ScalarVector &dense, IndexVector &panel_lsub, IndexVector &segrep, IndexVector &repfnz, IndexVector &xprune, IndexVector &marker, IndexVector &parent, IndexVector &xplore, GlobalLU_t &glu) |
Performs a symbolic factorization on a panel of columns [jcol, jcol+w) More... | |
void | panel_bmod (const Index m, const Index w, const Index jcol, const Index nseg, ScalarVector &dense, ScalarVector &tempv, IndexVector &segrep, IndexVector &repfnz, GlobalLU_t &glu) |
Performs numeric block updates (sup-panel) in topological order. More... | |
Index | column_dfs (const Index m, const Index jcol, IndexVector &perm_r, Index maxsuper, Index &nseg, BlockIndexVector lsub_col, IndexVector &segrep, BlockIndexVector repfnz, IndexVector &xprune, IndexVector &marker, IndexVector &parent, IndexVector &xplore, GlobalLU_t &glu) |
Performs a symbolic factorization on column jcol and decide the supernode boundary. More... | |
Index | column_bmod (const Index jcol, const Index nseg, BlockScalarVector dense, ScalarVector &tempv, BlockIndexVector segrep, BlockIndexVector repfnz, Index fpanelc, GlobalLU_t &glu) |
Performs numeric block updates (sup-col) in topological order. More... | |
Index | copy_to_ucol (const Index jcol, const Index nseg, IndexVector &segrep, BlockIndexVector repfnz, IndexVector &perm_r, BlockScalarVector dense, GlobalLU_t &glu) |
Performs numeric block updates (sup-col) in topological order. More... | |
void | pruneL (const Index jcol, const IndexVector &perm_r, const Index pivrow, const Index nseg, const IndexVector &segrep, BlockIndexVector repfnz, IndexVector &xprune, GlobalLU_t &glu) |
Prunes the L-structure. More... | |
void | countnz (const Index n, Index &nnzL, Index &nnzU, GlobalLU_t &glu) |
Count Nonzero elements in the factors. More... | |
void | fixupL (const Index n, const IndexVector &perm_r, GlobalLU_t &glu) |
Fix up the data storage lsub for L-subscripts. More... | |
Protected Attributes | |
ComputationInfo | m_info |
bool | m_factorizationIsOk |
bool | m_analysisIsOk |
std::string | m_lastError |
NCMatrix | m_mat |
SCMatrix | m_Lstore |
Map< SparseMatrix< Scalar, ColMajor, StorageIndex > > | m_Ustore |
PermutationType | m_perm_c |
PermutationType | m_perm_r |
IndexVector | m_etree |
Base::GlobalLU_t | m_glu |
bool | m_symmetricmode |
internal::perfvalues | m_perfv |
RealScalar | m_diagpivotthresh |
Index | m_nnzL |
Index | m_nnzU |
Index | m_detPermR |
Index | m_detPermC |
![]() | |
bool | m_isInitialized |
Private Member Functions | |
SparseLU (const SparseLU &) | |
Sparse supernodal LU factorization for general matrices.
This class implements the supernodal LU factorization for general matrices. It uses the main techniques from the sequential SuperLU package (http://crd-legacy.lbl.gov/~xiaoye/SuperLU/). It handles transparently real and complex arithmetic with single and double precision, depending on the scalar type of your input matrix. The code has been optimized to provide BLAS-3 operations during supernode-panel updates. It benefits directly from the built-in high-performant Eigen BLAS routines. Moreover, when the size of a supernode is very small, the BLAS calls are avoided to enable a better optimization from the compiler. For best performance, you should compile it with NDEBUG flag to avoid the numerous bounds checking on vectors.
An important parameter of this class is the ordering method. It is used to reorder the columns (and eventually the rows) of the matrix to reduce the number of new elements that are created during numerical factorization. The cheapest method available is COLAMD. See the OrderingMethods module for the list of built-in and external ordering methods.
Simple example with key steps
We can directly call compute() instead of analyzePattern() and factorize()
Or give the matrix to the constructor SparseLU(const MatrixType& matrix)
MatrixType_ | The type of the sparse matrix. It must be a column-major SparseMatrix<> |
OrderingType_ | The ordering method to use, either AMD, COLAMD or METIS. Default is COLMAD |
\implsparsesolverconcept
|
protected |
typedef internal::SparseLUImpl<Scalar, StorageIndex> Eigen::SparseLU< MatrixType_, OrderingType_ >::Base |
typedef Matrix<StorageIndex, Dynamic, 1> Eigen::SparseLU< MatrixType_, OrderingType_ >::IndexVector |
typedef MatrixType_ Eigen::SparseLU< MatrixType_, OrderingType_ >::MatrixType |
typedef SparseMatrix<Scalar, ColMajor, StorageIndex> Eigen::SparseLU< MatrixType_, OrderingType_ >::NCMatrix |
typedef OrderingType_ Eigen::SparseLU< MatrixType_, OrderingType_ >::OrderingType |
typedef PermutationMatrix<Dynamic, Dynamic, StorageIndex> Eigen::SparseLU< MatrixType_, OrderingType_ >::PermutationType |
typedef MatrixType::RealScalar Eigen::SparseLU< MatrixType_, OrderingType_ >::RealScalar |
typedef MatrixType::Scalar Eigen::SparseLU< MatrixType_, OrderingType_ >::Scalar |
typedef Matrix<Scalar, Dynamic, 1> Eigen::SparseLU< MatrixType_, OrderingType_ >::ScalarVector |
typedef internal::MappedSuperNodalMatrix<Scalar, StorageIndex> Eigen::SparseLU< MatrixType_, OrderingType_ >::SCMatrix |
typedef MatrixType::StorageIndex Eigen::SparseLU< MatrixType_, OrderingType_ >::StorageIndex |
anonymous enum |
Enumerator | |
---|---|
ColsAtCompileTime | |
MaxColsAtCompileTime |
|
inline |
Basic constructor of the solver.
Construct a SparseLU. As no matrix is given as argument, compute() should be called afterward with a matrix.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::initperfvalues().
|
inlineexplicit |
Constructor of the solver already based on a specific matrix.
Construct a SparseLU. compute() is already called with the given matrix.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::compute(), Eigen::SparseLU< MatrixType_, OrderingType_ >::initperfvalues(), and matrix().
|
inline |
|
private |
|
inline |
References Eigen::SparseLU< MatrixType_, OrderingType_ >::colsPermutation(), eigen_assert, EIGEN_STATIC_ASSERT, Eigen::PermutationBase< Derived >::inverse(), j, Eigen::SparseLU< MatrixType_, OrderingType_ >::m_factorizationIsOk, Eigen::SparseLU< MatrixType_, OrderingType_ >::matrixL(), Eigen::SparseLU< MatrixType_, OrderingType_ >::matrixU(), Eigen::RowMajorBit, Eigen::SparseLU< MatrixType_, OrderingType_ >::rowsPermutation(), and X.
|
inline |
Give the absolute value of the determinant.
References abs(), Eigen::SparseLU< MatrixType_, OrderingType_ >::cols(), eigen_assert, j, Eigen::SparseLU< MatrixType_, OrderingType_ >::m_factorizationIsOk, and Eigen::SparseLU< MatrixType_, OrderingType_ >::m_Lstore.
|
inline |
Return a solver for the adjointed matrix.
A typical usage is to solve for the adjoint problem A' x = b:
For real scalar types, this function is equivalent to transpose().
References Eigen::SparseSolverBase< SparseLU< MatrixType_, OrderingType_ > >::m_isInitialized, Eigen::SparseLUTransposeView< Conjugate, SparseLUType >::setIsInitialized(), and Eigen::SparseLUTransposeView< Conjugate, SparseLUType >::setSparseLU().
void Eigen::SparseLU< MatrixType, OrderingType >::analyzePattern | ( | const MatrixType & | mat | ) |
Compute the column permutation.
Compute the column permutation to minimize the fill-in
It is possible to call compute() instead of analyzePattern() + factorize().
If the matrix is row-major this function will do an heavy copy.
References Eigen::internal::coletree(), Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::cols(), ei_declare_aligned_stack_constructed_variable, i, Eigen::PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_ >::indices(), Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::isCompressed(), m, Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::outerIndexPtr(), Eigen::PlainObjectBase< Derived >::resize(), and Eigen::internal::treePostorder().
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::compute().
|
inline |
Give the number of columns.
References Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::cols(), and Eigen::SparseLU< MatrixType_, OrderingType_ >::m_mat.
Referenced by gdb.printers._MatrixEntryIterator::__next__(), Eigen::SparseLU< MatrixType_, OrderingType_ >::absDeterminant(), gdb.printers.EigenMatrixPrinter::children(), gdb.printers.EigenSparseMatrixPrinter::children(), Eigen::SparseLU< MatrixType_, OrderingType_ >::determinant(), Eigen::SparseLU< MatrixType_, OrderingType_ >::logAbsDeterminant(), Eigen::SparseLU< MatrixType_, OrderingType_ >::signDeterminant(), gdb.printers.EigenMatrixPrinter::to_string(), and gdb.printers.EigenSparseMatrixPrinter::to_string().
|
inline |
Give the column matrix permutation.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_perm_c.
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::_solve_impl(), and Eigen::SparseInverse< Scalar >::computeInverse().
|
inline |
Analyze and factorize the matrix so the solver is ready to solve.
Compute the symbolic and numeric factorization of the input sparse matrix. The input matrix should be in column-major storage, otherwise analyzePattern() will do a heavy copy.
Call analyzePattern() followed by factorize()
References Eigen::SparseLU< MatrixType_, OrderingType_ >::analyzePattern(), Eigen::SparseLU< MatrixType_, OrderingType_ >::factorize(), and matrix().
Referenced by check_sparse_inverse(), Eigen::SparseInverse< Scalar >::compute(), and Eigen::SparseLU< MatrixType_, OrderingType_ >::SparseLU().
|
inline |
Give the determinant.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::cols(), eigen_assert, j, Eigen::SparseLU< MatrixType_, OrderingType_ >::m_detPermC, Eigen::SparseLU< MatrixType_, OrderingType_ >::m_detPermR, Eigen::SparseLU< MatrixType_, OrderingType_ >::m_factorizationIsOk, and Eigen::SparseLU< MatrixType_, OrderingType_ >::m_Lstore.
void Eigen::SparseLU< MatrixType, OrderingType >::factorize | ( | const MatrixType & | matrix | ) |
Factorize the matrix to get the solver ready.
To get error of this function you should check info(), you can get more info of errors with lastErrorMessage().
In the past (before 2012 (git history is not older)), this function was returning an integer. This exit was 0 if successful factorization.
0 if info = i, and i is been completed, but the factor U is exactly singular,
and division by zero will occur if it is used to solve a system of equation.
A->ncol: number of bytes allocated when memory allocation failure occurred, plus A->ncol.
If lwork = -1, it is the estimated amount of space needed, plus A->ncol.
It seems that A was the name of the matrix in the past.
References countnz(), eigen_assert, Eigen::internal::emptyIdxLU, fixupL(), heap_relax_snode(), i, Eigen::PermutationMatrix< SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_ >::indices(), info, k, Eigen::internal::LUNoMarker, Eigen::internal::LUnumTempV(), m, matrix(), min, n, Eigen::NumericalIssue, relax_snode(), Eigen::PlainObjectBase< Derived >::setConstant(), Eigen::PlainObjectBase< Derived >::setZero(), and Eigen::Success.
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::compute().
|
inline |
Reports whether previous computation was successful.
Success
if computation was successful, NumericalIssue
if the LU factorization reports a problem, zero diagonal for instance InvalidInput
if the input matrix is invalidYou can get a readable error message with lastErrorMessage().
References eigen_assert, Eigen::SparseLU< MatrixType_, OrderingType_ >::m_info, and Eigen::SparseSolverBase< SparseLU< MatrixType_, OrderingType_ > >::m_isInitialized.
Referenced by Eigen::SparseInverse< Scalar >::computeInverse().
|
inlineprotected |
References Eigen::internal::perfvalues::colblk, Eigen::internal::perfvalues::fillfactor, Eigen::SparseLU< MatrixType_, OrderingType_ >::m_perfv, Eigen::internal::perfvalues::maxsuper, Eigen::internal::perfvalues::panel_size, Eigen::internal::perfvalues::relax, and Eigen::internal::perfvalues::rowblk.
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::SparseLU().
|
inline |
Let you set that the pattern of the input matrix is symmetric.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_symmetricmode.
|
inline |
Give a human readable error.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_lastError.
|
inline |
Give the natural log of the absolute determinant.
References abs(), Eigen::SparseLU< MatrixType_, OrderingType_ >::cols(), eigen_assert, j, Eigen::bfloat16_impl::log(), Eigen::SparseLU< MatrixType_, OrderingType_ >::m_factorizationIsOk, and Eigen::SparseLU< MatrixType_, OrderingType_ >::m_Lstore.
|
inline |
Give the matrixL.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_Lstore.
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::_solve_impl(), and Eigen::SparseInverse< Scalar >::computeInverse().
|
inline |
Give the MatrixU.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_Lstore, and Eigen::SparseLU< MatrixType_, OrderingType_ >::m_Ustore.
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::_solve_impl(), and Eigen::SparseInverse< Scalar >::computeInverse().
|
inline |
Give the number of non zero in matrix L.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_nnzL.
|
inline |
Give the number of non zero in matrix U.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_nnzU.
|
inline |
Give the number of rows.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_mat, and Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::rows().
Referenced by gdb.printers._MatrixEntryIterator::__next__(), gdb.printers.EigenMatrixPrinter::children(), gdb.printers.EigenSparseMatrixPrinter::children(), gdb.printers.EigenMatrixPrinter::to_string(), and gdb.printers.EigenSparseMatrixPrinter::to_string().
|
inline |
Give the row matrix permutation.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_perm_r.
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::_solve_impl(), and Eigen::SparseInverse< Scalar >::computeInverse().
|
inline |
Set the threshold used for a diagonal entry to be an acceptable pivot.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_diagpivotthresh.
|
inline |
Give the sign of the determinant.
References Eigen::SparseLU< MatrixType_, OrderingType_ >::cols(), eigen_assert, j, Eigen::SparseLU< MatrixType_, OrderingType_ >::m_detPermC, Eigen::SparseLU< MatrixType_, OrderingType_ >::m_detPermR, Eigen::SparseLU< MatrixType_, OrderingType_ >::m_factorizationIsOk, and Eigen::SparseLU< MatrixType_, OrderingType_ >::m_Lstore.
void Eigen::SparseLU< MatrixType_, OrderingType_ >::simplicialfactorize | ( | const MatrixType & | matrix | ) |
|
inline |
Return a solver for the transposed matrix.
A typical usage is to solve for the transposed problem A^T x = b:
References Eigen::SparseSolverBase< SparseLU< MatrixType_, OrderingType_ > >::m_isInitialized, Eigen::SparseLUTransposeView< Conjugate, SparseLUType >::setIsInitialized(), and Eigen::SparseLUTransposeView< Conjugate, SparseLUType >::setSparseLU().
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::_solve_impl(), Eigen::SparseLU< MatrixType_, OrderingType_ >::absDeterminant(), Eigen::SparseLU< MatrixType_, OrderingType_ >::determinant(), Eigen::SparseLU< MatrixType_, OrderingType_ >::logAbsDeterminant(), and Eigen::SparseLU< MatrixType_, OrderingType_ >::signDeterminant().
|
protected |
|
mutableprotected |
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::info().
|
protected |
|
protected |
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::absDeterminant(), Eigen::SparseLU< MatrixType_, OrderingType_ >::determinant(), Eigen::SparseLU< MatrixType_, OrderingType_ >::logAbsDeterminant(), Eigen::SparseLU< MatrixType_, OrderingType_ >::matrixL(), Eigen::SparseLU< MatrixType_, OrderingType_ >::matrixU(), and Eigen::SparseLU< MatrixType_, OrderingType_ >::signDeterminant().
|
protected |
|
protected |
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::nnzL().
|
protected |
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::nnzU().
|
protected |
|
protected |
|
protected |
|
protected |
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::isSymmetric().
|
protected |
Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::matrixU().