g2o
Loading...
Searching...
No Matches
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.
 
typedef std::vector< RowBlockSparseColumn
 

Public Member Functions

int cols () const
 columns of the matrix
 
int rows () const
 rows of the matrix
 
 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?
 
int colsOfBlock (int c) const
 how many cols does the block at block-col c has?
 
int rowBaseOfBlock (int r) const
 where does the row at block-row r start?
 
int colBaseOfBlock (int c) const
 where does the col at block-col r start?
 
const std::vector< SparseColumn > & blockCols () const
 the block matrices per block-column
 
std::vector< SparseColumn > & blockCols ()
 
const std::vector< int > & rowBlockIndices () const
 indices of the row blocks
 
const std::vector< int > & colBlockIndices () const
 indices of the column blocks
 
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
 
const std::vector< int > & _colBlockIndices
 vector of the indices of the blocks along the cols
 
std::vector< SparseColumn_blockCols
 the matrices stored in CCS order
 

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 48 of file sparse_block_matrix_ccs.h.

Member Typedef Documentation

◆ SparseColumn

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

Definition at line 72 of file sparse_block_matrix_ccs.h.

◆ SparseMatrixBlock

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 51 of file sparse_block_matrix_ccs.h.

Constructor & Destructor Documentation

◆ SparseBlockMatrixCCS()

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

Definition at line 74 of file sparse_block_matrix_ccs.h.

76 : _rowBlockIndices(rowIndices), _colBlockIndices(colIndices) {}
const std::vector< int > & _colBlockIndices
vector of the indices of the blocks along the cols
const std::vector< int > & _rowBlockIndices

Member Function Documentation

◆ blockCols() [1/2]

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

Definition at line 98 of file sparse_block_matrix_ccs.h.

98{ return _blockCols; }
std::vector< SparseColumn > _blockCols
the matrices stored in CCS order

References g2o::SparseBlockMatrixCCS< MatrixType >::_blockCols.

◆ blockCols() [2/2]

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

◆ colBaseOfBlock()

template<class MatrixType >
int g2o::SparseBlockMatrixCCS< MatrixType >::colBaseOfBlock ( int  c) const
inline

where does the col at block-col r start?

Definition at line 94 of file sparse_block_matrix_ccs.h.

94{ return c ? _colBlockIndices[c - 1] : 0; }

References g2o::SparseBlockMatrixCCS< MatrixType >::_colBlockIndices.

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

◆ colBlockIndices()

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

indices of the column blocks

Definition at line 104 of file sparse_block_matrix_ccs.h.

104{ return _colBlockIndices; }

References g2o::SparseBlockMatrixCCS< MatrixType >::_colBlockIndices.

◆ cols()

template<class MatrixType >
int g2o::SparseBlockMatrixCCS< MatrixType >::cols ( ) const
inline

columns of the matrix

Definition at line 54 of file sparse_block_matrix_ccs.h.

54 {
55 return _colBlockIndices.size() ? _colBlockIndices.back() : 0;
56 }

References g2o::SparseBlockMatrixCCS< MatrixType >::_colBlockIndices.

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

◆ colsOfBlock()

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 85 of file sparse_block_matrix_ccs.h.

85 {
86 return c ? _colBlockIndices[c] - _colBlockIndices[c - 1]
88 }

References g2o::SparseBlockMatrixCCS< MatrixType >::_colBlockIndices.

Referenced by g2o::SparseBlockMatrixCCS< MatrixType >::fillCCS().

◆ fillCCS() [1/2]

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 180 of file sparse_block_matrix_ccs.h.

180 {
181 assert(Cx && "Target destination is NULL");
182 double* CxStart = Cx;
183 int cstart = 0;
184 for (size_t i = 0; i < _blockCols.size(); ++i) {
185 int csize = _colBlockIndices[i] - cstart;
186 for (int c = 0; c < csize; ++c) {
187 for (typename SparseColumn::const_iterator it = _blockCols[i].begin();
188 it != _blockCols[i].end(); ++it) {
189 const SparseMatrixBlock* b = it->block;
190 int rstart = it->row ? _rowBlockIndices[it->row - 1] : 0;
191
192 int elemsToCopy = b->rows();
193 if (upperTriangle && rstart == cstart) elemsToCopy = c + 1;
194 memcpy(Cx, b->data() + c * b->rows(), elemsToCopy * sizeof(double));
195 Cx += elemsToCopy;
196 }
197 }
198 cstart = _colBlockIndices[i];
199 }
200 return Cx - CxStart;
201 }
MatrixType SparseMatrixBlock
this is the type of the elementary block, it is an Eigen::Matrix.

References g2o::SparseBlockMatrixCCS< MatrixType >::_blockCols, g2o::SparseBlockMatrixCCS< MatrixType >::_colBlockIndices, and g2o::SparseBlockMatrixCCS< MatrixType >::_rowBlockIndices.

◆ fillCCS() [2/2]

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 147 of file sparse_block_matrix_ccs.h.

147 {
148 assert(Cp && Ci && Cx && "Target destination is NULL");
149 int nz = 0;
150 for (size_t i = 0; i < _blockCols.size(); ++i) {
151 int cstart = i ? _colBlockIndices[i - 1] : 0;
152 int csize = colsOfBlock(i);
153 for (int c = 0; c < csize; ++c) {
154 *Cp = nz;
155 for (typename SparseColumn::const_iterator it = _blockCols[i].begin();
156 it != _blockCols[i].end(); ++it) {
157 const SparseMatrixBlock* b = it->block;
158 int rstart = it->row ? _rowBlockIndices[it->row - 1] : 0;
159
160 int elemsToCopy = b->rows();
161 if (upperTriangle && rstart == cstart) elemsToCopy = c + 1;
162 for (int r = 0; r < elemsToCopy; ++r) {
163 *Cx++ = (*b)(r, c);
164 *Ci++ = rstart++;
165 ++nz;
166 }
167 }
168 ++Cp;
169 }
170 }
171 *Cp = nz;
172 return nz;
173 }
int colsOfBlock(int c) const
how many cols does the block at block-col c has?

References g2o::SparseBlockMatrixCCS< MatrixType >::_blockCols, g2o::SparseBlockMatrixCCS< MatrixType >::_colBlockIndices, g2o::SparseBlockMatrixCCS< MatrixType >::_rowBlockIndices, and g2o::SparseBlockMatrixCCS< MatrixType >::colsOfBlock().

◆ rightMultiply()

template<class MatrixType >
void g2o::SparseBlockMatrixCCS< MatrixType >::rightMultiply ( double *&  dest,
const double *  src 
) const
inline

Definition at line 106 of file sparse_block_matrix_ccs.h.

106 {
107 int destSize = cols();
108
109 if (!dest) {
110 dest = new double[destSize];
111 memset(dest, 0, destSize * sizeof(double));
112 }
113
114 // map the memory by Eigen
115 Eigen::Map<VectorX> destVec(dest, destSize);
116 Eigen::Map<const VectorX> srcVec(src, rows());
117
118#ifdef G2O_OPENMP
119#pragma omp parallel for default(shared) schedule(dynamic, 10)
120#endif
121 for (int i = 0; i < static_cast<int>(_blockCols.size()); ++i) {
122 int destOffset = colBaseOfBlock(i);
123 for (typename SparseColumn::const_iterator it = _blockCols[i].begin();
124 it != _blockCols[i].end(); ++it) {
125 const SparseMatrixBlock* a = it->block;
126 int srcOffset = rowBaseOfBlock(it->row);
127 // destVec += *a.transpose() * srcVec (according to the sub-vector
128 // parts)
129 internal::template atxpy<SparseMatrixBlock>(*a, srcVec, srcOffset,
130 destVec, destOffset);
131 }
132 }
133 }
int cols() const
columns of the matrix
int colBaseOfBlock(int c) const
where does the col at block-col r start?
int rowBaseOfBlock(int r) const
where does the row at block-row r start?
int rows() const
rows of the matrix

References g2o::SparseBlockMatrixCCS< MatrixType >::_blockCols, g2o::SparseBlockMatrixCCS< MatrixType >::colBaseOfBlock(), g2o::SparseBlockMatrixCCS< MatrixType >::cols(), g2o::SparseBlockMatrixCCS< MatrixType >::rowBaseOfBlock(), and g2o::SparseBlockMatrixCCS< MatrixType >::rows().

◆ rowBaseOfBlock()

template<class MatrixType >
int g2o::SparseBlockMatrixCCS< MatrixType >::rowBaseOfBlock ( int  r) const
inline

where does the row at block-row r start?

Definition at line 91 of file sparse_block_matrix_ccs.h.

91{ return r ? _rowBlockIndices[r - 1] : 0; }

References g2o::SparseBlockMatrixCCS< MatrixType >::_rowBlockIndices.

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

◆ rowBlockIndices()

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

indices of the row blocks

Definition at line 101 of file sparse_block_matrix_ccs.h.

101{ return _rowBlockIndices; }

References g2o::SparseBlockMatrixCCS< MatrixType >::_rowBlockIndices.

◆ 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.

58 {
59 return _rowBlockIndices.size() ? _rowBlockIndices.back() : 0;
60 }

References g2o::SparseBlockMatrixCCS< MatrixType >::_rowBlockIndices.

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

◆ rowsOfBlock()

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 79 of file sparse_block_matrix_ccs.h.

79 {
80 return r ? _rowBlockIndices[r] - _rowBlockIndices[r - 1]
82 }

References g2o::SparseBlockMatrixCCS< MatrixType >::_rowBlockIndices.

◆ sortColumns()

template<class MatrixType >
void g2o::SparseBlockMatrixCCS< MatrixType >::sortColumns ( )
inline

sort the blocks in each column

Definition at line 138 of file sparse_block_matrix_ccs.h.

138 {
139 for (int i = 0; i < static_cast<int>(_blockCols.size()); ++i) {
140 std::sort(_blockCols[i].begin(), _blockCols[i].end());
141 }
142 }

References g2o::SparseBlockMatrixCCS< MatrixType >::_blockCols.

Member Data Documentation

◆ _blockCols

template<class MatrixType >
std::vector<SparseColumn> g2o::SparseBlockMatrixCCS< MatrixType >::_blockCols
protected

◆ _colBlockIndices

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

◆ _rowBlockIndices

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

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