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>
84 typedef typename MatrixType::Scalar
Scalar;
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)
233 this->
matrixL().solveInPlace(X);
234 this->
matrixU().solveInPlace(X);
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");
514 const StorageIndex * outerIndexPtr;
515 if (matrix.isCompressed()) outerIndexPtr = matrix.outerIndexPtr();
518 StorageIndex* outerIndexPtr_t =
new StorageIndex[matrix.cols()+1];
520 outerIndexPtr = outerIndexPtr_t;
522 for (
Index i = 0; i < matrix.cols(); i++)
527 if(!matrix.isCompressed())
delete[] outerIndexPtr;
532 for(StorageIndex i = 0; i < matrix.cols(); ++i)
m_perm_c.
indices()(i) = i;
544 m_lastError =
"UNABLE TO ALLOCATE WORKING MEMORY\n\n" ;
596 for (jcol = 0; jcol < n; )
600 for (k = jcol + 1; k < (std::min)(jcol+panel_size, n); k++)
604 panel_size = k - jcol;
609 panel_size = n - jcol;
612 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);
618 for ( jj = jcol; jj< jcol + panel_size; jj++)
626 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);
629 m_lastError =
"UNABLE TO EXPAND MEMORY IN COLUMN_DFS() ";
640 m_lastError =
"UNABLE TO EXPAND MEMORY IN COLUMN_BMOD() ";
650 m_lastError =
"UNABLE TO EXPAND MEMORY IN COPY_TO_UCOL() ";
660 m_lastError =
"THE MATRIX IS STRUCTURALLY SINGULAR ... ZERO COLUMN AT ";
661 std::ostringstream returnInfo;
677 for (i = 0; i < nseg; i++)
703 template<
typename MappedSupernodalType>
706 typedef typename MappedSupernodalType::Scalar
Scalar;
711 template<
typename Dest>
714 m_mapL.solveInPlace(X);
719 template<
typename MatrixLType,
typename MatrixUType>
722 typedef typename MatrixLType::Scalar
Scalar;
724 : m_mapL(mapL),m_mapU(mapU)
731 Index nrhs = X.cols();
734 for (
Index k = m_mapL.nsuper(); k >= 0; k--)
736 Index fsupc = m_mapL.supToCol()[k];
737 Index lda = m_mapL.colIndexPtr()[fsupc+1] - m_mapL.colIndexPtr()[fsupc];
738 Index nsupc = m_mapL.supToCol()[k+1] - fsupc;
739 Index luptr = m_mapL.colIndexPtr()[fsupc];
743 for (
Index j = 0; j < nrhs; j++)
745 X(fsupc, j) /= m_mapL.valuePtr()[luptr];
752 U =
A.template triangularView<Upper>().
solve(U);
755 for (
Index j = 0; j < nrhs; ++j)
757 for (
Index jcol = fsupc; jcol < fsupc + nsupc; jcol++)
759 typename MatrixUType::InnerIterator it(m_mapU, jcol);
762 Index irow = it.index();
763 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
internal::traits< Derived >::Scalar Scalar
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
EIGEN_DEVICE_FUNC CoeffReturnType value() 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
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.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const AbsReturnType abs() const
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
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
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
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