27#ifndef G2O_LINEAR_SOLVER_EIGEN_H
28#define G2O_LINEAR_SOLVER_EIGEN_H
30#include <Eigen/Sparse>
31#include <Eigen/SparseCholesky>
50template <
typename MatrixType>
55 typedef Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic>
59 Eigen::SimplicialLLT<SparseMatrix, Eigen::Upper>;
73 m_P = permutation.inverse();
76 ap.selfadjointView<Eigen::Upper>() =
77 a.selfadjointView<UpLo>().twistedBy(m_P);
78 analyzePattern_preordered(ap,
false);
82 using CholeskyDecompositionBase::analyzePattern_preordered;
97 if (!cholState)
return false;
107 _cholesky.matrixL().nestedExpression().nonZeros();
131 "Cholesky failure, writing debug.txt (Hessian loadable by Octave)");
152 assert(A.
rows() == A.
cols() &&
"Matrix A is not square");
154 Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic> blockP;
160 auxBlockMatrix.innerIndexPtr());
162 using Ordering = Eigen::AMDOrdering<SparseMatrix::StorageIndex>;
164 ordering(auxBlockMatrix, blockP);
181 this->
_ccsMatrix->fillCCS(_sparseMatrix.valuePtr(),
true);
186 int nz = this->
_ccsMatrix->fillCCS(_sparseMatrix.outerIndexPtr(),
204 if (!cholState)
return false;
210 _cholesky.matrixL().nestedExpression().outerIndexPtr()),
212 _cholesky.matrixL().nestedExpression().innerIndexPtr()),
213 const_cast<double*
>(
_cholesky.matrixL().nestedExpression().valuePtr()),
214 const_cast<int*
>(
_cholesky.permutationP().indices().data()));
220 _cholesky.matrixL().nestedExpression().nonZeros();
Solver with faster iterating structure for the linear matrix.
void initMatrixStructure(const SparseBlockMatrix< MatrixType > &A)
SparseBlockMatrixCCS< MatrixType > * _ccsMatrix
bool blockOrdering() const
do the AMD ordering on the blocks or on the scalar matrix
Sub-classing Eigen's SimplicialLLT to perform ordering with a given ordering.
void analyzePatternWithPermutation(SparseMatrix &a, const PermutationMatrix &permutation)
use a given permutation for analyzing the pattern of the sparse matrix
linear solver which uses the sparse Cholesky solver from Eigen
void computeSymbolicDecomposition(const SparseBlockMatrix< MatrixType > &A)
SparseMatrix _sparseMatrix
bool solveBlocks_impl(const SparseBlockMatrix< MatrixType > &A, std::function< void(MarginalCovarianceCholesky &)> compute)
Eigen::Triplet< double > Triplet
bool computeCholesky(const SparseBlockMatrix< MatrixType > &A, double &t)
void fillSparseMatrix(const SparseBlockMatrix< MatrixType > &A, bool onlyValues)
Eigen::PermutationMatrix< Eigen::Dynamic, Eigen::Dynamic > PermutationMatrix
CholeskyDecomposition _cholesky
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
Eigen::SimplicialLLT< SparseMatrix, Eigen::Upper > CholeskyDecompositionBase
bool solve(const SparseBlockMatrix< MatrixType > &A, double *x, double *b)
Eigen::SparseMatrix< double, Eigen::ColMajor > SparseMatrix
bool writeDebug() const
write a debug dump of the system matrix if it is not PSD in solve
static void blockToScalarPermutation(const SparseBlockMatrix< MatrixType > &A, const Eigen::MatrixBase< BlockDerived > &p, const Eigen::MatrixBase< ScalarDerived > &scalar)
computing the marginal covariance given a cholesky factor (lower triangle of the factor)
void setCholeskyFactor(int n, int *Lp, int *Li, double *Lx, int *permInv)
Sparse matrix which uses blocks.
size_t nonZeros() const
number of non-zero elements
bool writeOctave(const char *filename, bool upperTriangle=true) const
size_t nonZeroBlocks() const
number of allocated blocks
const std::vector< IntBlockMap > & blockCols() const
the block matrices per block-column
int rows() const
rows of the matrix
int cols() const
columns of the matrix
void fillBlockStructure(MatrixStructure &ms) const
exports the non zero blocks in the structure matrix ms
double get_monotonic_time()
statistics about the optimization
static G2OBatchStatistics * globalStats()
double timeNumericDecomposition
numeric decomposition (0 if not done)
double timeSymbolicDecomposition
symbolic decomposition (0 if not done)
size_t choleskyNNZ
number of non-zeros in the cholesky factor
utility functions for handling time related stuff