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

Sparse matrix which uses blocks. More...

#include <sparse_block_matrix_ccs.h>

Classes

struct  RowBlock
 A block within a column. More...
 

Public Types

typedef MatrixType SparseMatrixBlock
 this is the type of the elementary block, it is an Eigen::Matrix. More...
 
typedef std::vector< RowBlockSparseColumn
 

Public Member Functions

int cols () const
 columns of the matrix More...
 
int rows () const
 rows of the matrix More...
 
 SparseBlockMatrixCCS (const std::vector< int > &rowIndices, const std::vector< int > &colIndices)
 
int rowsOfBlock (int r) const
 how many rows does the block at block-row r has? More...
 
int colsOfBlock (int c) const
 how many cols does the block at block-col c has? More...
 
int rowBaseOfBlock (int r) const
 where does the row at block-row r start? More...
 
int colBaseOfBlock (int c) const
 where does the col at block-col r start? More...
 
const std::vector< SparseColumn > & blockCols () const
 the block matrices per block-column More...
 
std::vector< SparseColumn > & blockCols ()
 
const std::vector< int > & rowBlockIndices () const
 indices of the row blocks More...
 
const std::vector< int > & colBlockIndices () const
 indices of the column blocks More...
 
void rightMultiply (double *&dest, const double *src) const
 
void sortColumns ()
 
int fillCCS (int *Cp, int *Ci, double *Cx, bool upperTriangle=false) const
 
int fillCCS (double *Cx, bool upperTriangle=false) const
 

Protected Attributes

const std::vector< int > & _rowBlockIndices
 vector of the indices of the blocks along the rows. More...
 
const std::vector< int > & _colBlockIndices
 vector of the indices of the blocks along the cols More...
 
std::vector< SparseColumn_blockCols
 the matrices stored in CCS order More...
 

Detailed Description

template<class MatrixType>
class g2o::SparseBlockMatrixCCS< MatrixType >

Sparse matrix which uses blocks.

This class is used as a const view on a SparseBlockMatrix which allows a faster iteration over the elements of the matrix.

Definition at line 49 of file sparse_block_matrix_ccs.h.

Member Typedef Documentation

template<class MatrixType>
typedef std::vector<RowBlock> g2o::SparseBlockMatrixCCS< MatrixType >::SparseColumn

Definition at line 71 of file sparse_block_matrix_ccs.h.

template<class MatrixType>
typedef MatrixType g2o::SparseBlockMatrixCCS< MatrixType >::SparseMatrixBlock

this is the type of the elementary block, it is an Eigen::Matrix.

Definition at line 53 of file sparse_block_matrix_ccs.h.

Constructor & Destructor Documentation

template<class MatrixType>
g2o::SparseBlockMatrixCCS< MatrixType >::SparseBlockMatrixCCS ( const std::vector< int > &  rowIndices,
const std::vector< int > &  colIndices 
)
inline

Definition at line 73 of file sparse_block_matrix_ccs.h.

73  :
74  _rowBlockIndices(rowIndices), _colBlockIndices(colIndices)
75  {}
const std::vector< int > & _colBlockIndices
vector of the indices of the blocks along the cols
const std::vector< int > & _rowBlockIndices
vector of the indices of the blocks along the rows.

Member Function Documentation

template<class MatrixType>
const std::vector<SparseColumn>& g2o::SparseBlockMatrixCCS< MatrixType >::blockCols ( ) const
inline

the block matrices per block-column

Definition at line 90 of file sparse_block_matrix_ccs.h.

Referenced by g2o::SparseBlockMatrix< MatrixType >::fillSparseBlockMatrixCCS(), g2o::SparseBlockMatrix< MatrixType >::fillSparseBlockMatrixCCSTransposed(), and g2o::BlockSolver< Traits >::solve().

90 { return _blockCols;}
std::vector< SparseColumn > _blockCols
the matrices stored in CCS order
template<class MatrixType>
std::vector<SparseColumn>& g2o::SparseBlockMatrixCCS< MatrixType >::blockCols ( )
inline

Definition at line 91 of file sparse_block_matrix_ccs.h.

91 { return _blockCols;}
std::vector< SparseColumn > _blockCols
the matrices stored in CCS order
template<class MatrixType>
int g2o::SparseBlockMatrixCCS< MatrixType >::colBaseOfBlock ( int  c) const
inline

where does the col at block-col r start?

Definition at line 87 of file sparse_block_matrix_ccs.h.

Referenced by g2o::SparseBlockMatrixCCS< PoseMatrixType >::rightMultiply().

87 { return c ? _colBlockIndices[c-1] : 0 ; }
const std::vector< int > & _colBlockIndices
vector of the indices of the blocks along the cols
template<class MatrixType>
const std::vector<int>& g2o::SparseBlockMatrixCCS< MatrixType >::colBlockIndices ( ) const
inline

indices of the column blocks

Definition at line 97 of file sparse_block_matrix_ccs.h.

97 { return _colBlockIndices;}
const std::vector< int > & _colBlockIndices
vector of the indices of the blocks along the cols
template<class MatrixType>
int g2o::SparseBlockMatrixCCS< MatrixType >::cols ( ) const
inline

columns of the matrix

Definition at line 56 of file sparse_block_matrix_ccs.h.

Referenced by g2o::SparseBlockMatrixCCS< PoseMatrixType >::rightMultiply().

56 {return _colBlockIndices.size() ? _colBlockIndices.back() : 0;}
const std::vector< int > & _colBlockIndices
vector of the indices of the blocks along the cols
template<class MatrixType>
int g2o::SparseBlockMatrixCCS< MatrixType >::colsOfBlock ( int  c) const
inline

how many cols does the block at block-col c has?

Definition at line 81 of file sparse_block_matrix_ccs.h.

Referenced by g2o::SparseBlockMatrixHashMap< MatrixType >::addBlock(), and g2o::SparseBlockMatrixCCS< PoseMatrixType >::fillCCS().

81 { return c ? _colBlockIndices[c] - _colBlockIndices[c-1] : _colBlockIndices[0]; }
const std::vector< int > & _colBlockIndices
vector of the indices of the blocks along the cols
template<class MatrixType>
int g2o::SparseBlockMatrixCCS< MatrixType >::fillCCS ( int *  Cp,
int *  Ci,
double *  Cx,
bool  upperTriangle = false 
) const
inline

fill the CCS arrays of a matrix, arrays have to be allocated beforehand

Definition at line 139 of file sparse_block_matrix_ccs.h.

140  {
141  assert(Cp && Ci && Cx && "Target destination is NULL");
142  int nz=0;
143  for (size_t i=0; i<_blockCols.size(); ++i){
144  int cstart=i ? _colBlockIndices[i-1] : 0;
145  int csize=colsOfBlock(i);
146  for (int c=0; c<csize; ++c) {
147  *Cp=nz;
148  for (typename SparseColumn::const_iterator it = _blockCols[i].begin(); it!=_blockCols[i].end(); ++it) {
149  const SparseMatrixBlock* b=it->block;
150  int rstart=it->row ? _rowBlockIndices[it->row-1] : 0;
151 
152  int elemsToCopy = b->rows();
153  if (upperTriangle && rstart == cstart)
154  elemsToCopy = c + 1;
155  for (int r=0; r<elemsToCopy; ++r){
156  *Cx++ = (*b)(r,c);
157  *Ci++ = rstart++;
158  ++nz;
159  }
160  }
161  ++Cp;
162  }
163  }
164  *Cp=nz;
165  return nz;
166  }
MatrixType SparseMatrixBlock
this is the type of the elementary block, it is an Eigen::Matrix.
int colsOfBlock(int c) const
how many cols does the block at block-col c has?
const std::vector< int > & _colBlockIndices
vector of the indices of the blocks along the cols
const std::vector< int > & _rowBlockIndices
vector of the indices of the blocks along the rows.
std::vector< SparseColumn > _blockCols
the matrices stored in CCS order
template<class MatrixType>
int g2o::SparseBlockMatrixCCS< MatrixType >::fillCCS ( double *  Cx,
bool  upperTriangle = false 
) const
inline

fill the CCS arrays of a matrix, arrays have to be allocated beforehand. This function only writes the values and assumes that column and row structures have already been written.

Definition at line 172 of file sparse_block_matrix_ccs.h.

173  {
174  assert(Cx && "Target destination is NULL");
175  double* CxStart = Cx;
176  int cstart = 0;
177  for (size_t i=0; i<_blockCols.size(); ++i){
178  int csize = _colBlockIndices[i] - cstart;
179  for (int c=0; c<csize; ++c) {
180  for (typename SparseColumn::const_iterator it = _blockCols[i].begin(); it!=_blockCols[i].end(); ++it) {
181  const SparseMatrixBlock* b = it->block;
182  int rstart = it->row ? _rowBlockIndices[it->row-1] : 0;
183 
184  int elemsToCopy = b->rows();
185  if (upperTriangle && rstart == cstart)
186  elemsToCopy = c + 1;
187  memcpy(Cx, b->data() + c*b->rows(), elemsToCopy * sizeof(double));
188  Cx += elemsToCopy;
189 
190  }
191  }
192  cstart = _colBlockIndices[i];
193  }
194  return Cx - CxStart;
195  }
MatrixType SparseMatrixBlock
this is the type of the elementary block, it is an Eigen::Matrix.
const std::vector< int > & _colBlockIndices
vector of the indices of the blocks along the cols
const std::vector< int > & _rowBlockIndices
vector of the indices of the blocks along the rows.
std::vector< SparseColumn > _blockCols
the matrices stored in CCS order
template<class MatrixType>
void g2o::SparseBlockMatrixCCS< MatrixType >::rightMultiply ( double *&  dest,
const double *  src 
) const
inline

Definition at line 99 of file sparse_block_matrix_ccs.h.

Referenced by g2o::BlockSolver< Traits >::solve().

100  {
101  int destSize=cols();
102 
103  if (! dest){
104  dest=new double [ destSize ];
105  memset(dest,0, destSize*sizeof(double));
106  }
107 
108  // map the memory by Eigen
109  Eigen::Map<Eigen::VectorXd> destVec(dest, destSize);
110  Eigen::Map<const Eigen::VectorXd> srcVec(src, rows());
111 
112 # ifdef G2O_OPENMP
113 # pragma omp parallel for default (shared) schedule(dynamic, 10)
114 # endif
115  for (int i=0; i < static_cast<int>(_blockCols.size()); ++i){
116  int destOffset = colBaseOfBlock(i);
117  for (typename SparseColumn::const_iterator it = _blockCols[i].begin(); it!=_blockCols[i].end(); ++it) {
118  const SparseMatrixBlock* a = it->block;
119  int srcOffset = rowBaseOfBlock(it->row);
120  // destVec += *a.transpose() * srcVec (according to the sub-vector parts)
121  internal::template atxpy<SparseMatrixBlock>(*a, srcVec, srcOffset, destVec, destOffset);
122  }
123  }
124  }
MatrixType SparseMatrixBlock
this is the type of the elementary block, it is an Eigen::Matrix.
int colBaseOfBlock(int c) const
where does the col at block-col r start?
int cols() const
columns of the matrix
std::vector< SparseColumn > _blockCols
the matrices stored in CCS order
int rows() const
rows of the matrix
int rowBaseOfBlock(int r) const
where does the row at block-row r start?
template<class MatrixType>
int g2o::SparseBlockMatrixCCS< MatrixType >::rowBaseOfBlock ( int  r) const
inline

where does the row at block-row r start?

Definition at line 84 of file sparse_block_matrix_ccs.h.

Referenced by g2o::SparseBlockMatrixCCS< PoseMatrixType >::rightMultiply(), and g2o::BlockSolver< Traits >::solve().

84 { return r ? _rowBlockIndices[r-1] : 0 ; }
const std::vector< int > & _rowBlockIndices
vector of the indices of the blocks along the rows.
template<class MatrixType>
const std::vector<int>& g2o::SparseBlockMatrixCCS< MatrixType >::rowBlockIndices ( ) const
inline

indices of the row blocks

Definition at line 94 of file sparse_block_matrix_ccs.h.

94 { return _rowBlockIndices;}
const std::vector< int > & _rowBlockIndices
vector of the indices of the blocks along the rows.
template<class MatrixType>
int g2o::SparseBlockMatrixCCS< MatrixType >::rows ( ) const
inline

rows of the matrix

Definition at line 58 of file sparse_block_matrix_ccs.h.

Referenced by g2o::SparseBlockMatrixCCS< PoseMatrixType >::rightMultiply().

58 {return _rowBlockIndices.size() ? _rowBlockIndices.back() : 0;}
const std::vector< int > & _rowBlockIndices
vector of the indices of the blocks along the rows.
template<class MatrixType>
int g2o::SparseBlockMatrixCCS< MatrixType >::rowsOfBlock ( int  r) const
inline

how many rows does the block at block-row r has?

Definition at line 78 of file sparse_block_matrix_ccs.h.

Referenced by g2o::SparseBlockMatrixHashMap< MatrixType >::addBlock().

78 { return r ? _rowBlockIndices[r] - _rowBlockIndices[r-1] : _rowBlockIndices[0] ; }
const std::vector< int > & _rowBlockIndices
vector of the indices of the blocks along the rows.
template<class MatrixType>
void g2o::SparseBlockMatrixCCS< MatrixType >::sortColumns ( )
inline

sort the blocks in each column

Definition at line 129 of file sparse_block_matrix_ccs.h.

130  {
131  for (int i=0; i < static_cast<int>(_blockCols.size()); ++i){
132  std::sort(_blockCols[i].begin(), _blockCols[i].end());
133  }
134  }
std::vector< SparseColumn > _blockCols
the matrices stored in CCS order

Member Data Documentation

template<class MatrixType>
std::vector<SparseColumn> g2o::SparseBlockMatrixCCS< MatrixType >::_blockCols
protected
template<class MatrixType>
const std::vector<int>& g2o::SparseBlockMatrixCCS< MatrixType >::_colBlockIndices
protected
template<class MatrixType>
const std::vector<int>& g2o::SparseBlockMatrixCCS< MatrixType >::_rowBlockIndices
protected

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