Eigen::SparseLU< MatrixType_, OrderingType_ > Class Template Reference

Sparse supernodal LU factorization for general matrices. More...

#include <SparseLU.h>

+ Inheritance diagram for Eigen::SparseLU< MatrixType_, OrderingType_ >:

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, StorageIndexNCMatrix
 
typedef internal::MappedSuperNodalMatrix< Scalar, StorageIndexSCMatrix
 
typedef Matrix< Scalar, Dynamic, 1 > ScalarVector
 
typedef Matrix< StorageIndex, Dynamic, 1 > IndexVector
 
typedef PermutationMatrix< Dynamic, Dynamic, StorageIndexPermutationType
 
typedef internal::SparseLUImpl< Scalar, StorageIndexBase
 
- Public Types inherited from Eigen::internal::SparseLUImpl< MatrixType_::Scalar, MatrixType_::StorageIndex >
typedef Matrix< MatrixType_::Scalar, Dynamic, 1 > ScalarVector
 
typedef Matrix< MatrixType_::StorageIndex, Dynamic, 1 > IndexVector
 
typedef Matrix< MatrixType_::Scalar, Dynamic, Dynamic, ColMajor > ScalarMatrix
 
typedef Map< ScalarMatrix, 0, OuterStride<> > MappedMatrixBlock
 
typedef ScalarVector::RealScalar RealScalar
 
typedef Ref< Matrix< MatrixType_::Scalar, Dynamic, 1 > > BlockScalarVector
 
typedef Ref< Matrix< MatrixType_::StorageIndex, Dynamic, 1 > > BlockIndexVector
 
typedef LU_GlobalLU_t< IndexVector, ScalarVectorGlobalLU_t
 
typedef SparseMatrix< MatrixType_::Scalar, ColMajor, MatrixType_::StorageIndex > MatrixType
 

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< SCMatrixmatrixL () const
 Give the matrixL. More...
 
SparseLUMatrixUReturnType< SCMatrix, Map< SparseMatrix< Scalar, ColMajor, StorageIndex > > > matrixU () const
 Give the MatrixU. More...
 
const PermutationTyperowsPermutation () const
 Give the row matrix permutation. More...
 
const PermutationTypecolsPermutation () 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...
 
- Public Member Functions inherited from Eigen::SparseSolverBase< SparseLU< MatrixType_, OrderingType_ > >
 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 ()
 
- Protected Member Functions inherited from Eigen::internal::SparseLUImpl< MatrixType_::Scalar, MatrixType_::StorageIndex >
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
 
- Protected Attributes inherited from Eigen::SparseSolverBase< SparseLU< MatrixType_, OrderingType_ > >
bool m_isInitialized
 

Private Member Functions

 SparseLU (const SparseLU &)
 

Detailed Description

template<typename MatrixType_, typename OrderingType_>
class Eigen::SparseLU< MatrixType_, OrderingType_ >

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

VectorXd x(n), b(n);
SparseMatrix<double> A;
SparseLU<SparseMatrix<double>, COLAMDOrdering<int> > solver;
// Fill A and b.
// Compute the ordering permutation vector from the structural pattern of A.
solver.analyzePattern(A);
// Compute the numerical factorization.
solver.factorize(A);
// Use the factors to solve the linear system.
x = solver.solve(b);
BiCGSTAB< SparseMatrix< double > > solver
Definition: BiCGSTAB_simple.cpp:5
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Scalar * b
Definition: benchVecAdd.cpp:17
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
list x
Definition: plotDoE.py:28

We can directly call compute() instead of analyzePattern() and factorize()

VectorXd x(n), b(n);
SparseMatrix<double> A;
SparseLU<SparseMatrix<double>, COLAMDOrdering<int> > solver;
// Fill A and b.
solver.compute(A);
// Use the factors to solve the linear system.
x = solver.solve(b);

Or give the matrix to the constructor SparseLU(const MatrixType& matrix)

VectorXd x(n), b(n);
SparseMatrix<double> A;
// Fill A and b.
SparseLU<SparseMatrix<double>, COLAMDOrdering<int> > solver(A);
// Use the factors to solve the linear system.
x = solver.solve(b);
Warning
The input matrix A should be in a compressed and column-major form. Otherwise an expensive copy will be made. You can call the inexpensive makeCompressed() to get a compressed matrix.
Note
Unlike the initial SuperLU implementation, there is no step to equilibrate the matrix. For badly scaled matrices, this step can be useful to reduce the pivoting during factorization. If this is the case for your matrices, you can try the basic scaling method at "unsupported/Eigen/src/IterativeSolvers/Scaling.h"
Template Parameters
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

See also
Sparse solver concept
OrderingMethods_Module

Member Typedef Documentation

◆ APIBase

template<typename MatrixType_ , typename OrderingType_ >
typedef SparseSolverBase<SparseLU<MatrixType_, OrderingType_> > Eigen::SparseLU< MatrixType_, OrderingType_ >::APIBase
protected

◆ Base

template<typename MatrixType_ , typename OrderingType_ >
typedef internal::SparseLUImpl<Scalar, StorageIndex> Eigen::SparseLU< MatrixType_, OrderingType_ >::Base

◆ IndexVector

template<typename MatrixType_ , typename OrderingType_ >
typedef Matrix<StorageIndex, Dynamic, 1> Eigen::SparseLU< MatrixType_, OrderingType_ >::IndexVector

◆ MatrixType

template<typename MatrixType_ , typename OrderingType_ >
typedef MatrixType_ Eigen::SparseLU< MatrixType_, OrderingType_ >::MatrixType

◆ NCMatrix

template<typename MatrixType_ , typename OrderingType_ >
typedef SparseMatrix<Scalar, ColMajor, StorageIndex> Eigen::SparseLU< MatrixType_, OrderingType_ >::NCMatrix

◆ OrderingType

template<typename MatrixType_ , typename OrderingType_ >
typedef OrderingType_ Eigen::SparseLU< MatrixType_, OrderingType_ >::OrderingType

◆ PermutationType

template<typename MatrixType_ , typename OrderingType_ >
typedef PermutationMatrix<Dynamic, Dynamic, StorageIndex> Eigen::SparseLU< MatrixType_, OrderingType_ >::PermutationType

◆ RealScalar

template<typename MatrixType_ , typename OrderingType_ >
typedef MatrixType::RealScalar Eigen::SparseLU< MatrixType_, OrderingType_ >::RealScalar

◆ Scalar

template<typename MatrixType_ , typename OrderingType_ >
typedef MatrixType::Scalar Eigen::SparseLU< MatrixType_, OrderingType_ >::Scalar

◆ ScalarVector

template<typename MatrixType_ , typename OrderingType_ >
typedef Matrix<Scalar, Dynamic, 1> Eigen::SparseLU< MatrixType_, OrderingType_ >::ScalarVector

◆ SCMatrix

template<typename MatrixType_ , typename OrderingType_ >
typedef internal::MappedSuperNodalMatrix<Scalar, StorageIndex> Eigen::SparseLU< MatrixType_, OrderingType_ >::SCMatrix

◆ StorageIndex

template<typename MatrixType_ , typename OrderingType_ >
typedef MatrixType::StorageIndex Eigen::SparseLU< MatrixType_, OrderingType_ >::StorageIndex

Member Enumeration Documentation

◆ anonymous enum

template<typename MatrixType_ , typename OrderingType_ >
anonymous enum
Enumerator
ColsAtCompileTime 
MaxColsAtCompileTime 
171 { ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime };
@ ColsAtCompileTime
Definition: SparseLU.h:171
@ MaxColsAtCompileTime
Definition: SparseLU.h:171

Constructor & Destructor Documentation

◆ SparseLU() [1/3]

template<typename MatrixType_ , typename OrderingType_ >
Eigen::SparseLU< MatrixType_, OrderingType_ >::SparseLU ( )
inline

Basic constructor of the solver.

Construct a SparseLU. As no matrix is given as argument, compute() should be called afterward with a matrix.

179  : m_lastError(""), m_Ustore(0, 0, 0, 0, 0, 0), m_symmetricmode(false), m_diagpivotthresh(1.0), m_detPermR(1) {
180  initperfvalues();
181  }
std::string m_lastError
Definition: SparseLU.h:488
Index m_detPermR
Definition: SparseLU.h:504
Map< SparseMatrix< Scalar, ColMajor, StorageIndex > > m_Ustore
Definition: SparseLU.h:491
void initperfvalues()
Definition: SparseLU.h:475
bool m_symmetricmode
Definition: SparseLU.h:499
RealScalar m_diagpivotthresh
Definition: SparseLU.h:502

References Eigen::SparseLU< MatrixType_, OrderingType_ >::initperfvalues().

◆ SparseLU() [2/3]

template<typename MatrixType_ , typename OrderingType_ >
Eigen::SparseLU< MatrixType_, OrderingType_ >::SparseLU ( const MatrixType matrix)
inlineexplicit

Constructor of the solver already based on a specific matrix.

Construct a SparseLU. compute() is already called with the given matrix.

187  : m_lastError(""), m_Ustore(0, 0, 0, 0, 0, 0), m_symmetricmode(false), m_diagpivotthresh(1.0), m_detPermR(1) {
188  initperfvalues();
189  compute(matrix);
190  }
void compute(const MatrixType &matrix)
Analyze and factorize the matrix so the solver is ready to solve.
Definition: SparseLU.h:210
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85

References Eigen::SparseLU< MatrixType_, OrderingType_ >::compute(), Eigen::SparseLU< MatrixType_, OrderingType_ >::initperfvalues(), and matrix().

◆ ~SparseLU()

template<typename MatrixType_ , typename OrderingType_ >
Eigen::SparseLU< MatrixType_, OrderingType_ >::~SparseLU ( )
inline
192  {
193  // Free all explicit dynamic pointers
194  }

◆ SparseLU() [3/3]

template<typename MatrixType_ , typename OrderingType_ >
Eigen::SparseLU< MatrixType_, OrderingType_ >::SparseLU ( const SparseLU< MatrixType_, OrderingType_ > &  )
private

Member Function Documentation

◆ _solve_impl()

template<typename MatrixType_ , typename OrderingType_ >
template<typename Rhs , typename Dest >
bool Eigen::SparseLU< MatrixType_, OrderingType_ >::_solve_impl ( const MatrixBase< Rhs > &  B,
MatrixBase< Dest > &  X_base 
) const
inline
338  {
339  Dest& X(X_base.derived());
340  eigen_assert(m_factorizationIsOk && "The matrix should be factorized first");
341  EIGEN_STATIC_ASSERT((Dest::Flags & RowMajorBit) == 0, THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
342 
343  // Permute the right hand side to form X = Pr*B
344  // on return, X is overwritten by the computed solution
345  X.resize(B.rows(), B.cols());
346 
347  // this ugly const_cast_derived() helps to detect aliasing when applying the permutations
348  for (Index j = 0; j < B.cols(); ++j) X.col(j) = rowsPermutation() * B.const_cast_derived().col(j);
349 
350  // Forward substitution with L
351  this->matrixL().solveInPlace(X);
352  this->matrixU().solveInPlace(X);
353 
354  // Permute back the solution
355  for (Index j = 0; j < B.cols(); ++j) X.col(j) = colsPermutation().inverse() * X.col(j);
356 
357  return true;
358  }
#define eigen_assert(x)
Definition: Macros.h:910
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
InverseReturnType inverse() const
Definition: PermutationMatrix.h:172
bool m_factorizationIsOk
Definition: SparseLU.h:486
SparseLUMatrixUReturnType< SCMatrix, Map< SparseMatrix< Scalar, ColMajor, StorageIndex > > > matrixU() const
Give the MatrixU.
Definition: SparseLU.h:284
const PermutationType & rowsPermutation() const
Give the row matrix permutation.
Definition: SparseLU.h:293
SparseLUMatrixLReturnType< SCMatrix > matrixL() const
Give the matrixL.
Definition: SparseLU.h:275
const PermutationType & colsPermutation() const
Give the column matrix permutation.
Definition: SparseLU.h:299
Definition: matrices.h:74
const unsigned int RowMajorBit
Definition: Constants.h:70
#define X
Definition: icosphere.cpp:20
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

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.

◆ absDeterminant()

template<typename MatrixType_ , typename OrderingType_ >
Scalar Eigen::SparseLU< MatrixType_, OrderingType_ >::absDeterminant ( )
inline

Give the absolute value of the determinant.

Returns
the absolute value of the determinant of the matrix of which *this is the QR decomposition.
Warning
a determinant can be very big or small, so for matrices of large enough dimension, there is a risk of overflow/underflow. One way to work around that is to use logAbsDeterminant() instead.
See also
logAbsDeterminant(), signDeterminant()
371  {
372  using std::abs;
373  eigen_assert(m_factorizationIsOk && "The matrix should be factorized first.");
374  // Initialize with the determinant of the row matrix
375  Scalar det = Scalar(1.);
376  // Note that the diagonal blocks of U are stored in supernodes,
377  // which are available in the L part :)
378  for (Index j = 0; j < this->cols(); ++j) {
379  for (typename SCMatrix::InnerIterator it(m_Lstore, j); it; ++it) {
380  if (it.index() == j) {
381  det *= abs(it.value());
382  break;
383  }
384  }
385  }
386  return det;
387  }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
SCALAR Scalar
Definition: bench_gemm.cpp:45
Index cols() const
Give the number of columns.
Definition: SparseLU.h:262
MatrixType::Scalar Scalar
Definition: SparseLU.h:161
SCMatrix m_Lstore
Definition: SparseLU.h:490

References abs(), Eigen::SparseLU< MatrixType_, OrderingType_ >::cols(), eigen_assert, j, Eigen::SparseLU< MatrixType_, OrderingType_ >::m_factorizationIsOk, and Eigen::SparseLU< MatrixType_, OrderingType_ >::m_Lstore.

◆ adjoint()

template<typename MatrixType_ , typename OrderingType_ >
const SparseLUTransposeView<true, SparseLU<MatrixType_, OrderingType_> > Eigen::SparseLU< MatrixType_, OrderingType_ >::adjoint ( )
inline

Return a solver for the adjointed matrix.

Returns
an expression of the adjoint of the factored matrix

A typical usage is to solve for the adjoint problem A' x = b:

solver.compute(A);
x = solver.adjoint().solve(b);

For real scalar types, this function is equivalent to transpose().

See also
transpose(), solve()
250  {
251  SparseLUTransposeView<true, SparseLU<MatrixType_, OrderingType_>> adjointView;
252  adjointView.setSparseLU(this);
253  adjointView.setIsInitialized(this->m_isInitialized);
254  return adjointView;
255  }

References Eigen::SparseSolverBase< SparseLU< MatrixType_, OrderingType_ > >::m_isInitialized, Eigen::SparseLUTransposeView< Conjugate, SparseLUType >::setIsInitialized(), and Eigen::SparseLUTransposeView< Conjugate, SparseLUType >::setSparseLU().

◆ analyzePattern()

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

Compute the column permutation.

Compute the column permutation to minimize the fill-in

  • Apply this permutation to the input matrix -
  • Compute the column elimination tree on the permuted matrix
  • Postorder the elimination tree and the column permutation

It is possible to call compute() instead of analyzePattern() + factorize().

If the matrix is row-major this function will do an heavy copy.

See also
factorize(), compute()
528  {
529  // TODO It is possible as in SuperLU to compute row and columns scaling vectors to equilibrate the matrix mat.
530 
531  // Firstly, copy the whole input matrix.
532  m_mat = mat;
533 
534  // Compute fill-in ordering
535  OrderingType ord;
536  ord(m_mat, m_perm_c);
537 
538  // Apply the permutation to the column of the input matrix
539  if (m_perm_c.size()) {
540  m_mat.uncompress(); // NOTE: The effect of this command is only to create the InnerNonzeros pointers. FIXME : This
541  // vector is filled but not subsequently used.
542  // Then, permute only the column pointers
544  StorageIndex, outerIndexPtr, mat.cols() + 1,
545  mat.isCompressed() ? const_cast<StorageIndex*>(mat.outerIndexPtr()) : 0);
546 
547  // If the input matrix 'mat' is uncompressed, then the outer-indices do not match the ones of m_mat, and a copy is
548  // thus needed.
549  if (!mat.isCompressed())
550  IndexVector::Map(outerIndexPtr, mat.cols() + 1) = IndexVector::Map(m_mat.outerIndexPtr(), mat.cols() + 1);
551 
552  // Apply the permutation and compute the nnz per column.
553  for (Index i = 0; i < mat.cols(); i++) {
554  m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i];
555  m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i + 1] - outerIndexPtr[i];
556  }
557  }
558 
559  // Compute the column elimination tree of the permuted matrix
560  IndexVector firstRowElt;
561  internal::coletree(m_mat, m_etree, firstRowElt);
562 
563  // In symmetric mode, do not do postorder here
564  if (!m_symmetricmode) {
565  IndexVector post, iwork;
566  // Post order etree
568 
569  // Renumber etree in postorder
570  Index m = m_mat.cols();
571  iwork.resize(m + 1);
572  for (Index i = 0; i < m; ++i) iwork(post(i)) = post(m_etree(i));
573  m_etree = iwork;
574 
575  // Postmultiply A*Pc by post, i.e reorder the matrix according to the postorder of the etree
576  PermutationType post_perm(m);
577  for (Index i = 0; i < m; i++) post_perm.indices()(i) = post(i);
578 
579  // Combine the two permutations : postorder the permutation for future use
580  if (m_perm_c.size()) {
581  m_perm_c = post_perm * m_perm_c;
582  }
583 
584  } // end postordering
585 
586  m_analysisIsOk = true;
587 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::SparseMatrix< double > mat
Definition: EigenUnitTest.cpp:10
#define ei_declare_aligned_stack_constructed_variable(TYPE, NAME, SIZE, BUFFER)
Definition: Memory.h:806
EIGEN_DEVICE_FUNC Index size() const
Definition: PermutationMatrix.h:96
const IndicesType & indices() const
Definition: PermutationMatrix.h:334
static ConstMapType Map(const Scalar *data)
Definition: PlainObjectBase.h:595
PermutationType m_perm_c
Definition: SparseLU.h:492
NCMatrix m_mat
Definition: SparseLU.h:489
Matrix< StorageIndex, Dynamic, 1 > IndexVector
Definition: SparseLU.h:167
bool m_analysisIsOk
Definition: SparseLU.h:487
OrderingType_ OrderingType
Definition: SparseLU.h:160
PermutationMatrix< Dynamic, Dynamic, StorageIndex > PermutationType
Definition: SparseLU.h:168
IndexVector m_etree
Definition: SparseLU.h:494
MatrixType::StorageIndex StorageIndex
Definition: SparseLU.h:163
Index cols() const
Definition: SparseMatrix.h:161
void uncompress()
Definition: SparseMatrix.h:622
const StorageIndex * innerNonZeroPtr() const
Definition: SparseMatrix.h:198
bool isCompressed() const
Definition: SparseCompressedBase.h:114
const StorageIndex * outerIndexPtr() const
Definition: SparseMatrix.h:189
int * m
Definition: level2_cplx_impl.h:294
int coletree(const MatrixType &mat, IndexVector &parent, IndexVector &firstRowElt, typename MatrixType::StorageIndex *perm=0)
Definition: SparseColEtree.h:61
void treePostorder(typename IndexVector::Scalar n, IndexVector &parent, IndexVector &post)
Post order a tree.
Definition: SparseColEtree.h:168

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().

◆ cols()

◆ colsPermutation()

template<typename MatrixType_ , typename OrderingType_ >
const PermutationType& Eigen::SparseLU< MatrixType_, OrderingType_ >::colsPermutation ( ) const
inline

Give the column matrix permutation.

Returns
a reference to the column matrix permutation \( P_c^T \) such that \(P_r A P_c^T = L U\)
See also
rowsPermutation()
299 { return m_perm_c; }

References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_perm_c.

Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::_solve_impl(), and Eigen::SparseInverse< Scalar >::computeInverse().

◆ compute()

template<typename MatrixType_ , typename OrderingType_ >
void Eigen::SparseLU< MatrixType_, OrderingType_ >::compute ( const MatrixType matrix)
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()

See also
analyzePattern(), factorize()
210  {
211  // Analyze
213  // Factorize
214  factorize(matrix);
215  }
void factorize(const MatrixType &matrix)
Factorize the matrix to get the solver ready.
Definition: SparseLU.h:611
void analyzePattern(const MatrixType &matrix)
Compute the column permutation.
Definition: SparseLU.h:528

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().

◆ determinant()

template<typename MatrixType_ , typename OrderingType_ >
Scalar Eigen::SparseLU< MatrixType_, OrderingType_ >::determinant ( )
inline

Give the determinant.

Returns
The determinant of the matrix.
See also
absDeterminant(), logAbsDeterminant()
449  {
450  eigen_assert(m_factorizationIsOk && "The matrix should be factorized first.");
451  // Initialize with the determinant of the row matrix
452  Scalar det = Scalar(1.);
453  // Note that the diagonal blocks of U are stored in supernodes,
454  // which are available in the L part :)
455  for (Index j = 0; j < this->cols(); ++j) {
456  for (typename SCMatrix::InnerIterator it(m_Lstore, j); it; ++it) {
457  if (it.index() == j) {
458  det *= it.value();
459  break;
460  }
461  }
462  }
463  return (m_detPermR * m_detPermC) > 0 ? det : -det;
464  }
Index m_detPermC
Definition: SparseLU.h:504

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.

◆ factorize()

template<typename MatrixType , typename OrderingType >
void Eigen::SparseLU< MatrixType, OrderingType >::factorize ( const MatrixType matrix)

Factorize the matrix to get the solver ready.

  • Numerical factorization
  • Interleaved with the symbolic factorization

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.

See also
analyzePattern(), compute(), SparseLU(), info(), lastErrorMessage()
611  {
612  using internal::emptyIdxLU;
613  eigen_assert(m_analysisIsOk && "analyzePattern() should be called first");
614  eigen_assert((matrix.rows() == matrix.cols()) && "Only for squared matrices");
615 
616  m_isInitialized = true;
617 
618  // Apply the column permutation computed in analyzepattern()
619  // m_mat = matrix * m_perm_c.inverse();
620  m_mat = matrix;
621  if (m_perm_c.size()) {
622  m_mat.uncompress(); // NOTE: The effect of this command is only to create the InnerNonzeros pointers.
623  // Then, permute only the column pointers
624  const StorageIndex* outerIndexPtr;
625  if (matrix.isCompressed())
626  outerIndexPtr = matrix.outerIndexPtr();
627  else {
628  StorageIndex* outerIndexPtr_t = new StorageIndex[matrix.cols() + 1];
629  for (Index i = 0; i <= matrix.cols(); i++) outerIndexPtr_t[i] = m_mat.outerIndexPtr()[i];
630  outerIndexPtr = outerIndexPtr_t;
631  }
632  for (Index i = 0; i < matrix.cols(); i++) {
633  m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i];
634  m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i + 1] - outerIndexPtr[i];
635  }
636  if (!matrix.isCompressed()) delete[] outerIndexPtr;
637  } else { // FIXME This should not be needed if the empty permutation is handled transparently
638  m_perm_c.resize(matrix.cols());
639  for (StorageIndex i = 0; i < matrix.cols(); ++i) m_perm_c.indices()(i) = i;
640  }
641 
642  Index m = m_mat.rows();
643  Index n = m_mat.cols();
644  Index nnz = m_mat.nonZeros();
645  Index maxpanel = m_perfv.panel_size * m;
646  // Allocate working storage common to the factor routines
647  Index lwork = 0;
648  // Return the size of actually allocated memory when allocation failed,
649  // and 0 on success.
651  if (info) {
652  m_lastError = "UNABLE TO ALLOCATE WORKING MEMORY\n\n";
653  m_factorizationIsOk = false;
654  return;
655  }
656 
657  // Set up pointers for integer working arrays
658  IndexVector segrep(m);
659  segrep.setZero();
660  IndexVector parent(m);
661  parent.setZero();
662  IndexVector xplore(m);
663  xplore.setZero();
664  IndexVector repfnz(maxpanel);
665  IndexVector panel_lsub(maxpanel);
666  IndexVector xprune(n);
667  xprune.setZero();
669  marker.setZero();
670 
671  repfnz.setConstant(-1);
672  panel_lsub.setConstant(-1);
673 
674  // Set up pointers for scalar working arrays
675  ScalarVector dense;
676  dense.setZero(maxpanel);
677  ScalarVector tempv;
678  tempv.setZero(internal::LUnumTempV(m, m_perfv.panel_size, m_perfv.maxsuper, /*m_perfv.rowblk*/ m));
679 
680  // Compute the inverse of perm_c
681  PermutationType iperm_c(m_perm_c.inverse());
682 
683  // Identify initial relaxed snodes
684  IndexVector relax_end(n);
685  if (m_symmetricmode == true)
686  Base::heap_relax_snode(n, m_etree, m_perfv.relax, marker, relax_end);
687  else
688  Base::relax_snode(n, m_etree, m_perfv.relax, marker, relax_end);
689 
690  m_perm_r.resize(m);
691  m_perm_r.indices().setConstant(-1);
692  marker.setConstant(-1);
693  m_detPermR = 1; // Record the determinant of the row permutation
694 
695  m_glu.supno(0) = emptyIdxLU;
697  m_glu.xsup(0) = m_glu.xlsub(0) = m_glu.xusub(0) = m_glu.xlusup(0) = Index(0);
698 
699  // Work on one 'panel' at a time. A panel is one of the following :
700  // (a) a relaxed supernode at the bottom of the etree, or
701  // (b) panel_size contiguous columns, <panel_size> defined by the user
702  Index jcol;
703  Index pivrow; // Pivotal row number in the original row matrix
704  Index nseg1; // Number of segments in U-column above panel row jcol
705  Index nseg; // Number of segments in each U-column
706  Index irep;
707  Index i, k, jj;
708  for (jcol = 0; jcol < n;) {
709  // Adjust panel size so that a panel won't overlap with the next relaxed snode.
710  Index panel_size = m_perfv.panel_size; // upper bound on panel width
711  for (k = jcol + 1; k < (std::min)(jcol + panel_size, n); k++) {
712  if (relax_end(k) != emptyIdxLU) {
713  panel_size = k - jcol;
714  break;
715  }
716  }
717  if (k == n) panel_size = n - jcol;
718 
719  // Symbolic outer factorization on a panel of columns
720  Base::panel_dfs(m, panel_size, jcol, m_mat, m_perm_r.indices(), nseg1, dense, panel_lsub, segrep, repfnz, xprune,
721  marker, parent, xplore, m_glu);
722 
723  // Numeric sup-panel updates in topological order
724  Base::panel_bmod(m, panel_size, jcol, nseg1, dense, tempv, segrep, repfnz, m_glu);
725 
726  // Sparse LU within the panel, and below the panel diagonal
727  for (jj = jcol; jj < jcol + panel_size; jj++) {
728  k = (jj - jcol) * m; // Column index for w-wide arrays
729 
730  nseg = nseg1; // begin after all the panel segments
731  // Depth-first-search for the current column
732  VectorBlock<IndexVector> panel_lsubk(panel_lsub, k, m);
733  VectorBlock<IndexVector> repfnz_k(repfnz, k, m);
734  // Return 0 on success and > 0 number of bytes allocated when run out of space.
735  info = Base::column_dfs(m, jj, m_perm_r.indices(), m_perfv.maxsuper, nseg, panel_lsubk, segrep, repfnz_k, xprune,
736  marker, parent, xplore, m_glu);
737  if (info) {
738  m_lastError = "UNABLE TO EXPAND MEMORY IN COLUMN_DFS() ";
740  m_factorizationIsOk = false;
741  return;
742  }
743  // Numeric updates to this column
744  VectorBlock<ScalarVector> dense_k(dense, k, m);
745  VectorBlock<IndexVector> segrep_k(segrep, nseg1, m - nseg1);
746  // Return 0 on success and > 0 number of bytes allocated when run out of space.
747  info = Base::column_bmod(jj, (nseg - nseg1), dense_k, tempv, segrep_k, repfnz_k, jcol, m_glu);
748  if (info) {
749  m_lastError = "UNABLE TO EXPAND MEMORY IN COLUMN_BMOD() ";
751  m_factorizationIsOk = false;
752  return;
753  }
754 
755  // Copy the U-segments to ucol(*)
756  // Return 0 on success and > 0 number of bytes allocated when run out of space.
757  info = Base::copy_to_ucol(jj, nseg, segrep, repfnz_k, m_perm_r.indices(), dense_k, m_glu);
758  if (info) {
759  m_lastError = "UNABLE TO EXPAND MEMORY IN COPY_TO_UCOL() ";
761  m_factorizationIsOk = false;
762  return;
763  }
764 
765  // Form the L-segment
766  // Return O if success, i > 0 if U(i, i) is exactly zero.
767  info = Base::pivotL(jj, m_diagpivotthresh, m_perm_r.indices(), iperm_c.indices(), pivrow, m_glu);
768  if (info) {
769  m_lastError = "THE MATRIX IS STRUCTURALLY SINGULAR";
770 #ifndef EIGEN_NO_IO
771  std::ostringstream returnInfo;
772  returnInfo << " ... ZERO COLUMN AT ";
773  returnInfo << info;
774  m_lastError += returnInfo.str();
775 #endif
777  m_factorizationIsOk = false;
778  return;
779  }
780 
781  // Update the determinant of the row permutation matrix
782  // FIXME: the following test is not correct, we should probably take iperm_c into account and pivrow is not
783  // directly the row pivot.
784  if (pivrow != jj) m_detPermR = -m_detPermR;
785 
786  // Prune columns (0:jj-1) using column jj
787  Base::pruneL(jj, m_perm_r.indices(), pivrow, nseg, segrep, repfnz_k, xprune, m_glu);
788 
789  // Reset repfnz for this column
790  for (i = 0; i < nseg; i++) {
791  irep = segrep(i);
792  repfnz_k(irep) = emptyIdxLU;
793  }
794  } // end SparseLU within the panel
795  jcol += panel_size; // Move to the next panel
796  } // end for -- end elimination
797 
800 
801  // Count the number of nonzeros in factors
803  // Apply permutation to the L subscripts
805 
806  // Create supernode matrix L
808  // Create the column major upper sparse matrix U;
809  new (&m_Ustore) Map<SparseMatrix<Scalar, ColMajor, StorageIndex>>(m, n, m_nnzU, m_glu.xusub.data(), m_glu.usub.data(),
810  m_glu.ucol.data());
811 
812  m_info = Success;
813  m_factorizationIsOk = true;
814 }
void resize(Index newSize)
Definition: PermutationMatrix.h:119
Index determinant() const
Definition: PermutationMatrix.h:228
constexpr EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: PlainObjectBase.h:273
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:569
EIGEN_DEVICE_FUNC Derived & setConstant(Index size, const Scalar &val)
Definition: CwiseNullaryOp.h:365
Matrix< Scalar, Dynamic, 1 > ScalarVector
Definition: SparseLU.h:166
Index m_nnzU
Definition: SparseLU.h:503
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: SparseLU.h:326
internal::perfvalues m_perfv
Definition: SparseLU.h:501
Index m_nnzL
Definition: SparseLU.h:503
PermutationType m_perm_r
Definition: SparseLU.h:493
Base::GlobalLU_t m_glu
Definition: SparseLU.h:496
ComputationInfo m_info
Definition: SparseLU.h:485
Index nonZeros() const
Definition: SparseCompressedBase.h:64
Index rows() const
Definition: SparseMatrix.h:159
void setInfos(Index m, Index n, ScalarVector &nzval, IndexVector &nzval_colptr, IndexVector &rowind, IndexVector &rowind_colptr, IndexVector &col_to_sup, IndexVector &sup_to_col)
Definition: SparseLU_SupernodalMatrix.h:57
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.
Definition: SparseLU_panel_bmod.h:59
void relax_snode(const Index n, IndexVector &et, const Index relax_columns, IndexVector &descendants, IndexVector &relax_end)
Identify the initial relaxed supernodes.
Definition: SparseLU_relax_snode.h:50
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.
Definition: SparseLU_pruneL.h:56
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.
Definition: SparseLU_column_dfs.h:90
void heap_relax_snode(const Index n, IndexVector &et, const Index relax_columns, IndexVector &descendants, IndexVector &relax_end)
Identify the initial relaxed supernodes.
Definition: SparseLU_heap_relax_snode.h:49
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.
Definition: SparseLU_pivotL.h:63
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.
Definition: SparseLU_Memory.h:139
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)
Definition: SparseLU_panel_dfs.h:197
void countnz(const Index n, Index &nnzL, Index &nnzU, GlobalLU_t &glu)
Count Nonzero elements in the factors.
Definition: SparseLU_Utils.h:23
void fixupL(const Index n, const IndexVector &perm_r, GlobalLU_t &glu)
Fix up the data storage lsub for L-subscripts.
Definition: SparseLU_Utils.h:51
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.
Definition: SparseLU_column_bmod.h:56
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.
Definition: SparseLU_copy_to_ucol.h:53
#define min(a, b)
Definition: datatypes.h:22
@ NumericalIssue
Definition: Constants.h:442
@ Success
Definition: Constants.h:440
char char char int int * k
Definition: level2_impl.h:374
Index LUnumTempV(Index &m, Index &w, Index &t, Index &b)
Definition: SparseLU_Memory.h:42
@ LUNoMarker
Definition: SparseLU_Memory.h:40
@ emptyIdxLU
Definition: SparseLU_Memory.h:41
IndexVector usub
Definition: SparseLU_Structs.h:91
IndexVector xsup
Definition: SparseLU_Structs.h:82
IndexVector xlusup
Definition: SparseLU_Structs.h:86
IndexVector supno
Definition: SparseLU_Structs.h:83
IndexVector lsub
Definition: SparseLU_Structs.h:85
IndexVector xusub
Definition: SparseLU_Structs.h:92
IndexVector xlsub
Definition: SparseLU_Structs.h:87
ScalarVector lusup
Definition: SparseLU_Structs.h:84
ScalarVector ucol
Definition: SparseLU_Structs.h:90
Index relax
Definition: SparseLU_Structs.h:101
Index panel_size
Definition: SparseLU_Structs.h:100
Index maxsuper
Definition: SparseLU_Structs.h:104
Index fillfactor
Definition: SparseLU_Structs.h:107

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().

◆ info()

template<typename MatrixType_ , typename OrderingType_ >
ComputationInfo Eigen::SparseLU< MatrixType_, OrderingType_ >::info ( ) const
inline

Reports whether previous computation was successful.

Returns
Success if computation was successful, NumericalIssue if the LU factorization reports a problem, zero diagonal for instance InvalidInput if the input matrix is invalid

You can get a readable error message with lastErrorMessage().

See also
lastErrorMessage()
326  {
327  eigen_assert(m_isInitialized && "Decomposition is not initialized.");
328  return m_info;
329  }

References eigen_assert, Eigen::SparseLU< MatrixType_, OrderingType_ >::m_info, and Eigen::SparseSolverBase< SparseLU< MatrixType_, OrderingType_ > >::m_isInitialized.

Referenced by Eigen::SparseInverse< Scalar >::computeInverse().

◆ initperfvalues()

template<typename MatrixType_ , typename OrderingType_ >
void Eigen::SparseLU< MatrixType_, OrderingType_ >::initperfvalues ( )
inlineprotected

◆ isSymmetric()

template<typename MatrixType_ , typename OrderingType_ >
void Eigen::SparseLU< MatrixType_, OrderingType_ >::isSymmetric ( bool  sym)
inline

Let you set that the pattern of the input matrix is symmetric.

265 { m_symmetricmode = sym; }

References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_symmetricmode.

◆ lastErrorMessage()

template<typename MatrixType_ , typename OrderingType_ >
std::string Eigen::SparseLU< MatrixType_, OrderingType_ >::lastErrorMessage ( ) const
inline

Give a human readable error.

Returns
A string describing the type of error
335 { return m_lastError; }

References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_lastError.

◆ logAbsDeterminant()

template<typename MatrixType_ , typename OrderingType_ >
Scalar Eigen::SparseLU< MatrixType_, OrderingType_ >::logAbsDeterminant ( ) const
inline

Give the natural log of the absolute determinant.

Returns
the natural log of the absolute value of the determinant of the matrix of which **this is the QR decomposition
Note
This method is useful to work around the risk of overflow/underflow that's inherent to the determinant computation.
See also
absDeterminant(), signDeterminant()
399  {
400  using std::abs;
401  using std::log;
402 
403  eigen_assert(m_factorizationIsOk && "The matrix should be factorized first.");
404  Scalar det = Scalar(0.);
405  for (Index j = 0; j < this->cols(); ++j) {
406  for (typename SCMatrix::InnerIterator it(m_Lstore, j); it; ++it) {
407  if (it.row() < j) continue;
408  if (it.row() == j) {
409  det += log(abs(it.value()));
410  break;
411  }
412  }
413  }
414  return det;
415  }
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log(const bfloat16 &a)
Definition: BFloat16.h:618

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.

◆ matrixL()

template<typename MatrixType_ , typename OrderingType_ >
SparseLUMatrixLReturnType<SCMatrix> Eigen::SparseLU< MatrixType_, OrderingType_ >::matrixL ( ) const
inline

Give the matrixL.

Returns
an expression of the matrix L, internally stored as supernodes The only operation available with this expression is the triangular solve
y = b; matrixL().solveInPlace(y);
Scalar * y
Definition: level1_cplx_impl.h:128
275 { return SparseLUMatrixLReturnType<SCMatrix>(m_Lstore); }

References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_Lstore.

Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::_solve_impl(), and Eigen::SparseInverse< Scalar >::computeInverse().

◆ matrixU()

template<typename MatrixType_ , typename OrderingType_ >
SparseLUMatrixUReturnType<SCMatrix, Map<SparseMatrix<Scalar, ColMajor, StorageIndex> > > Eigen::SparseLU< MatrixType_, OrderingType_ >::matrixU ( ) const
inline

Give the MatrixU.

Returns
an expression of the matrix U, The only operation available with this expression is the triangular solve
y = b; matrixU().solveInPlace(y);
284  {
285  return SparseLUMatrixUReturnType<SCMatrix, Map<SparseMatrix<Scalar, ColMajor, StorageIndex>>>(m_Lstore, m_Ustore);
286  }

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().

◆ nnzL()

template<typename MatrixType_ , typename OrderingType_ >
Index Eigen::SparseLU< MatrixType_, OrderingType_ >::nnzL ( ) const
inline

Give the number of non zero in matrix L.

468 { return m_nnzL; }

References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_nnzL.

◆ nnzU()

template<typename MatrixType_ , typename OrderingType_ >
Index Eigen::SparseLU< MatrixType_, OrderingType_ >::nnzU ( ) const
inline

Give the number of non zero in matrix U.

471 { return m_nnzU; }

References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_nnzU.

◆ rows()

◆ rowsPermutation()

template<typename MatrixType_ , typename OrderingType_ >
const PermutationType& Eigen::SparseLU< MatrixType_, OrderingType_ >::rowsPermutation ( ) const
inline

Give the row matrix permutation.

Returns
a reference to the row matrix permutation \( P_r \) such that \(P_r A P_c^T = L U\)
See also
colsPermutation()
293 { return m_perm_r; }

References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_perm_r.

Referenced by Eigen::SparseLU< MatrixType_, OrderingType_ >::_solve_impl(), and Eigen::SparseInverse< Scalar >::computeInverse().

◆ setPivotThreshold()

template<typename MatrixType_ , typename OrderingType_ >
void Eigen::SparseLU< MatrixType_, OrderingType_ >::setPivotThreshold ( const RealScalar thresh)
inline

Set the threshold used for a diagonal entry to be an acceptable pivot.

301 { m_diagpivotthresh = thresh; }

References Eigen::SparseLU< MatrixType_, OrderingType_ >::m_diagpivotthresh.

◆ signDeterminant()

template<typename MatrixType_ , typename OrderingType_ >
Scalar Eigen::SparseLU< MatrixType_, OrderingType_ >::signDeterminant ( )
inline

Give the sign of the determinant.

Returns
A number representing the sign of the determinant
See also
absDeterminant(), logAbsDeterminant()
423  {
424  eigen_assert(m_factorizationIsOk && "The matrix should be factorized first.");
425  // Initialize with the determinant of the row matrix
426  Index det = 1;
427  // Note that the diagonal blocks of U are stored in supernodes,
428  // which are available in the L part :)
429  for (Index j = 0; j < this->cols(); ++j) {
430  for (typename SCMatrix::InnerIterator it(m_Lstore, j); it; ++it) {
431  if (it.index() == j) {
432  if (it.value() < 0)
433  det = -det;
434  else if (it.value() == 0)
435  return 0;
436  break;
437  }
438  }
439  }
440  return det * m_detPermR * m_detPermC;
441  }

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.

◆ simplicialfactorize()

template<typename MatrixType_ , typename OrderingType_ >
void Eigen::SparseLU< MatrixType_, OrderingType_ >::simplicialfactorize ( const MatrixType matrix)

◆ transpose()

template<typename MatrixType_ , typename OrderingType_ >
const SparseLUTransposeView<false, SparseLU<MatrixType_, OrderingType_> > Eigen::SparseLU< MatrixType_, OrderingType_ >::transpose ( )
inline

Return a solver for the transposed matrix.

Returns
an expression of the transposed of the factored matrix.

A typical usage is to solve for the transposed problem A^T x = b:

solver.compute(A);
x = solver.transpose().solve(b);
See also
adjoint(), solve()
229  {
230  SparseLUTransposeView<false, SparseLU<MatrixType_, OrderingType_>> transposeView;
231  transposeView.setSparseLU(this);
232  transposeView.setIsInitialized(this->m_isInitialized);
233  return transposeView;
234  }

References Eigen::SparseSolverBase< SparseLU< MatrixType_, OrderingType_ > >::m_isInitialized, Eigen::SparseLUTransposeView< Conjugate, SparseLUType >::setIsInitialized(), and Eigen::SparseLUTransposeView< Conjugate, SparseLUType >::setSparseLU().

Member Data Documentation

◆ m_analysisIsOk

template<typename MatrixType_ , typename OrderingType_ >
bool Eigen::SparseLU< MatrixType_, OrderingType_ >::m_analysisIsOk
protected

◆ m_detPermC

template<typename MatrixType_ , typename OrderingType_ >
Index Eigen::SparseLU< MatrixType_, OrderingType_ >::m_detPermC
protected

◆ m_detPermR

template<typename MatrixType_ , typename OrderingType_ >
Index Eigen::SparseLU< MatrixType_, OrderingType_ >::m_detPermR
protected

◆ m_diagpivotthresh

template<typename MatrixType_ , typename OrderingType_ >
RealScalar Eigen::SparseLU< MatrixType_, OrderingType_ >::m_diagpivotthresh
protected

◆ m_etree

template<typename MatrixType_ , typename OrderingType_ >
IndexVector Eigen::SparseLU< MatrixType_, OrderingType_ >::m_etree
protected

◆ m_factorizationIsOk

◆ m_glu

template<typename MatrixType_ , typename OrderingType_ >
Base::GlobalLU_t Eigen::SparseLU< MatrixType_, OrderingType_ >::m_glu
protected

◆ m_info

template<typename MatrixType_ , typename OrderingType_ >
ComputationInfo Eigen::SparseLU< MatrixType_, OrderingType_ >::m_info
mutableprotected

◆ m_lastError

template<typename MatrixType_ , typename OrderingType_ >
std::string Eigen::SparseLU< MatrixType_, OrderingType_ >::m_lastError
protected

◆ m_Lstore

◆ m_mat

template<typename MatrixType_ , typename OrderingType_ >
NCMatrix Eigen::SparseLU< MatrixType_, OrderingType_ >::m_mat
protected

◆ m_nnzL

template<typename MatrixType_ , typename OrderingType_ >
Index Eigen::SparseLU< MatrixType_, OrderingType_ >::m_nnzL
protected

◆ m_nnzU

template<typename MatrixType_ , typename OrderingType_ >
Index Eigen::SparseLU< MatrixType_, OrderingType_ >::m_nnzU
protected

◆ m_perfv

template<typename MatrixType_ , typename OrderingType_ >
internal::perfvalues Eigen::SparseLU< MatrixType_, OrderingType_ >::m_perfv
protected

◆ m_perm_c

template<typename MatrixType_ , typename OrderingType_ >
PermutationType Eigen::SparseLU< MatrixType_, OrderingType_ >::m_perm_c
protected

◆ m_perm_r

template<typename MatrixType_ , typename OrderingType_ >
PermutationType Eigen::SparseLU< MatrixType_, OrderingType_ >::m_perm_r
protected

◆ m_symmetricmode

template<typename MatrixType_ , typename OrderingType_ >
bool Eigen::SparseLU< MatrixType_, OrderingType_ >::m_symmetricmode
protected

◆ m_Ustore

template<typename MatrixType_ , typename OrderingType_ >
Map<SparseMatrix<Scalar, ColMajor, StorageIndex> > Eigen::SparseLU< MatrixType_, OrderingType_ >::m_Ustore
protected

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