10 #ifndef EIGEN_SPARSEINVERSE_H 11 #define EIGEN_SPARSEINVERSE_H 14 #include "./InternalHeaderCheck.h" 16 #include "../../../../Eigen/Sparse" 17 #include "../../../../Eigen/SparseLU" 34 template <
typename Scalar>
41 Scalar value() {
return _sum; }
43 void operator+=(Scalar increment) {
44 const Scalar correctedIncrement = increment + _correction;
45 const Scalar previousSum = _sum;
46 _sum += correctedIncrement;
47 _correction = correctedIncrement - (_sum - previousSum);
50 template <
typename Scalar, Index W
idth = 16>
62 Scalar value() {
return _block.topRows(_blockUsed).sum() + _totalSum.value(); }
64 void operator+=(Scalar increment) {
65 _block(_blockUsed++, 0) = increment;
66 if (_blockUsed == Width) {
67 _totalSum += _block.sum();
80 template <
typename Derived,
typename OtherDerived>
82 typedef typename Derived::Scalar Scalar;
83 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
84 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived)
85 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived, OtherDerived)
86 static_assert(internal::is_same<Scalar, typename OtherDerived::Scalar>::value,
"mismatched types");
88 internal::evaluator<Derived> thisEval(A.
derived());
89 typename Derived::ReverseInnerIterator i(thisEval, 0);
91 internal::evaluator<OtherDerived> otherEval(other.
derived());
92 typename OtherDerived::ReverseInnerIterator j(otherEval, 0);
96 if (i.index() == j.index()) {
97 res += numext::conj(i.value()) * j.value();
100 }
else if (i.index() > j.index())
127 template <
typename Scalar>
173 invD = DU.
diagonal().cwiseInverse();
174 Upper = (invD.asDiagonal() * DU).
template triangularView<StrictlyUpper>();
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);
203 typename MatrixType::ReverseInnerIterator colIter(colInv, recurseLevel);
204 for (; recurseLevel < colIter.index(); --colIter) {
205 const Scalar element = -
accurateDot(col, rowInv.row(colIter.index()));
206 colIter.valueRef() = element;
207 rowInv.coeffRef(colIter.index(), recurseLevel) = element;
211 typename RowMatrixType::ReverseInnerIterator rowIter(rowInv, recurseLevel);
212 for (; recurseLevel < rowIter.index(); --rowIter) {
213 const Scalar element = -
accurateDot(row, colInv.col(rowIter.index()));
214 rowIter.valueRef() = element;
215 colInv.coeffRef(recurseLevel, rowIter.index()) = element;
219 const Scalar diag = inverseDiagonal(recurseLevel) -
accurateDot(row, colInv.col(recurseLevel));
220 rowIter.valueRef() = diag;
221 colIter.valueRef() = diag;
void compute(const MatrixType &matrix)
ComputationInfo info() const
const ConstDiagonalReturnType diagonal() const
Namespace containing all symbols from the Eigen library.
const PermutationType & colsPermutation() const
Kahan algorithm based accumulator.
Definition: SparseInverse.h:35
calculate sparse subset of inverse of sparse matrix
Definition: SparseInverse.h:128
Derived::Scalar accurateDot(const SparseMatrixBase< Derived > &A, const SparseMatrixBase< OtherDerived > &other)
computes an accurate dot product on two sparse vectors
Definition: SparseInverse.h:81
SparseInverse(const SparseLU< MatrixType > &slu)
This Constructor is for if you already have a factored SparseLU and would like to use it to calculate...
Definition: SparseInverse.h:142
SparseInverse & compute(const SparseMatrix< Scalar > &A)
Calculate the sparse inverse from a given sparse input.
Definition: SparseInverse.h:147
const PermutationType & rowsPermutation() const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
constexpr Derived & derived()
SparseLUMatrixLReturnType< SCMatrix > matrixL() const
SparseLUMatrixUReturnType< SCMatrix, Map< SparseMatrix< Scalar, ColMajor, StorageIndex > > > matrixU() const
const MatrixType & inverse() const
return the already-calculated sparse inverse, or a 0x0 matrix if it could not be computed ...
Definition: SparseInverse.h:157
static MatrixType computeInverse(const RowMatrixType &Upper, const Matrix< Scalar, Dynamic, 1 > &inverseDiagonal, const MatrixType &Lower)
Internal function to calculate the inverse from strictly upper, diagonal and strictly lower component...
Definition: SparseInverse.h:185
static MatrixType computeInverse(const SparseLU< MatrixType > &slu)
Internal function to calculate the sparse inverse in a functional way.
Definition: SparseInverse.h:163