27#ifndef G2O_LINEAR_SOLVER_EIGEN_H
28#define G2O_LINEAR_SOLVER_EIGEN_H
30#include <Eigen/Sparse>
31#include <Eigen/SparseCholesky>
33#include "linear_solver.h"
45 template <
typename MatrixType>
61 using Eigen::SimplicialLDLT<
SparseMatrix, Eigen::Upper>::analyzePattern_preordered;
69 m_P = permutation.inverse();
72 ap.selfadjointView<Eigen::Upper>() = a.selfadjointView<UpLo>().twistedBy(m_P);
73 analyzePattern_preordered(ap,
true);
106 fillSparseMatrix(A, !
_init);
112 if (
_cholesky.info() != Eigen::Success) {
118 Eigen::VectorX<g_type>::ConstMapType bb(b,
_sparseMatrix.cols());
150 Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic> blockP;
153 std::vector<Triplet> triplets;
154 for (
uint04 c = 0; c < A.blockCols().size(); ++c) {
155 const typename SparseBlockMatrix<MatrixType>::IntBlockMap& column = A.blockCols()[c];
156 for (
typename SparseBlockMatrix<MatrixType>::IntBlockMap::const_iterator it = column.begin(); it != column.end(); ++it) {
157 const int& r = it->first;
158 if (r >
static_cast<int>(c))
160 triplets.push_back(
Triplet(r, c, 0.));
166 SparseMatrix auxBlockMatrix(A.blockCols().size(), A.blockCols().size());
167 auxBlockMatrix.setFromTriplets(triplets.begin(), triplets.end());
168 typename CholeskyDecomposition::CholMatrixType C;
169 C = auxBlockMatrix.selfadjointView<Eigen::Upper>();
170 Eigen::internal::minimum_degree_ordering(C, blockP);
174 assert(rows == A.cols() &&
"Matrix A is not square");
178 scalarP.resize(rows);
180 for (
int i = 0; i < blockP.size(); ++i) {
181 const int& p = blockP.indices()(i);
182 int base = A.colBaseOfBlock(p);
183 int nCols = A.colsOfBlock(p);
184 for (
int j = 0; j < nCols; ++j)
185 scalarP.indices()(scalarIdx++) = base++;
187 assert(scalarIdx == rows &&
"did not completely fill the permutation matrix");
204 std::vector<Triplet> triplets;
205 triplets.reserve(A.nonZeros());
206 for (
uint04 c = 0; c < A.blockCols().size(); ++c) {
207 int colBaseOfBlock = A.colBaseOfBlock(c);
208 const typename SparseBlockMatrix<MatrixType>::IntBlockMap& column = A.blockCols()[c];
209 for (
typename SparseBlockMatrix<MatrixType>::IntBlockMap::const_iterator it = column.begin(); it != column.end(); ++it) {
210 int rowBaseOfBlock = A.rowBaseOfBlock(it->first);
211 const MatrixType& m = it->second;
212 for (
int cc = 0; cc < m.cols(); ++cc) {
213 int aux_c = colBaseOfBlock + cc;
214 for (
int rr = 0; rr < m.rows(); ++rr) {
215 int aux_r = rowBaseOfBlock + rr;
218 triplets.push_back(
Triplet(aux_r, aux_c, m(rr, cc)));
223 _sparseMatrix.setFromTriplets(triplets.begin(), triplets.end());
Sub-classing Eigen's SimplicialLDLT to perform ordering with a given ordering.
CholeskyDecomposition()
Default constructor.
void analyzePatternWithPermutation(SparseMatrix &a, const PermutationMatrix &permutation)
Analyzes the sparsity pattern with a user-provided permutation.
linear solver which uses the sparse Cholesky solver from Eigen
Eigen::PermutationMatrix< Eigen::Dynamic, Eigen::Dynamic, int > PermutationMatrix
Permutation matrix type.
void computeSymbolicDecomposition(const SparseBlockMatrix< MatrixType > &A)
compute the symbolic decompostion of the matrix only once.
bool _init
Whether the symbolic decomposition needs to be (re)computed.
LinearSolverEigen()
Default constructor.
CholeskyDecomposition _cholesky
The Cholesky decomposition.
SparseMatrix _sparseMatrix
The Eigen sparse matrix representation.
Eigen::Triplet< g_type > Triplet
Triplet type for sparse matrix construction.
virtual bool init()
Resets the solver for a new factorization.
Eigen::SparseMatrix< g_type, Eigen::ColMajor > SparseMatrix
Column-major Eigen sparse matrix type.
SparseOptimizer optimizer
The sparse optimizer instance.
bool blockOrdering() const
do the AMD ordering on the blocks or on the scalar matrix
bool solve(const SparseBlockMatrix< MatrixType > &A, g_type *x, g_type *b)
Solves the linear system Ax = b using sparse Cholesky decomposition.
bool _blockOrdering
Whether to use block-level AMD ordering.
Sparse matrix which uses blocks.
Sparse optimizer that manages active vertices and edges for graph-based optimization.
Convenience typedefs for commonly used Eigen vector, matrix, and transform types.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.