g2o
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
g2o::LinearSolver< MatrixType > Class Template Referenceabstract

basic solver for Ax = b More...

#include <linear_solver.h>

Inheritance diagram for g2o::LinearSolver< MatrixType >:
Inheritance graph
[legend]

Public Member Functions

 LinearSolver ()
 
virtual ~LinearSolver ()
 
virtual bool init ()=0
 
virtual bool solve (const SparseBlockMatrix< MatrixType > &A, double *x, double *b)=0
 
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)
 

Static Public Member Functions

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)
 

Protected Attributes

bool _writeDebug
 

Detailed Description

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

basic solver for Ax = b

basic solver for Ax = b which has to reimplemented for different linear algebra libraries. A is assumed to be symmetric (only upper triangular block is stored) and positive-semi-definite.

Definition at line 47 of file linear_solver.h.

Constructor & Destructor Documentation

◆ LinearSolver()

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

Definition at line 49 of file linear_solver.h.

49: _writeDebug(true){};

◆ ~LinearSolver()

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

Definition at line 50 of file linear_solver.h.

50{}

Member Function Documentation

◆ allocateBlocks()

template<typename MatrixType >
static void g2o::LinearSolver< MatrixType >::allocateBlocks ( const SparseBlockMatrix< MatrixType > &  A,
double **&  blocks 
)
inlinestatic

allocate block memory structure

Definition at line 97 of file linear_solver.h.

98 {
99 blocks = new double*[A.rows()];
100 double** block = blocks;
101 for (size_t i = 0; i < A.rowBlockIndices().size(); ++i) {
102 int dim = A.rowsOfBlock(i) * A.colsOfBlock(i);
103 *block = new double[dim];
104 block++;
105 }
106 }

References g2o::SparseBlockMatrix< MatrixType >::colsOfBlock(), g2o::SparseBlockMatrix< MatrixType >::rowBlockIndices(), g2o::SparseBlockMatrix< MatrixType >::rows(), and g2o::SparseBlockMatrix< MatrixType >::rowsOfBlock().

Referenced by g2o::LinearSolverCCS< MatrixType >::solveBlocks().

◆ blockToScalarPermutation()

template<typename MatrixType >
template<typename BlockDerived , typename ScalarDerived >
static void g2o::LinearSolver< MatrixType >::blockToScalarPermutation ( const SparseBlockMatrix< MatrixType > &  A,
const Eigen::MatrixBase< BlockDerived > &  p,
const Eigen::MatrixBase< ScalarDerived > &  scalar 
)
inlinestatic

Convert a block permutation matrix to a scalar permutation

Definition at line 122 of file linear_solver.h.

125 {
126 int n = A.cols();
127 Eigen::MatrixBase<ScalarDerived>& scalarPermutation =
128 const_cast<Eigen::MatrixBase<ScalarDerived>&>(scalar);
129 if (scalarPermutation.size() == 0) scalarPermutation.derived().resize(n);
130 if (scalarPermutation.size() < n) scalarPermutation.derived().resize(2 * n);
131 size_t scalarIdx = 0;
132 for (size_t i = 0; i < A.colBlockIndices().size(); ++i) {
133 int base = A.colBaseOfBlock(p(i));
134 int nCols = A.colsOfBlock(p(i));
135 for (int j = 0; j < nCols; ++j) {
136 scalarPermutation(scalarIdx++) = base++;
137 }
138 }
139 assert((int)scalarIdx == n);
140 }

References g2o::SparseBlockMatrix< MatrixType >::colBaseOfBlock(), g2o::SparseBlockMatrix< MatrixType >::colBlockIndices(), g2o::SparseBlockMatrix< MatrixType >::cols(), and g2o::SparseBlockMatrix< MatrixType >::colsOfBlock().

Referenced by g2o::LinearSolverCholmod< MatrixType >::computeSymbolicDecomposition(), g2o::LinearSolverCSparse< MatrixType >::computeSymbolicDecomposition(), and g2o::LinearSolverEigen< MatrixType >::computeSymbolicDecomposition().

◆ deallocateBlocks()

template<typename MatrixType >
static void g2o::LinearSolver< MatrixType >::deallocateBlocks ( const SparseBlockMatrix< MatrixType > &  A,
double **&  blocks 
)
inlinestatic

de-allocate the block structure

Definition at line 109 of file linear_solver.h.

110 {
111 for (size_t i = 0; i < A.rowBlockIndices().size(); ++i) {
112 delete[] blocks[i];
113 }
114 delete[] blocks;
115 blocks = nullptr;
116 }

References g2o::SparseBlockMatrix< MatrixType >::rowBlockIndices().

◆ init()

template<typename MatrixType >
virtual bool g2o::LinearSolver< MatrixType >::init ( )
pure virtual

◆ setWriteDebug()

template<typename MatrixType >
void g2o::LinearSolver< MatrixType >::setWriteDebug ( bool  b)
inline

Definition at line 94 of file linear_solver.h.

94{ _writeDebug = b; }

References g2o::LinearSolver< MatrixType >::_writeDebug.

◆ solve()

template<typename MatrixType >
virtual bool g2o::LinearSolver< MatrixType >::solve ( const SparseBlockMatrix< MatrixType > &  A,
double *  x,
double *  b 
)
pure 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!!

Implemented in g2o::LinearSolverCholmodOnline< MatrixType >, g2o::LinearSolverCholmod< MatrixType >, g2o::LinearSolverCSparse< MatrixType >, g2o::LinearSolverDense< MatrixType >, g2o::LinearSolverEigen< MatrixType >, and g2o::LinearSolverPCG< MatrixType >.

◆ solveBlocks()

template<typename MatrixType >
virtual bool g2o::LinearSolver< MatrixType >::solveBlocks ( double **&  blocks,
const SparseBlockMatrix< MatrixType > &  A 
)
inlinevirtual

Inverts the diagonal blocks of A

Returns
false if not defined.

Reimplemented in g2o::LinearSolverCCS< MatrixType >.

Definition at line 71 of file linear_solver.h.

72 {
73 (void)blocks;
74 (void)A;
75 return false;
76 }

◆ solvePattern()

template<typename MatrixType >
virtual bool g2o::LinearSolver< MatrixType >::solvePattern ( SparseBlockMatrix< MatrixX > &  spinv,
const std::vector< std::pair< int, int > > &  blockIndices,
const SparseBlockMatrix< MatrixType > &  A 
)
inlinevirtual

Inverts the a block pattern of A in spinv

Returns
false if not defined.

Reimplemented in g2o::LinearSolverCCS< MatrixType >.

Definition at line 82 of file linear_solver.h.

85 {
86 (void)spinv;
87 (void)blockIndices;
88 (void)A;
89 return false;
90 }

◆ writeDebug()

template<typename MatrixType >
bool g2o::LinearSolver< MatrixType >::writeDebug ( ) const
inline

Member Data Documentation

◆ _writeDebug

template<typename MatrixType >
bool g2o::LinearSolver< MatrixType >::_writeDebug
protected

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