12 #ifndef EIGEN_SPARSE_LU_H 13 #define EIGEN_SPARSE_LU_H 17 template <
typename _MatrixType,
typename _OrderingType = COLAMDOrdering<
typename _MatrixType::StorageIndex> >
class SparseLU;
73 template <
typename _MatrixType,
typename _OrderingType>
117 void factorize (
const MatrixType& matrix);
183 #ifdef EIGEN_PARSED_BY_DOXYGEN 190 template<
typename Rhs>
192 #endif // EIGEN_PARSED_BY_DOXYGEN 216 template<
typename Rhs,
typename Dest>
219 Dest&
X(X_base.derived());
222 THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
226 X.resize(B.rows(),B.cols());
229 for(
Index j = 0; j < B.cols(); ++j)
237 for (
Index j = 0; j < B.cols(); ++j)
263 for (
typename SCMatrix::InnerIterator it(
m_Lstore, j); it; ++it)
267 det *=
abs(it.value());
292 for (
typename SCMatrix::InnerIterator it(
m_Lstore, j); it; ++it)
294 if(it.row() < j)
continue;
297 det +=
log(
abs(it.value()));
318 for (
typename SCMatrix::InnerIterator it(
m_Lstore, j); it; ++it)
324 else if(it.value()==0)
346 for (
typename SCMatrix::InnerIterator it(
m_Lstore, j); it; ++it)
410 template <
typename MatrixType,
typename OrderingType>
431 if(!mat.isCompressed())
435 for (
Index i = 0; i < mat.cols(); i++)
456 for (
Index i = 0; i < m; ++i) iwork(post(i)) = post(
m_etree(i));
461 for (
Index i = 0; i < m; i++)
462 post_perm.
indices()(i) = post(i);
495 template <
typename MatrixType,
typename OrderingType>
500 eigen_assert((matrix.rows() == matrix.cols()) &&
"Only for squared matrices");
513 if (matrix.isCompressed()) outerIndexPtr = matrix.outerIndexPtr();
518 outerIndexPtr = outerIndexPtr_t;
520 for (
Index i = 0; i < matrix.cols(); i++)
525 if(!matrix.isCompressed())
delete[] outerIndexPtr;
542 m_lastError =
"UNABLE TO ALLOCATE WORKING MEMORY\n\n" ;
594 for (jcol = 0; jcol <
n; )
598 for (k = jcol + 1; k < (
std::min)(jcol+panel_size, n); k++)
602 panel_size = k - jcol;
607 panel_size = n - jcol;
610 Base::panel_dfs(m, panel_size, jcol,
m_mat,
m_perm_r.
indices(), nseg1, dense, panel_lsub, segrep, repfnz, xprune, marker, parent, xplore,
m_glu);
616 for ( jj = jcol; jj< jcol + panel_size; jj++)
624 info =
Base::column_dfs(m, jj,
m_perm_r.
indices(),
m_perfv.
maxsuper, nseg, panel_lsubk, segrep, repfnz_k, xprune, marker, parent, xplore,
m_glu);
627 m_lastError =
"UNABLE TO EXPAND MEMORY IN COLUMN_DFS() ";
638 m_lastError =
"UNABLE TO EXPAND MEMORY IN COLUMN_BMOD() ";
648 m_lastError =
"UNABLE TO EXPAND MEMORY IN COPY_TO_UCOL() ";
658 m_lastError =
"THE MATRIX IS STRUCTURALLY SINGULAR ... ZERO COLUMN AT ";
659 std::ostringstream returnInfo;
675 for (i = 0; i < nseg; i++)
701 template<
typename MappedSupernodalType>
709 template<
typename Dest>
712 m_mapL.solveInPlace(X);
717 template<
typename MatrixLType,
typename MatrixUType>
722 : m_mapL(mapL),m_mapU(mapU)
729 Index nrhs = X.cols();
732 for (
Index k = m_mapL.nsuper(); k >= 0; k--)
734 Index fsupc = m_mapL.supToCol()[k];
735 Index lda = m_mapL.colIndexPtr()[fsupc+1] - m_mapL.colIndexPtr()[fsupc];
736 Index nsupc = m_mapL.supToCol()[k+1] - fsupc;
737 Index luptr = m_mapL.colIndexPtr()[fsupc];
741 for (
Index j = 0; j < nrhs; j++)
743 X(fsupc, j) /= m_mapL.valuePtr()[luptr];
750 U =
A.template triangularView<Upper>().
solve(U);
753 for (
Index j = 0; j < nrhs; ++j)
755 for (
Index jcol = fsupc; jcol < fsupc + nsupc; jcol++)
757 typename MatrixUType::InnerIterator it(m_mapU, jcol);
760 Index irow = it.index();
761 X(irow, j) -=
X(jcol, j) * it.value();
EIGEN_DEVICE_FUNC ColXpr col(Index i)
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
SparseLUMatrixUReturnType(const MatrixLType &mapL, const MatrixUType &mapU)
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.
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
MatrixLType::Scalar Scalar
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.
MatrixType::StorageIndex StorageIndex
const MatrixLType & m_mapL
int coletree(const MatrixType &mat, IndexVector &parent, IndexVector &firstRowElt, typename MatrixType::StorageIndex *perm=0)
const StorageIndex * outerIndexPtr() const
void solveInPlace(MatrixBase< Dest > &X) const
const PermutationType & rowsPermutation() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
InverseReturnType inverse() const
A matrix or vector expression mapping an existing array of data.
Matrix< Scalar, Dynamic, 1 > ScalarVector
A base class for sparse solvers.
const Solve< SparseLU< _MatrixType, _OrderingType >, Rhs > solve(const MatrixBase< Rhs > &b) const
void relax_snode(const Index n, IndexVector &et, const Index relax_columns, IndexVector &descendants, IndexVector &relax_end)
Identify the initial relaxed supernodes.
internal::perfvalues m_perfv
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.
PermutationMatrix< Dynamic, Dynamic, StorageIndex > PermutationType
void heap_relax_snode(const Index n, IndexVector &et, const Index relax_columns, IndexVector &descendants, IndexVector &relax_end)
Identify the initial relaxed supernodes.
const MappedSupernodalType & m_mapL
void fixupL(const Index n, const IndexVector &perm_r, GlobalLU_t &glu)
Fix up the data storage lsub for L-subscripts.
return(x<=y ? ADS(x) :ADS(y))
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
void countnz(const Index n, Index &nnzL, Index &nnzU, GlobalLU_t &glu)
Count Nonzero elements in the factors.
void factorize(const MatrixType &matrix)
const unsigned int RowMajorBit
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.
EIGEN_DEVICE_FUNC const LogReturnType log() const
Sparse supernodal LU factorization for general matrices.
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)
void solveInPlace(MatrixBase< Dest > &X) const
void simplicialfactorize(const MatrixType &matrix)
SparseLU(const MatrixType &matrix)
void setPivotThreshold(const RealScalar &thresh)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const AbsReturnType abs() const
MatrixType A(a, *n, *n, *lda)
NumTraits< Scalar >::Real RealScalar
SparseLUMatrixLReturnType< SCMatrix > matrixL() const
void _solve_impl(const SparseMatrixBase< Rhs > &b, SparseMatrixBase< Dest > &dest) const
Expression of a fixed-size or dynamic-size sub-vector.
Matrix< StorageIndex, Dynamic, 1 > IndexVector
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
const IndicesType & indices() const
RealScalar m_diagpivotthresh
void compute(const MatrixType &matrix)
void isSymmetric(bool sym)
MatrixType::Scalar Scalar
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Index pivotL(const Index jcol, const RealScalar &diagpivotthresh, IndexVector &perm_r, IndexVector &iperm_c, Index &pivrow, GlobalLU_t &glu)
Performs the numerical pivotin on the current column of L, and the CDIV operation.
void setInfos(Index m, Index n, ScalarVector &nzval, IndexVector &nzval_colptr, IndexVector &rowind, IndexVector &rowind_colptr, IndexVector &col_to_sup, IndexVector &sup_to_col)
Index LUnumTempV(Index &m, Index &w, Index &t, Index &b)
EIGEN_DEVICE_FUNC Derived & setConstant(Index size, const Scalar &val)
const StorageIndex * innerNonZeroPtr() const
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.
#define ei_declare_aligned_stack_constructed_variable(TYPE, NAME, SIZE, BUFFER)
MappedSparseMatrix< Scalar, ColMajor, StorageIndex > m_Ustore
internal::MappedSuperNodalMatrix< Scalar, StorageIndex > SCMatrix
SparseMatrix< Scalar, ColMajor, StorageIndex > NCMatrix
SparseLUMatrixUReturnType< SCMatrix, MappedSparseMatrix< Scalar, ColMajor, StorageIndex > > matrixU() const
_OrderingType OrderingType
internal::SparseLUImpl< Scalar, StorageIndex > Base
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.
std::string lastErrorMessage() const
Scalar logAbsDeterminant() const
bool _solve_impl(const MatrixBase< Rhs > &B, MatrixBase< Dest > &X_base) const
static ConstMapType Map(const Scalar *data)
void treePostorder(typename IndexVector::Scalar n, IndexVector &parent, IndexVector &post)
Post order a tree.
const PermutationType & colsPermutation() const
SparseSolverBase< SparseLU< _MatrixType, _OrderingType > > APIBase
SparseLUMatrixLReturnType(const MappedSupernodalType &mapL)
Pseudo expression representing a solving operation.
MatrixType B(b, *n, *nrhs, *ldb)
void analyzePattern(const MatrixType &matrix)
const MatrixUType & m_mapU
MatrixType::RealScalar RealScalar
void resize(Index newSize)
Index determinant() const
Base class for all dense matrices, vectors, and expressions.
ComputationInfo info() const
Reports whether previous computation was successful.
MappedSupernodalType::Scalar Scalar