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;
EIGEN_STRONG_INLINE iterator begin()
const Scalar * const_iterator
GLenum GLenum GLvoid * row
GLsizei const GLchar ** string
void clear()
Clear the contents of this container.
This base provides a set of functions for maths stuff.
std::map< KEY, VALUE, std::less< KEY >, mrpt::aligned_allocator_cpp11< std::pair< const KEY, VALUE > >> aligned_std_map
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.
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.
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)
Eigen::Matrix< Scalar, NROWS, NCOLS > matrix_t
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
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 cols() const
Get current number of cols.
const col_t & getCol(const size_t idx) const
mrpt::aligned_std_map< size_t, TEntry > col_t
Each compressed sparse column.