27#ifndef G2O_SPARSE_BLOCK_MATRIX_CCS_H
28#define G2O_SPARSE_BLOCK_MATRIX_CCS_H
32#include <unordered_map>
35#include "g2o/config.h"
47template <
class MatrixType>
75 const std::vector<int>& colIndices)
107 int destSize =
cols();
110 dest =
new double[destSize];
111 memset(dest, 0, destSize *
sizeof(
double));
115 Eigen::Map<VectorX> destVec(dest, destSize);
116 Eigen::Map<const VectorX> srcVec(src,
rows());
119#pragma omp parallel for default(shared) schedule(dynamic, 10)
121 for (
int i = 0; i < static_cast<int>(
_blockCols.size()); ++i) {
123 for (
typename SparseColumn::const_iterator it =
_blockCols[i].begin();
129 internal::template atxpy<SparseMatrixBlock>(*a, srcVec, srcOffset,
130 destVec, destOffset);
139 for (
int i = 0; i < static_cast<int>(
_blockCols.size()); ++i) {
147 int fillCCS(
int* Cp,
int* Ci,
double* Cx,
bool upperTriangle =
false)
const {
148 assert(Cp && Ci && Cx &&
"Target destination is NULL");
150 for (
size_t i = 0; i <
_blockCols.size(); ++i) {
153 for (
int c = 0; c < csize; ++c) {
155 for (
typename SparseColumn::const_iterator it =
_blockCols[i].begin();
160 int elemsToCopy = b->rows();
161 if (upperTriangle && rstart == cstart) elemsToCopy = c + 1;
162 for (
int r = 0; r < elemsToCopy; ++r) {
180 int fillCCS(
double* Cx,
bool upperTriangle =
false)
const {
181 assert(Cx &&
"Target destination is NULL");
182 double* CxStart = Cx;
184 for (
size_t i = 0; i <
_blockCols.size(); ++i) {
186 for (
int c = 0; c < csize; ++c) {
187 for (
typename SparseColumn::const_iterator it =
_blockCols[i].begin();
192 int elemsToCopy = b->rows();
193 if (upperTriangle && rstart == cstart) elemsToCopy = c + 1;
194 memcpy(Cx, b->data() + c * b->rows(), elemsToCopy *
sizeof(
double));
206 const std::vector<int>&
216template <
class MatrixType>
234 const std::vector<int>& colIndices)
268 MatrixType*
addBlock(
int r,
int c,
bool zeroBlock =
false) {
270 "accessing column which is not available");
272 typename SparseColumn::iterator foundIt = sparseColumn.find(r);
273 if (foundIt == sparseColumn.end()) {
276 MatrixType* m =
new MatrixType(rb, cb);
277 if (zeroBlock) m->setZero();
281 return foundIt->second;
287 const std::vector<int>&
Sparse matrix which uses blocks.
int rowsOfBlock(int r) const
how many rows does the block at block-row r has?
int fillCCS(int *Cp, int *Ci, double *Cx, bool upperTriangle=false) const
int colsOfBlock(int c) const
how many cols does the block at block-col c has?
MatrixType SparseMatrixBlock
this is the type of the elementary block, it is an Eigen::Matrix.
std::vector< RowBlock > SparseColumn
int cols() const
columns of the matrix
int colBaseOfBlock(int c) const
where does the col at block-col r start?
int fillCCS(double *Cx, bool upperTriangle=false) const
const std::vector< SparseColumn > & blockCols() const
the block matrices per block-column
const std::vector< int > & rowBlockIndices() const
indices of the row blocks
int rowBaseOfBlock(int r) const
where does the row at block-row r start?
std::vector< SparseColumn > _blockCols
the matrices stored in CCS order
SparseBlockMatrixCCS(const std::vector< int > &rowIndices, const std::vector< int > &colIndices)
std::vector< SparseColumn > & blockCols()
int rows() const
rows of the matrix
void rightMultiply(double *&dest, const double *src) const
const std::vector< int > & colBlockIndices() const
indices of the column blocks
const std::vector< int > & _colBlockIndices
vector of the indices of the blocks along the cols
const std::vector< int > & _rowBlockIndices
Sparse matrix which uses blocks based on hash structures.
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
MatrixType * addBlock(int r, int c, bool zeroBlock=false)
std::unordered_map< int, MatrixType * > SparseColumn
int colsOfBlock(int c) const
how many cols does the block at block-col c has?
const std::vector< int > & rowBlockIndices() const
indices of the row blocks
int cols() const
columns of the matrix
std::vector< SparseColumn > & blockCols()
int rowBaseOfBlock(int r) const
where does the row at block-row r start?
const std::vector< int > & _rowBlockIndices
SparseBlockMatrixHashMap(const std::vector< int > &rowIndices, const std::vector< int > &colIndices)
const std::vector< SparseColumn > & blockCols() const
the block matrices per block-column
int colBaseOfBlock(int c) const
where does the col at block-col r start?
const std::vector< int > & colBlockIndices() const
indices of the column blocks
int rows() const
rows of the matrix
std::vector< SparseColumn > _blockCols
the matrices stored in CCS order
int rowsOfBlock(int r) const
how many rows does the block at block-row r has?
RowBlock(int r, MatrixType *b)
MatrixType * block
matrix pointer for the block
bool operator<(const RowBlock &other) const