mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Add Sparse Subset of Matrix Inverse
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
34780d8bd1
commit
69714ff613
@@ -816,6 +816,31 @@ struct SparseLUMatrixLReturnType : internal::no_assignment_operator
|
||||
m_mapL.template solveTransposedInPlace<Conjugate>(X);
|
||||
}
|
||||
|
||||
SparseMatrix<Scalar, ColMajor, Index> toSparse() const {
|
||||
ArrayXi colCount = ArrayXi::Ones(cols());
|
||||
for (Index i = 0; i < cols(); i++) {
|
||||
typename MappedSupernodalType::InnerIterator iter(m_mapL, i);
|
||||
for (; iter; ++iter) {
|
||||
if (iter.row() > iter.col()) {
|
||||
colCount(iter.col())++;
|
||||
}
|
||||
}
|
||||
}
|
||||
SparseMatrix<Scalar, ColMajor, Index> sL(rows(), cols());
|
||||
sL.reserve(colCount);
|
||||
for (Index i = 0; i < cols(); i++) {
|
||||
sL.insert(i, i) = 1.0;
|
||||
typename MappedSupernodalType::InnerIterator iter(m_mapL, i);
|
||||
for (; iter; ++iter) {
|
||||
if (iter.row() > iter.col()) {
|
||||
sL.insert(iter.row(), iter.col()) = iter.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
sL.makeCompressed();
|
||||
return sL;
|
||||
}
|
||||
|
||||
const MappedSupernodalType& m_mapL;
|
||||
};
|
||||
|
||||
@@ -915,6 +940,32 @@ struct SparseLUMatrixUReturnType : internal::no_assignment_operator
|
||||
}// End For U-solve
|
||||
}
|
||||
|
||||
SparseMatrix<Scalar, RowMajor, Index> toSparse() {
|
||||
ArrayXi rowCount = ArrayXi::Zero(rows());
|
||||
for (Index i = 0; i < cols(); i++) {
|
||||
typename MatrixLType::InnerIterator iter(m_mapL, i);
|
||||
for (; iter; ++iter) {
|
||||
if (iter.row() <= iter.col()) {
|
||||
rowCount(iter.row())++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SparseMatrix<Scalar, RowMajor, Index> sU(rows(), cols());
|
||||
sU.reserve(rowCount);
|
||||
for (Index i = 0; i < cols(); i++) {
|
||||
typename MatrixLType::InnerIterator iter(m_mapL, i);
|
||||
for (; iter; ++iter) {
|
||||
if (iter.row() <= iter.col()) {
|
||||
sU.insert(iter.row(), iter.col()) = iter.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
sU.makeCompressed();
|
||||
const SparseMatrix<Scalar, RowMajor, Index> u = m_mapU; // convert to RowMajor
|
||||
sU += u;
|
||||
return sU;
|
||||
}
|
||||
|
||||
const MatrixLType& m_mapL;
|
||||
const MatrixUType& m_mapU;
|
||||
|
||||
Reference in New Issue
Block a user