template<typename Scalar>
class Eigen::SparseInverse< Scalar >
calculate sparse subset of inverse of sparse matrix
This class returns a sparse subset of the inverse of the input matrix. The nonzeros correspond to the nonzeros of the input, plus any additional elements required due to fill-in of the internal LU factorization. This is is minimized via a applying a fill-reducing permutation as part of the LU factorization.
If there are specific entries of the input matrix which you need inverse values for, which are zero for the input, you need to insert entries into the input sparse matrix for them to be calculated.
Due to the sensitive nature of matrix inversion, particularly on large matrices which are made possible via sparsity, high accuracy dot products based on Kahan summation are used to reduce numerical error. If you still encounter numerical errors you may with to equilibrate your matrix before calculating the inverse, as well as making sure it is actually full rank.
template<typename Scalar >
Internal function to calculate the inverse from strictly upper, diagonal and strictly lower components.
189 MatrixType colInv =
Lower.transpose().template triangularView<UnitUpper>();
190 colInv +=
Upper.transpose();
194 rowInv +=
Lower.transpose();
198 for (
Index recurseLevel =
Upper.cols() - 1; recurseLevel >= 0; recurseLevel--) {
199 const auto&
col =
Lower.col(recurseLevel);
200 const auto&
row =
Upper.row(recurseLevel);
204 for (; recurseLevel < colIter.index(); --colIter) {
206 colIter.valueRef() = element;
207 rowInv.coeffRef(colIter.index(), recurseLevel) = element;
212 for (; recurseLevel < rowIter.index(); --rowIter) {
214 rowIter.valueRef() = element;
215 colInv.coeffRef(recurseLevel, rowIter.index()) = element;
220 rowIter.valueRef() =
diag;
221 colIter.valueRef() =
diag;
SCALAR Scalar
Definition: bench_gemm.cpp:45
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
SparseMatrix< Scalar, RowMajor > RowMatrixType
Definition: SparseInverse.h:131
Base::ReverseInnerIterator ReverseInnerIterator
Definition: SparseMatrix.h:139
@ Lower
Definition: Constants.h:211
@ Upper
Definition: Constants.h:213
const char const char const char * diag
Definition: level2_impl.h:86
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
Derived::Scalar accurateDot(const SparseMatrixBase< Derived > &A, const SparseMatrixBase< OtherDerived > &other)
computes an accurate dot product on two sparse vectors
Definition: SparseInverse.h:81
References Eigen::accurateDot(), Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::coeffRef(), col(), diag, Eigen::Lower, row(), and Eigen::Upper.
template<typename Scalar >
Internal function to calculate the sparse inverse in a functional way.
- Returns
- A sparse inverse representation, or, if the decomposition didn't complete, a 0x0 matrix.
169 Matrix<Scalar, Dynamic, 1> invD;
173 invD = DU.
diagonal().cwiseInverse();
174 Upper = (invD.asDiagonal() * DU).
template triangularView<StrictlyUpper>();
176 MatrixType Lower = slu.matrixL().toSparse().template triangularView<StrictlyLower>();
SparseMatrix< Scalar, ColMajor > MatrixType
Definition: SparseInverse.h:130
const ConstDiagonalReturnType diagonal() const
Definition: SparseMatrix.h:757
@ Success
Definition: Constants.h:440
References Eigen::SparseLU< MatrixType_, OrderingType_ >::colsPermutation(), Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::diagonal(), Eigen::SparseLU< MatrixType_, OrderingType_ >::info(), Eigen::Lower, Eigen::SparseLU< MatrixType_, OrderingType_ >::matrixL(), Eigen::SparseLU< MatrixType_, OrderingType_ >::matrixU(), Eigen::SparseLU< MatrixType_, OrderingType_ >::rowsPermutation(), Eigen::Success, Eigen::PermutationBase< Derived >::transpose(), and Eigen::Upper.
Referenced by Eigen::SparseInverse< Scalar >::compute(), and Eigen::SparseInverse< Scalar >::SparseInverse().