27 #ifndef G2O_SPARSE_BLOCK_MATRIX_CCS_H 28 #define G2O_SPARSE_BLOCK_MATRIX_CCS_H 34 #include "g2o/config.h" 37 #include <unordered_map> 48 template <
class MatrixType>
68 RowBlock(
int r, MatrixType* b) : row(r), block(b) {}
104 dest=
new double [ destSize ];
105 memset(dest,0, destSize*
sizeof(
double));
109 Eigen::Map<Eigen::VectorXd> destVec(dest, destSize);
110 Eigen::Map<const Eigen::VectorXd> srcVec(src,
rows());
113 # pragma omp parallel for default (shared) schedule(dynamic, 10) 115 for (
int i=0; i < static_cast<int>(
_blockCols.size()); ++i){
117 for (
typename SparseColumn::const_iterator it =
_blockCols[i].begin(); it!=
_blockCols[i].end(); ++it) {
118 const SparseMatrixBlock* a = it->block;
121 internal::template atxpy<SparseMatrixBlock>(*a, srcVec, srcOffset, destVec, destOffset);
131 for (
int i=0; i < static_cast<int>(
_blockCols.size()); ++i){
139 int fillCCS(
int* Cp,
int* Ci,
double* Cx,
bool upperTriangle =
false)
const 141 assert(Cp && Ci && Cx &&
"Target destination is NULL");
146 for (
int c=0; c<csize; ++c) {
148 for (
typename SparseColumn::const_iterator it =
_blockCols[i].begin(); it!=
_blockCols[i].end(); ++it) {
149 const SparseMatrixBlock* b=it->block;
152 int elemsToCopy = b->rows();
153 if (upperTriangle && rstart == cstart)
155 for (
int r=0; r<elemsToCopy; ++r){
172 int fillCCS(
double* Cx,
bool upperTriangle =
false)
const 174 assert(Cx &&
"Target destination is NULL");
175 double* CxStart = Cx;
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;
184 int elemsToCopy = b->rows();
185 if (upperTriangle && rstart == cstart)
187 memcpy(Cx, b->data() + c*b->rows(), elemsToCopy *
sizeof(double));
210 template <
class MatrixType>
253 MatrixType*
addBlock(
int r,
int c,
bool zeroBlock =
false)
255 assert(c <(
int)
_blockCols.size() &&
"accessing column which is not available");
257 typename SparseColumn::iterator foundIt = sparseColumn.find(r);
258 if (foundIt == sparseColumn.end()) {
261 MatrixType* m =
new MatrixType(rb, cb);
267 return foundIt->second;
MatrixType SparseMatrixBlock
this is the type of the elementary block, it is an Eigen::Matrix.
int fillCCS(double *Cx, bool upperTriangle=false) const
const std::vector< int > & colBlockIndices() const
indices of the column blocks
const std::vector< int > & rowBlockIndices() const
indices of the row blocks
void rightMultiply(double *&dest, const double *src) const
std::unordered_map< int, MatrixType * > SparseColumn
MatrixType SparseMatrixBlock
this is the type of the elementary block, it is an Eigen::Matrix.
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?
std::vector< SparseColumn > & blockCols()
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?
const std::vector< int > & _colBlockIndices
vector of the indices of the blocks along the cols
std::vector< RowBlock > SparseColumn
SparseBlockMatrixHashMap(const std::vector< int > &rowIndices, const std::vector< int > &colIndices)
std::vector< SparseColumn > & blockCols()
int fillCCS(int *Cp, int *Ci, double *Cx, bool upperTriangle=false) const
int cols() const
columns of the matrix
MatrixType * addBlock(int r, int c, bool zeroBlock=false)
const std::vector< SparseColumn > & blockCols() const
the block matrices per block-column
Sparse matrix which uses blocks.
int colBaseOfBlock(int c) const
where does the col at block-col r start?
std::vector< SparseColumn > _blockCols
the matrices stored in CCS order
int colsOfBlock(int c) const
how many cols does the block at block-col c has?
int cols() const
columns of the matrix
const std::vector< int > & _rowBlockIndices
vector of the indices of the blocks along the rows.
SparseBlockMatrixCCS(const std::vector< int > &rowIndices, const std::vector< int > &colIndices)
MatrixType * block
matrix pointer for the block
std::vector< SparseColumn > _blockCols
the matrices stored in CCS order
const std::vector< int > & rowBlockIndices() const
indices of the row blocks
const std::vector< int > & _rowBlockIndices
vector of the indices of the blocks along the rows.
const std::vector< int > & _colBlockIndices
vector of the indices of the blocks along the cols
int rowsOfBlock(int r) const
how many rows does the block at block-row r has?
int rows() const
rows of the matrix
Sparse matrix which uses blocks based on hash structures.
RowBlock(int r, MatrixType *b)
const std::vector< SparseColumn > & blockCols() const
the block matrices per block-column
bool operator<(const RowBlock &other) const
int rowBaseOfBlock(int r) const
where does the row at block-row r start?
const std::vector< int > & colBlockIndices() const
indices of the column blocks