10 #ifndef _mrpt_math_MatrixBlockSparseCols_H 11 #define _mrpt_math_MatrixBlockSparseCols_H 37 template <
typename Scalar,
int NROWS,
int NCOLS,
typename INFO,
bool HAS_REMAP,
38 typename INDEX_REMAP_MAP_IMPL =
39 mrpt::utils::map_as_vector<size_t, size_t>>
42 using matrix_t = Eigen::Matrix<Scalar, NROWS, NCOLS>;
71 inline const mrpt::utils::map_as_vector<size_t, size_t>&
74 if (!HAS_REMAP) assert(
false);
79 if (!HAS_REMAP) assert(
false);
86 const size_t idx =
cols.size();
97 return *
cols.rbegin();
125 const std::string& filename,
const bool force_symmetry =
false,
126 const bool is_col_compressed =
true)
const 129 getAsDense(D, force_symmetry, is_col_compressed);
130 return D.saveToTextFile(filename);
139 const bool is_col_compressed =
true)
const 141 const size_t nCols =
cols.size();
144 if (is_col_compressed)
145 D.setSize(nRows * NROWS, nCols * NCOLS);
147 D.setSize(nCols * NROWS, nRows * NCOLS);
149 for (
size_t j = 0; j < nCols; j++)
152 itRow !=
cols[j].end(); ++itRow)
154 const size_t row = itRow->first;
155 const size_t row_idx =
156 is_col_compressed ?
row * NROWS : j * NROWS;
157 const size_t col_idx =
158 is_col_compressed ? j * NCOLS :
row * NCOLS;
159 D.block(row_idx, col_idx, NROWS, NCOLS) = itRow->second.num;
160 if (force_symmetry && row_idx != col_idx)
161 D.block(col_idx, row_idx, NCOLS, NROWS) =
162 itRow->second.num.transpose();
172 const size_t nCols =
cols.size();
173 for (
size_t j = 0; j < nCols; j++)
175 itRow !=
cols[j].end(); ++itRow)
183 template <
class MATRIX>
186 const size_t nCols =
cols.size();
188 out.zeros(nRows, nCols);
189 for (
size_t j = 0; j < nCols; j++)
191 itRow !=
cols[j].end(); ++itRow)
193 const size_t row = itRow->first;
203 const size_t nC = o.
cols.size();
204 if (
cols.size() != nC)
208 for (
size_t i = 0; i < nC; i++)
212 it != o.
cols[i].end(); ++it)
213 cols[i][it->first].num = it->second.num;
219 for (
size_t i = 0; i < nC; i++)
225 while (it_src != o.
cols[i].end())
227 if (it_dst->first < it_src->first)
229 it_dst->second.num.setZero();
232 else if (it_dst->first > it_src->first)
234 cols[i][it_src->first].num = it_src->second.num;
239 it_dst->second.num = it_src->second.num;
251 #endif //_mrpt_math_MatrixBlockSparseCols_H
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.
symbolic_t sym
Extra symbolic info.
void getBinaryBlocksRepresentation(MATRIX &out) const
Builds a binary matrix with 1s where an elementary matrix is stored, 0s elsewhere.
const col_t & getCol(const size_t idx) const
EIGEN_STRONG_INLINE iterator begin()
col_t & appendCol(const size_t remapIndex)
Append one column, returning a ref to the new col_t data.
std::map< KEY, VALUE, std::less< KEY >, mrpt::aligned_allocator_cpp11< std::pair< const KEY, VALUE > >> aligned_std_map
mrpt::aligned_std_map< size_t, TEntry > col_t
Each compressed sparse column.
matrix_t num
Numeric matrix.
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.
This base provides a set of functions for maths stuff.
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 setColCount(const size_t nCols)
Change the number of columns (keep old contents)
size_t cols() const
Get current number of cols.
GLsizei const GLchar ** string
std::deque< col_t > cols
-> cols[i]: i'th column.
A templated column-indexed efficient storage of block-sparse Jacobian or Hessian matrices, together with other arbitrary information.
size_t findCurrentNumberOfRows() const
Goes over all the columns and keep the largest column length.
col_t & getCol(const size_t idx)
void clearColEntries()
Clear all the entries in each column (do not change the number of columns, though!) ...
const std::vector< size_t > & getColRemappedIndices() const
const mrpt::utils::map_as_vector< size_t, size_t > & getColInverseRemappedIndices() const
GLenum GLenum GLvoid * row
void clearAll()
Clear all the entries in each column (do not change the number of columns, though!) ...
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...
std::vector< size_t > col_remapped_indices
void clear()
Clear the contents of this container.
const Scalar * const_iterator
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...
Eigen::Matrix< Scalar, NROWS, NCOLS > matrix_t