27#ifndef G2O_SPARSE_BLOCK_MATRIX_CCS_H
28#define G2O_SPARSE_BLOCK_MATRIX_CCS_H
30#include "Base/Headers/Buffer.hpp"
31#include "Base/Headers/Dictionary.h"
46 template <
class MatrixType>
47 class SparseBlockMatrixCCS
74 RowBlock(
int r, MatrixType b)
81 bool operator<(
const RowBlock& other)
const {
return row < other.row;}
83 typedef Buffer<RowBlock> SparseColumn;
85 SparseBlockMatrixCCS()
88 SparseBlockMatrixCCS(
const Buffer<int>& rowIndices,
const Buffer<int>& colIndices) :
93 int rowsOfBlock(
int r)
const {
return r ? (*_rowBlockIndices)[r] - (*_rowBlockIndices)[r-1] : (*_rowBlockIndices)[0] ; }
96 int colsOfBlock(
int c)
const {
return c ? (*_colBlockIndices)[c] - (*_colBlockIndices)[c-1] : (*_colBlockIndices)[0]; }
99 int rowBaseOfBlock(
int r)
const {
return r ? (*_rowBlockIndices)[r-1] : 0 ; }
114 void rightMultiply(g_type*& dest,
const g_type* src)
const
119 dest=
new g_type [ destSize ];
120 memset(dest,0, destSize*
sizeof(g_type));
124 Eigen::Map<Eigen::VectorX<g_type>> destVec(dest, destSize);
125 Eigen::Map<const Eigen::VectorX<g_type>> srcVec(src,
rows());
135 internal::atxpy(a, srcVec, srcOffset, destVec, destOffset);
154 int fillCCS(
int* Cp,
int* Ci, g_type* Cx,
bool upperTriangle =
false)
const
156 assert(Cp && Ci && Cx &&
"Target destination is NULL");
160 int cstart=i ? (*_colBlockIndices)[i-1] : 0;
162 for (
int c=0; c<csize; ++c) {
167 int rstart=it->row ? (*_rowBlockIndices)[it->row-1] : 0;
169 int elemsToCopy = b->rows();
170 if (upperTriangle && rstart == cstart)
172 for (
int r=0; r<elemsToCopy; ++r){
189 int fillCCS(g_type* Cx,
bool upperTriangle =
false)
const
191 assert(Cx &&
"Target destination is NULL");
192 g_type* CxStart = Cx;
196 int csize = (*_colBlockIndices)[i] - cstart;
197 for (
int c = 0; c < csize; ++c)
202 int rstart = it->row ? (*_rowBlockIndices)[it->row-1] : 0;
204 int elemsToCopy = b->rows();
205 if (upperTriangle && rstart == cstart)
207 memcpy(Cx, b->data() + c*b->rows(), elemsToCopy *
sizeof(g_type));
212 cstart = (*_colBlockIndices)[i];
230 template <
class MatrixType>
231 class SparseBlockMatrixHashMap
249 int rowsOfBlock(
int r)
const {
return r ? (*_rowBlockIndices)[r] - (*_rowBlockIndices)[r-1] : (*_rowBlockIndices)[0] ; }
252 int colsOfBlock(
int c)
const {
return c ? (*_colBlockIndices)[c] - (*_colBlockIndices)[c-1] : (*_colBlockIndices)[0]; }
276 auto iter = sparseColumn.find(r);
277 if (iter == sparseColumn.end())
281 MatrixType m(rb, cb);
285 return &sparseColumn[r];
287 return &iter.value();
The equivelent of std::vector but with a bit more control.
A hash-based key-value store, useful for quick associative lookups.
const Buffer< int > * _rowBlockIndices
vector of the indices of the blocks along the rows.
Buffer< SparseColumn > m_block_cols
the matrices stored in CCS order
const Buffer< int > * _colBlockIndices
vector of the indices of the blocks along the cols
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?
const Buffer< int > & colBlockIndices() const
indices of the column blocks
int cols() const
columns of the matrix
void sortColumns()
sort the blocks in each column
const Buffer< SparseColumn > & columns() const
the block matrices per block-column
int rows() const
rows of the matrix
int colsOfBlock(int c) const
how many cols does the block at block-col c has?
int rowsOfBlock(int r) const
how many rows does the block at block-row r has?
int rowBaseOfBlock(int r) const
where does the row at block-row r start?
int fillCCS(int *Cp, int *Ci, g_type *Cx, bool upperTriangle=false) const
fill the CCS arrays of a matrix, arrays have to be allocated beforehand
const Buffer< int > & rowBlockIndices() const
indices of the row blocks
int fillCCS(g_type *Cx, bool upperTriangle=false) const
fill the CCS arrays of a matrix, arrays have to be allocated beforehand.
Sparse matrix which uses blocks based on hash structures.
const Buffer< int > & colBlockIndices() const
indices of the column blocks
const Buffer< int > * _colBlockIndices
vector of the indices of the blocks along the cols
MatrixType * addBlock(int r, uint04 c, bool zeroBlock=false)
add a block to the pattern, return a pointer to the added block
int rows() const
rows of the matrix
int rowsOfBlock(int r) const
how many rows does the block at block-row r has?
const Buffer< int > * _rowBlockIndices
vector of the indices of the blocks along the rows.
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?
int cols() const
columns of the matrix
const Buffer< SparseColumn > & columns() const
the block matrices per block-column
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 Buffer< int > & rowBlockIndices() const
indices of the row blocks
Buffer< SparseColumn > m_block_cols
the matrices stored in CCS order
Internal helper functions for block-wise matrix-vector products (axpy and atxpy).
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
MatrixType block
matrix pointer for the block