10#ifndef EIGEN_SPARSEINVERSE_H
11#define EIGEN_SPARSEINVERSE_H
14#include "./InternalHeaderCheck.h"
16#include "../../../../Eigen/Sparse"
17#include "../../../../Eigen/SparseLU"
34template <
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);
50template <
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();
80template <
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())
127template <
typename Scalar>
157 const MatrixType&
inverse()
const {
return _result; }
165 return MatrixType(0, 0);
172 RowMatrixType DU = slu.
matrixU().toSparse();
173 invD = DU.
diagonal().cwiseInverse();
174 Upper = (invD.asDiagonal() * DU).template triangularView<StrictlyUpper>();
176 MatrixType
Lower = slu.
matrixL().toSparse().template triangularView<StrictlyLower>();
186 const MatrixType&
Lower) {
189 MatrixType colInv =
Lower.transpose().template triangularView<UnitUpper>();
190 colInv +=
Upper.transpose();
193 RowMatrixType rowInv =
Upper.transpose().template triangularView<UnitLower>();
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) {
206 colIter.valueRef() = element;
207 rowInv.
coeffRef(colIter.index(), recurseLevel) = element;
211 typename RowMatrixType::ReverseInnerIterator rowIter(rowInv, recurseLevel);
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;
Kahan algorithm based accumulator.
Definition SparseInverse.h:35
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
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
static MatrixType computeInverse(const SparseLU< MatrixType > &slu)
Internal function to calculate the sparse inverse in a functional way.
Definition SparseInverse.h:163
const MatrixType & inverse() const
return the already-calculated sparse inverse, or a 0x0 matrix if it could not be computed
Definition SparseInverse.h:157
SparseInverse & compute(const SparseMatrix< Scalar > &A)
Calculate the sparse inverse from a given sparse input.
Definition SparseInverse.h:147
SparseLUMatrixUReturnType< SCMatrix, Map< SparseMatrix< Scalar, ColMajor, StorageIndex > > > matrixU() const
SparseLUMatrixLReturnType< SCMatrix > matrixL() const
void compute(const MatrixType &matrix)
ComputationInfo info() const
const PermutationType & colsPermutation() const
const PermutationType & rowsPermutation() const
Scalar & coeffRef(Index row, Index col)
DiagonalReturnType diagonal()
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
Derived::Scalar accurateDot(const SparseMatrixBase< Derived > &A, const SparseMatrixBase< OtherDerived > &other)
computes an accurate dot product on two sparse vectors
Definition SparseInverse.h:81
constexpr Derived & derived()