27 #ifndef G2O_SPARSE_BLOCK_MATRIX_CCS_H 28 #define G2O_SPARSE_BLOCK_MATRIX_CCS_H 34 #include "../../config.h" 38 #include <unordered_map> 40 #include <tr1/unordered_map> 52 template <
class MatrixType>
72 RowBlock(
int r, MatrixType* b) : row(r), block(b) {}
108 dest=
new double [ destSize ];
109 memset(dest,0, destSize*
sizeof(
double));
113 Eigen::Map<Eigen::VectorXd> destVec(dest, destSize);
114 Eigen::Map<const Eigen::VectorXd> srcVec(src,
rows());
117 # pragma omp parallel for default (shared) schedule(dynamic, 10) 119 for (
int i=0; i < static_cast<int>(
_blockCols.size()); ++i){
121 for (
typename SparseColumn::const_iterator it =
_blockCols[i].begin(); it!=
_blockCols[i].end(); ++it) {
122 const SparseMatrixBlock* a = it->block;
135 for (
int i=0; i < static_cast<int>(
_blockCols.size()); ++i){
143 int fillCCS(
int* Cp,
int* Ci,
double* Cx,
bool upperTriangle =
false)
const 145 assert(Cp && Ci && Cx &&
"Target destination is NULL");
150 for (
int c=0; c<csize; ++c) {
152 for (
typename SparseColumn::const_iterator it =
_blockCols[i].begin(); it!=
_blockCols[i].end(); ++it) {
153 const SparseMatrixBlock* b=it->block;
156 int elemsToCopy = b->rows();
157 if (upperTriangle && rstart == cstart)
159 for (
int r=0; r<elemsToCopy; ++r){
176 int fillCCS(
double* Cx,
bool upperTriangle =
false)
const 178 assert(Cx &&
"Target destination is NULL");
179 double* CxStart = Cx;
183 for (
int c=0; c<csize; ++c) {
184 for (
typename SparseColumn::const_iterator it =
_blockCols[i].begin(); it!=
_blockCols[i].end(); ++it) {
185 const SparseMatrixBlock* b = it->block;
188 int elemsToCopy = b->rows();
189 if (upperTriangle && rstart == cstart)
191 memcpy(Cx, b->data() + c*b->rows(), elemsToCopy *
sizeof(double));
214 template <
class MatrixType>
257 MatrixType*
addBlock(
int r,
int c,
bool zeroBlock =
false)
259 assert(c <(
int)
_blockCols.size() &&
"accessing column which is not available");
261 typename SparseColumn::iterator foundIt = sparseColumn.find(r);
262 if (foundIt == sparseColumn.end()) {
265 MatrixType* m =
new MatrixType(rb, cb);
271 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
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?
void atxpy(const MatrixType &A, const Eigen::Map< const Eigen::VectorXd > &x, int xoff, Eigen::Map< Eigen::VectorXd > &y, int yoff)
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
std::tr1::unordered_map< int, MatrixType * > SparseColumn
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