g2o
Public Member Functions | Protected Attributes | List of all members
g2o::LinearSolverDense< MatrixType > Class Template Reference

linear solver using dense cholesky decomposition More...

#include <linear_solver_dense.h>

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

Public Member Functions

 LinearSolverDense ()
 
virtual ~LinearSolverDense ()
 
virtual bool init ()
 
bool solve (const SparseBlockMatrix< MatrixType > &A, double *x, double *b)
 
- Public Member Functions inherited from g2o::LinearSolver< MatrixType >
 LinearSolver ()
 
virtual ~LinearSolver ()
 
virtual bool solveBlocks (double **&blocks, const SparseBlockMatrix< MatrixType > &A)
 
virtual bool solvePattern (SparseBlockMatrix< MatrixXD > &spinv, const std::vector< std::pair< int, int > > &blockIndices, const SparseBlockMatrix< MatrixType > &A)
 
virtual bool writeDebug () const
 write a debug dump of the system matrix if it is not PSD in solve More...
 
virtual void setWriteDebug (bool)
 

Protected Attributes

bool _reset
 
MatrixXD _H
 
Eigen::LDLT< MatrixXD_cholesky
 

Detailed Description

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

linear solver using dense cholesky decomposition

Definition at line 46 of file linear_solver_dense.h.

Constructor & Destructor Documentation

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

Definition at line 49 of file linear_solver_dense.h.

49  :
50  LinearSolver<MatrixType>(),
51  _reset(true)
52  {
53  }
template<typename MatrixType>
virtual g2o::LinearSolverDense< MatrixType >::~LinearSolverDense ( )
inlinevirtual

Definition at line 55 of file linear_solver_dense.h.

56  {
57  }

Member Function Documentation

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

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

Implements g2o::LinearSolver< MatrixType >.

Definition at line 59 of file linear_solver_dense.h.

References g2o::LinearSolverDense< MatrixType >::_reset.

60  {
61  _reset = true;
62  return true;
63  }
template<typename MatrixType>
bool g2o::LinearSolverDense< MatrixType >::solve ( const SparseBlockMatrix< MatrixType > &  A,
double *  x,
double *  b 
)
inlinevirtual

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 65 of file linear_solver_dense.h.

References g2o::LinearSolverDense< MatrixType >::_cholesky, g2o::LinearSolverDense< MatrixType >::_H, g2o::LinearSolverDense< MatrixType >::_reset, g2o::SparseBlockMatrix< MatrixType >::blockCols(), g2o::SparseBlockMatrix< MatrixType >::colBaseOfBlock(), g2o::SparseBlockMatrix< MatrixType >::cols(), g2o::SparseBlockMatrix< MatrixType >::colsOfBlock(), g2o::SparseBlockMatrix< MatrixType >::rowBaseOfBlock(), g2o::SparseBlockMatrix< MatrixType >::rowsOfBlock(), and g2o::SparseBlockMatrix< MatrixType >::transpose().

66  {
67  int n = A.cols();
68  int m = A.cols();
69 
70  MatrixXD& H = _H;
71  if (H.cols() != n) {
72  H.resize(n, m);
73  _reset = true;
74  }
75  if (_reset) {
76  _reset = false;
77  H.setZero();
78  }
79 
80  // copy the sparse block matrix into a dense matrix
81  int c_idx = 0;
82  for (size_t i = 0; i < A.blockCols().size(); ++i) {
83  int c_size = A.colsOfBlock(i);
84  assert(c_idx == A.colBaseOfBlock(i) && "mismatch in block indices");
85 
86  const typename SparseBlockMatrix<MatrixType>::IntBlockMap& col = A.blockCols()[i];
87  if (col.size() > 0) {
88  typename SparseBlockMatrix<MatrixType>::IntBlockMap::const_iterator it;
89  for (it = col.begin(); it != col.end(); ++it) {
90  int r_idx = A.rowBaseOfBlock(it->first);
91  // only the upper triangular block is processed
92  if (it->first <= (int)i) {
93  int r_size = A.rowsOfBlock(it->first);
94  H.block(r_idx, c_idx, r_size, c_size) = *(it->second);
95  if (r_idx != c_idx) // write the lower triangular block
96  H.block(c_idx, r_idx, c_size, r_size) = it->second->transpose();
97  }
98  }
99  }
100 
101  c_idx += c_size;
102  }
103 
104  // solving via Cholesky decomposition
105  VectorXD::MapType xvec(x, m);
106  VectorXD::ConstMapType bvec(b, n);
107  _cholesky.compute(H);
108  if (_cholesky.isPositive()) {
109  xvec = _cholesky.solve(bvec);
110  return true;
111  }
112  return false;
113  }
Eigen::LDLT< MatrixXD > _cholesky
std::map< int, SparseMatrixBlock * > IntBlockMap
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixXD
Definition: eigen_types.h:63

Member Data Documentation

template<typename MatrixType>
Eigen::LDLT<MatrixXD> g2o::LinearSolverDense< MatrixType >::_cholesky
protected

Definition at line 118 of file linear_solver_dense.h.

Referenced by g2o::LinearSolverDense< MatrixType >::solve().

template<typename MatrixType>
MatrixXD g2o::LinearSolverDense< MatrixType >::_H
protected

Definition at line 117 of file linear_solver_dense.h.

Referenced by g2o::LinearSolverDense< MatrixType >::solve().

template<typename MatrixType>
bool g2o::LinearSolverDense< MatrixType >::_reset
protected

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