10 #ifndef _mrpt_math_MatrixBlockSparseCols_H
11 #define _mrpt_math_MatrixBlockSparseCols_H
39 template <
typename Scalar,
int NROWS,
int NCOLS,
typename INFO,
bool HAS_REMAP,
40 typename INDEX_REMAP_MAP_IMPL =
44 typedef Eigen::Matrix<Scalar, NROWS, NCOLS>
matrix_t;
76 if (!HAS_REMAP) assert(
false);
81 if (!HAS_REMAP) assert(
false);
88 const size_t idx =
cols.size();
99 return *
cols.rbegin();
127 const std::string& filename,
const bool force_symmetry =
false,
128 const bool is_col_compressed =
true)
const
131 getAsDense(D, force_symmetry, is_col_compressed);
132 return D.saveToTextFile(filename);
141 const bool is_col_compressed =
true)
const
143 const size_t nCols =
cols.size();
146 if (is_col_compressed)
147 D.setSize(nRows * NROWS, nCols * NCOLS);
149 D.setSize(nCols * NROWS, nRows * NCOLS);
151 for (
size_t j = 0; j < nCols; j++)
154 itRow !=
cols[j].end(); ++itRow)
156 const size_t row = itRow->first;
157 const size_t row_idx =
158 is_col_compressed ?
row * NROWS : j * NROWS;
159 const size_t col_idx =
160 is_col_compressed ? j * NCOLS :
row * NCOLS;
161 D.block(row_idx, col_idx, NROWS, NCOLS) = itRow->second.num;
162 if (force_symmetry && row_idx != col_idx)
163 D.block(col_idx, row_idx, NCOLS, NROWS) =
164 itRow->second.num.transpose();
174 const size_t nCols =
cols.size();
175 for (
size_t j = 0; j < nCols; j++)
177 itRow !=
cols[j].end(); ++itRow)
185 template <
class MATRIX>
188 const size_t nCols =
cols.size();
190 out.zeros(nRows, nCols);
191 for (
size_t j = 0; j < nCols; j++)
193 itRow !=
cols[j].end(); ++itRow)
195 const size_t row = itRow->first;
205 const size_t nC = o.
cols.size();
206 if (
cols.size() != nC)
210 for (
size_t i = 0; i < nC; i++)
214 it != o.
cols[i].end(); ++it)
215 cols[i][it->first].num = it->second.num;
221 for (
size_t i = 0; i < nC; i++)
227 while (it_src != o.
cols[i].end())
229 if (it_dst->first < it_src->first)
231 it_dst->second.num.setZero();
234 else if (it_dst->first > it_src->first)
236 cols[i][it_src->first].num = it_src->second.num;
241 it_dst->second.num = it_src->second.num;
void clear()
Clear the contents of this container.
const Scalar * const_iterator
EIGEN_STRONG_INLINE iterator begin()
GLenum GLenum GLvoid * row
GLsizei const GLchar ** string
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value.
void clear()
Clear the contents of this container.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::map< TYPE1, TYPE2, std::less< TYPE1 >, Eigen::aligned_allocator< std::pair< const TYPE1, TYPE2 > > > map_t
matrix_t num
Numeric matrix.
symbolic_t sym
Extra symbolic info.
A templated column-indexed efficient storage of block-sparse Jacobian or Hessian matrices,...
void getBinaryBlocksRepresentation(MATRIX &out) const
Builds a binary matrix with 1s where an elementary matrix is stored, 0s elsewhere.
mrpt::aligned_containers< size_t, TEntry >::map_t col_t
Each compressed sparse column.
const mrpt::utils::map_as_vector< size_t, size_t > & getColInverseRemappedIndices() const
void saveToTextFileAsDense(const std::string &filename, const bool force_symmetry=false, const bool is_col_compressed=true) const
Builds a dense representation of the matrix and saves to a text file.
void getAsDense(mrpt::math::CMatrixDouble &D, const bool force_symmetry=false, const bool is_col_compressed=true) const
Builds a dense representation of the matrix and saves to a text file.
size_t findCurrentNumberOfRows() const
Goes over all the columns and keep the largest column length.
void clearColEntries()
Clear all the entries in each column (do not change the number of columns, though!...
void setColCount(const size_t nCols)
Change the number of columns (keep old contents)
col_t & getCol(const size_t idx)
col_t & appendCol(const size_t remapIndex)
Append one column, returning a ref to the new col_t data.
std::deque< col_t > cols
-> cols[i]: i'th column.
std::vector< size_t > col_remapped_indices
mrpt::utils::map_as_vector< size_t, size_t > col_inverse_remapped_indices
"remapped index" is the index of some global variable, interpreted by the external user of this class...
const std::vector< size_t > & getColRemappedIndices() const
Eigen::Matrix< Scalar, NROWS, NCOLS > matrix_t
void copyNumericalValuesFrom(const MatrixBlockSparseCols< Scalar, NROWS, NCOLS, INFO, HAS_REMAP > &o)
Clear the current contents of this objects and replicates the sparse structure and numerical values o...
void clearAll()
Clear all the entries in each column (do not change the number of columns, though!...
size_t getColCount() const
Get current number of cols.
const col_t & getCol(const size_t idx) const