Add Sparse Subset of Matrix Inverse

This commit is contained in:
Julian Kent
2022-07-28 18:04:35 +00:00
committed by Rasmus Munk Larsen
parent 34780d8bd1
commit 69714ff613
4 changed files with 329 additions and 0 deletions

View File

@@ -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;