g2o
Loading...
Searching...
No Matches
g2o::LinearSolverPCG< MatrixType > Class Template Reference

linear solver using PCG, pre-conditioner is block Jacobi More...

#include <linear_solver_pcg.h>

Inheritance diagram for g2o::LinearSolverPCG< MatrixType >:
Collaboration diagram for g2o::LinearSolverPCG< MatrixType >:

Public Member Functions

 LinearSolverPCG ()
virtual ~LinearSolverPCG ()
virtual bool init ()
bool solve (const SparseBlockMatrix< MatrixType > &A, double *x, double *b)
double tolerance () const
 return the tolerance for terminating PCG before convergence
void setTolerance (double tolerance)
int maxIterations () const
void setMaxIterations (int maxIter)
bool absoluteTolerance () const
void setAbsoluteTolerance (bool absoluteTolerance)
Public Member Functions inherited from g2o::LinearSolver< MatrixType >
 LinearSolver ()
virtual ~LinearSolver ()
virtual bool solveBlocks (double **&blocks, const SparseBlockMatrix< MatrixType > &A)
virtual bool solvePattern (SparseBlockMatrix< MatrixX > &spinv, const std::vector< std::pair< int, int > > &blockIndices, const SparseBlockMatrix< MatrixType > &A)
bool writeDebug () const
 write a debug dump of the system matrix if it is not PSD in solve
void setWriteDebug (bool b)

Protected Types

using MatrixVector = std::vector<MatrixType>
using MatrixPtrVector = std::vector<const MatrixType*>

Protected Member Functions

void multDiag (const std::vector< int > &colBlockIndices, MatrixVector &A, const VectorX &src, VectorX &dest)
void multDiag (const std::vector< int > &colBlockIndices, MatrixPtrVector &A, const VectorX &src, VectorX &dest)
void mult (const std::vector< int > &colBlockIndices, const VectorX &src, VectorX &dest)

Protected Attributes

double _tolerance
double _residual
bool _absoluteTolerance
int _maxIter
MatrixPtrVector _diag
MatrixVector _J
std::vector< std::pair< int, int > > _indices
MatrixPtrVector _sparseMat
Protected Attributes inherited from g2o::LinearSolver< MatrixType >
bool _writeDebug

Additional Inherited Members

Static Public Member Functions inherited from g2o::LinearSolver< MatrixType >
static void allocateBlocks (const SparseBlockMatrix< MatrixType > &A, double **&blocks)
 allocate block memory structure
static void deallocateBlocks (const SparseBlockMatrix< MatrixType > &A, double **&blocks)
 de-allocate the block structure
template<typename BlockDerived, typename ScalarDerived>
static void blockToScalarPermutation (const SparseBlockMatrix< MatrixType > &A, const Eigen::MatrixBase< BlockDerived > &p, const Eigen::MatrixBase< ScalarDerived > &scalar)

Detailed Description

template<typename MatrixType>
class g2o::LinearSolverPCG< MatrixType >

linear solver using PCG, pre-conditioner is block Jacobi

Definition at line 43 of file linear_solver_pcg.h.

Member Typedef Documentation

◆ MatrixPtrVector

template<typename MatrixType>
using g2o::LinearSolverPCG< MatrixType >::MatrixPtrVector = std::vector<const MatrixType*>
protected

Definition at line 77 of file linear_solver_pcg.h.

◆ MatrixVector

template<typename MatrixType>
using g2o::LinearSolverPCG< MatrixType >::MatrixVector = std::vector<MatrixType>
protected

Definition at line 76 of file linear_solver_pcg.h.

Constructor & Destructor Documentation

◆ LinearSolverPCG()

template<typename MatrixType>
g2o::LinearSolverPCG< MatrixType >::LinearSolverPCG ( )
inline

◆ ~LinearSolverPCG()

template<typename MatrixType>
virtual g2o::LinearSolverPCG< MatrixType >::~LinearSolverPCG ( )
inlinevirtual

Definition at line 52 of file linear_solver_pcg.h.

Member Function Documentation

◆ absoluteTolerance()

template<typename MatrixType>
bool g2o::LinearSolverPCG< MatrixType >::absoluteTolerance ( ) const
inline

Definition at line 70 of file linear_solver_pcg.h.

References _absoluteTolerance.

Referenced by setAbsoluteTolerance().

◆ init()

template<typename MatrixType>
virtual bool g2o::LinearSolverPCG< MatrixType >::init ( )
inlinevirtual

init for operating on matrices with a different non-zero pattern like before

Implements g2o::LinearSolver< MatrixType >.

Definition at line 54 of file linear_solver_pcg.h.

References _indices, _residual, and _sparseMat.

◆ maxIterations()

template<typename MatrixType>
int g2o::LinearSolverPCG< MatrixType >::maxIterations ( ) const
inline

Definition at line 67 of file linear_solver_pcg.h.

References _maxIter.

◆ mult()

template<typename MatrixType>
void LinearSolverPCG::mult ( const std::vector< int > & colBlockIndices,
const VectorX & src,
VectorX & dest )
protected

Definition at line 186 of file linear_solver_pcg.h.

227template <typename MatrixType>
228class LinearSolverPCG : public LinearSolver<MatrixType> {
229 public:
231 _tolerance = cst(1e-6);
232 _absoluteTolerance = true;
233 _residual = -1.0;
234 _maxIter = -1;
235 }
236
237 virtual ~LinearSolverPCG() {}
238
239 virtual bool init() {
240 _residual = -1.0;
241 _indices.clear();
242 _sparseMat.clear();
243 return true;
244 }
245
246 bool solve(const SparseBlockMatrix<MatrixType>& A, double* x, double* b);
247
249 double tolerance() const { return _tolerance; }
250 void setTolerance(double tolerance) { _tolerance = tolerance; }
251
252 int maxIterations() const { return _maxIter; }
254
255 bool absoluteTolerance() const { return _absoluteTolerance; }
258 }
259
260 protected:
263
264 double _tolerance;
265 double _residual;
267 int _maxIter;
268
271
274
276 const VectorX& src, VectorX& dest);
278 const VectorX& src, VectorX& dest);
279 void mult(const std::vector<int>& colBlockIndices, const VectorX& src,
280 VectorX& dest);
281};
282
283#include "linear_solver_pcg.hpp"
284
285} // namespace g2o
286
287#endif
double tolerance() const
return the tolerance for terminating PCG before convergence
void mult(const std::vector< int > &colBlockIndices, const VectorX &src, VectorX &dest)
bool absoluteTolerance() const
bool solve(const SparseBlockMatrix< MatrixType > &A, double *x, double *b)
void setAbsoluteTolerance(bool absoluteTolerance)
void setMaxIterations(int maxIter)
void setTolerance(double tolerance)
void multDiag(const std::vector< int > &colBlockIndices, MatrixVector &A, const VectorX &src, VectorX &dest)

◆ multDiag() [1/2]

template<typename MatrixType>
void LinearSolverPCG::multDiag ( const std::vector< int > & colBlockIndices,
MatrixPtrVector & A,
const VectorX & src,
VectorX & dest )
protected

Definition at line 175 of file linear_solver_pcg.h.

211 {
212
216template <typename MatrixType>
217class LinearSolverPCG : public LinearSolver<MatrixType> {
218 public:
220 _tolerance = cst(1e-6);
221 _absoluteTolerance = true;
222 _residual = -1.0;
223 _maxIter = -1;
224 }
225
226 virtual ~LinearSolverPCG() {}
227
228 virtual bool init() {
229 _residual = -1.0;
230 _indices.clear();
231 _sparseMat.clear();
232 return true;
233 }
234
235 bool solve(const SparseBlockMatrix<MatrixType>& A, double* x, double* b);
236
238 double tolerance() const { return _tolerance; }
239 void setTolerance(double tolerance) { _tolerance = tolerance; }
240
241 int maxIterations() const { return _maxIter; }
243
244 bool absoluteTolerance() const { return _absoluteTolerance; }
247 }
248
249 protected:
252
253 double _tolerance;
254 double _residual;
256 int _maxIter;
257
260
263
265 const VectorX& src, VectorX& dest);
267 const VectorX& src, VectorX& dest);
268 void mult(const std::vector<int>& colBlockIndices, const VectorX& src,
269 VectorX& dest);
270};
271
272#include "linear_solver_pcg.hpp"
273
274} // namespace g2o
275
276#endif

◆ multDiag() [2/2]

template<typename MatrixType>
void LinearSolverPCG::multDiag ( const std::vector< int > & colBlockIndices,
MatrixVector & A,
const VectorX & src,
VectorX & dest )
protected

Definition at line 164 of file linear_solver_pcg.h.

200 {
201
205template <typename MatrixType>
206class LinearSolverPCG : public LinearSolver<MatrixType> {
207 public:
209 _tolerance = cst(1e-6);
210 _absoluteTolerance = true;
211 _residual = -1.0;
212 _maxIter = -1;
213 }
214
215 virtual ~LinearSolverPCG() {}
216
217 virtual bool init() {
218 _residual = -1.0;
219 _indices.clear();
220 _sparseMat.clear();
221 return true;
222 }
223
224 bool solve(const SparseBlockMatrix<MatrixType>& A, double* x, double* b);
225
227 double tolerance() const { return _tolerance; }
228 void setTolerance(double tolerance) { _tolerance = tolerance; }
229
230 int maxIterations() const { return _maxIter; }
232
233 bool absoluteTolerance() const { return _absoluteTolerance; }
236 }
237
238 protected:
241
242 double _tolerance;
243 double _residual;
245 int _maxIter;
246
249
252
254 const VectorX& src, VectorX& dest);
256 const VectorX& src, VectorX& dest);
257 void mult(const std::vector<int>& colBlockIndices, const VectorX& src,
258 VectorX& dest);
259};
260
261#include "linear_solver_pcg.hpp"
262
263} // namespace g2o
264
265#endif

◆ setAbsoluteTolerance()

template<typename MatrixType>
void g2o::LinearSolverPCG< MatrixType >::setAbsoluteTolerance ( bool absoluteTolerance)
inline

Definition at line 71 of file linear_solver_pcg.h.

References _absoluteTolerance, and absoluteTolerance().

◆ setMaxIterations()

template<typename MatrixType>
void g2o::LinearSolverPCG< MatrixType >::setMaxIterations ( int maxIter)
inline

Definition at line 68 of file linear_solver_pcg.h.

68{ _maxIter = maxIter; }

References _maxIter.

◆ setTolerance()

template<typename MatrixType>
void g2o::LinearSolverPCG< MatrixType >::setTolerance ( double tolerance)
inline

Definition at line 65 of file linear_solver_pcg.h.

References _tolerance, and tolerance().

◆ solve()

template<typename MatrixType>
bool LinearSolverPCG::solve ( const SparseBlockMatrix< MatrixType > & A,
double * x,
double * b )
virtual

Assumes that A is the same matrix for several calls. Among other assumptions, the non-zero pattern does not change! If the matrix changes call init() before. solve system Ax = b, x and b have to allocated beforehand!!

Implements g2o::LinearSolver< MatrixType >.

Definition at line 88 of file linear_solver_pcg.h.

◆ tolerance()

template<typename MatrixType>
double g2o::LinearSolverPCG< MatrixType >::tolerance ( ) const
inline

return the tolerance for terminating PCG before convergence

Definition at line 64 of file linear_solver_pcg.h.

64{ return _tolerance; }

References _tolerance.

Referenced by setTolerance().

Member Data Documentation

◆ _absoluteTolerance

template<typename MatrixType>
bool g2o::LinearSolverPCG< MatrixType >::_absoluteTolerance
protected

Definition at line 81 of file linear_solver_pcg.h.

Referenced by absoluteTolerance(), and setAbsoluteTolerance().

◆ _diag

template<typename MatrixType>
MatrixPtrVector g2o::LinearSolverPCG< MatrixType >::_diag
protected

Definition at line 84 of file linear_solver_pcg.h.

◆ _indices

template<typename MatrixType>
std::vector<std::pair<int, int> > g2o::LinearSolverPCG< MatrixType >::_indices
protected

Definition at line 87 of file linear_solver_pcg.h.

Referenced by init().

◆ _J

template<typename MatrixType>
MatrixVector g2o::LinearSolverPCG< MatrixType >::_J
protected

Definition at line 85 of file linear_solver_pcg.h.

◆ _maxIter

template<typename MatrixType>
int g2o::LinearSolverPCG< MatrixType >::_maxIter
protected

Definition at line 82 of file linear_solver_pcg.h.

Referenced by maxIterations(), and setMaxIterations().

◆ _residual

template<typename MatrixType>
double g2o::LinearSolverPCG< MatrixType >::_residual
protected

Definition at line 80 of file linear_solver_pcg.h.

Referenced by init().

◆ _sparseMat

template<typename MatrixType>
MatrixPtrVector g2o::LinearSolverPCG< MatrixType >::_sparseMat
protected

Definition at line 88 of file linear_solver_pcg.h.

Referenced by init().

◆ _tolerance

template<typename MatrixType>
double g2o::LinearSolverPCG< MatrixType >::_tolerance
protected

Definition at line 79 of file linear_solver_pcg.h.

Referenced by setTolerance(), and tolerance().


The documentation for this class was generated from the following files: