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>
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())
432 IndexVector::Map(outerIndexPtr,
mat.cols()+1) = IndexVector::Map(m_mat.outerIndexPtr(),
mat.cols()+1);
435 for (
Index i = 0; i <
mat.cols(); i++)
437 m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i];
438 m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i+1] - outerIndexPtr[i];
447 if (!m_symmetricmode) {
454 Index m = m_mat.cols();
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);
465 if(m_perm_c.size()) {
466 m_perm_c = post_perm * m_perm_c;
471 m_analysisIsOk =
true;
495 template <
typename MatrixType,
typename OrderingType>
499 eigen_assert(m_analysisIsOk &&
"analyzePattern() should be called first");
502 m_isInitialized =
true;
513 if (
matrix.isCompressed()) outerIndexPtr =
matrix.outerIndexPtr();
517 for(
Index i = 0; i <=
matrix.cols(); i++) outerIndexPtr_t[i] = m_mat.outerIndexPtr()[i];
518 outerIndexPtr = outerIndexPtr_t;
522 m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i];
523 m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i+1] - outerIndexPtr[i];
525 if(!
matrix.isCompressed())
delete[] outerIndexPtr;
529 m_perm_c.resize(
matrix.cols());
533 Index m = m_mat.rows();
535 Index nnz = m_mat.nonZeros();
536 Index maxpanel = m_perfv.panel_size * m;
539 Index info = Base::memInit(m,
n, nnz, lwork, m_perfv.fillfactor, m_perfv.panel_size, m_glu);
542 m_lastError =
"UNABLE TO ALLOCATE WORKING MEMORY\n\n" ;
543 m_factorizationIsOk =
false;
570 if ( m_symmetricmode ==
true )
571 Base::heap_relax_snode(
n, m_etree, m_perfv.relax, marker, relax_end);
573 Base::relax_snode(
n, m_etree, m_perfv.relax, marker, relax_end);
577 m_perm_r.indices().setConstant(-1);
581 m_glu.supno(0) =
emptyIdxLU; m_glu.xsup.setConstant(0);
582 m_glu.xsup(0) = m_glu.xlsub(0) = m_glu.xusub(0) = m_glu.xlusup(0) =
Index(0);
594 for (jcol = 0; jcol <
n; )
597 Index panel_size = m_perfv.panel_size;
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);
613 Base::panel_bmod(m, panel_size, jcol, nseg1, dense, tempv, segrep, repfnz, 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() ";
629 m_factorizationIsOk =
false;
635 info = Base::column_bmod(jj, (nseg - nseg1), dense_k, tempv, segrep_k, repfnz_k, jcol, m_glu);
638 m_lastError =
"UNABLE TO EXPAND MEMORY IN COLUMN_BMOD() ";
640 m_factorizationIsOk =
false;
645 info = Base::copy_to_ucol(jj, nseg, segrep, repfnz_k ,m_perm_r.indices(), dense_k, m_glu);
648 m_lastError =
"UNABLE TO EXPAND MEMORY IN COPY_TO_UCOL() ";
650 m_factorizationIsOk =
false;
655 info = Base::pivotL(jj, m_diagpivotthresh, m_perm_r.indices(), iperm_c.
indices(), pivrow, m_glu);
658 m_lastError =
"THE MATRIX IS STRUCTURALLY SINGULAR ... ZERO COLUMN AT ";
659 std::ostringstream returnInfo;
661 m_lastError += returnInfo.str();
663 m_factorizationIsOk =
false;
669 if (pivrow != jj) m_detPermR = -m_detPermR;
672 Base::pruneL(jj, m_perm_r.indices(), pivrow, nseg, segrep, repfnz_k, xprune, m_glu);
675 for (i = 0; i < nseg; i++)
684 m_detPermR = m_perm_r.determinant();
685 m_detPermC = m_perm_c.determinant();
688 Base::countnz(
n, m_nnzL, m_nnzU, m_glu);
690 Base::fixupL(
n, m_perm_r.indices(), m_glu);
693 m_Lstore.setInfos(m,
n, m_glu.lusup, m_glu.xlusup, m_glu.lsub, m_glu.xlsub, m_glu.supno, m_glu.xsup);
698 m_factorizationIsOk =
true;
701 template<
typename MappedSupernodalType>
709 template<
typename Dest>
717 template<
typename MatrixLType,
typename MatrixUType>
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();