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());
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++)
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];
743 X(fsupc,
j) /= m_mapL.valuePtr()[luptr];
750 U =
A.template triangularView<Upper>().
solve(U);
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)
void _solve_impl(const SparseMatrixBase< Rhs > &b, SparseMatrixBase< Dest > &dest) const
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 PermutationType & rowsPermutation() const
const StorageIndex * innerNonZeroPtr() const
A matrix or vector expression mapping an existing array of data.
Matrix< Scalar, Dynamic, 1 > ScalarVector
A base class for sparse solvers.
bool _solve_impl(const MatrixBase< Rhs > &B, MatrixBase< Dest > &X_base) 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
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
EIGEN_DEVICE_FUNC const LogReturnType log() const
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
const Solve< SparseLU< _MatrixType, _OrderingType >, Rhs > solve(const MatrixBase< Rhs > &b) const
Namespace containing all symbols from the Eigen library.
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.
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
void countnz(const Index n, Index &nnzL, Index &nnzU, GlobalLU_t &glu)
Count Nonzero elements in the factors.
std::string lastErrorMessage() const
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.
ComputationInfo info() const
Reports whether previous computation was successful.
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 simplicialfactorize(const MatrixType &matrix)
SparseLU(const MatrixType &matrix)
void setPivotThreshold(const RealScalar &thresh)
SparseLUMatrixUReturnType< SCMatrix, MappedSparseMatrix< Scalar, ColMajor, StorageIndex > > matrixU() const
internal::traits< SparseMatrix< _Scalar, _Options, _StorageIndex > >::StorageIndex StorageIndex
Expression of a fixed-size or dynamic-size sub-vector.
Matrix< StorageIndex, Dynamic, 1 > IndexVector
void solveInPlace(MatrixBase< Dest > &X) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
RealScalar m_diagpivotthresh
void compute(const MatrixType &matrix)
const PermutationType & colsPermutation() const
internal::traits< SparseMatrix< _Scalar, _Options, _StorageIndex > >::Scalar Scalar
return(x<=y?ADS(x):ADS(y))
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 determinant() const
Index LUnumTempV(Index &m, Index &w, Index &t, Index &b)
EIGEN_DEVICE_FUNC Derived & setConstant(Index size, const Scalar &val)
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)
const StorageIndex * outerIndexPtr() const
MappedSparseMatrix< Scalar, ColMajor, StorageIndex > m_Ustore
internal::MappedSuperNodalMatrix< Scalar, StorageIndex > SCMatrix
InverseReturnType inverse() const
SparseMatrix< Scalar, ColMajor, StorageIndex > NCMatrix
_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.
const IndicesType & indices() const
static ConstMapType Map(const Scalar *data)
void treePostorder(typename IndexVector::Scalar n, IndexVector &parent, IndexVector &post)
Post order a tree.
Scalar logAbsDeterminant() const
SparseSolverBase< SparseLU< _MatrixType, _OrderingType > > APIBase
SparseLUMatrixLReturnType(const MappedSupernodalType &mapL)
Pseudo expression representing a solving operation.
void analyzePattern(const MatrixType &matrix)
const MatrixUType & m_mapU
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
NumTraits< Scalar >::Real RealScalar
MatrixType::RealScalar RealScalar
Convenience specialization of Stride to specify only an outer stride See class Map for some examples...
void solveInPlace(MatrixBase< Dest > &X) const
void resize(Index newSize)
Base class for all dense matrices, vectors, and expressions.
SparseLUMatrixLReturnType< SCMatrix > matrixL() const
MappedSupernodalType::Scalar Scalar