Go to the documentation of this file.
58 typename SparseMatrixMap::const_reverse_iterator;
84 auto it =
objectList.find(std::make_pair(r, c));
93 inline bool exists(
size_t r,
size_t c)
const
95 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
96 if (r >=
mRows || c >=
mColumns)
throw std::logic_error(
"Out of range");
106 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
107 if (r >=
mRows || c >=
mColumns)
throw std::logic_error(
"Out of range");
126 template <
typename VECTOR>
127 void getRow(
size_t nRow, VECTOR& vec)
const
129 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
130 if (nRow >=
mRows)
throw std::logic_error(
"Out of range");
133 size_t nextIndex = 0;
134 for (
typename SparseMatrixMap::const_iterator it =
objectList.begin();
137 const std::pair<size_t, size_t>& index = it->first;
138 if (index.first < nRow)
140 else if (index.first == nRow)
142 for (
size_t i = nextIndex; i < index.second; i++) vec[i] = T();
143 vec[index.second] = it->second;
144 nextIndex = index.second + 1;
148 for (
size_t i = nextIndex; i <
mColumns; i++) vec[i] = T();
158 template <
typename VECTOR>
161 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
162 if (nCol >=
mColumns)
throw std::logic_error(
"Out of range");
165 size_t nextIndex = 0;
166 for (
typename SparseMatrixMap::const_iterator it =
objectList.begin();
169 const std::pair<size_t, size_t>& index = it->first;
170 if (index.second == nCol)
172 for (
size_t i = nextIndex; i < index.first; i++) vec[i] = T();
173 vec[index.first] = it->second;
174 nextIndex = index.first + 1;
177 for (
size_t i = nextIndex; i <
mRows; i++) vec[i] = T();
183 inline void insert(
size_t row,
size_t column,
const T& obj)
189 template <
class MATRIX_LIKE>
190 inline void insertMatrix(
size_t row,
size_t column,
const MATRIX_LIKE& mat)
192 for (
size_t nr = 0; nr < mat.rows(); nr++)
193 for (
size_t nc = 0; nc < mat.cols(); nc++)
194 operator()(row + nr, column + nc) = mat(nr, nc);
235 template <
typename VECTOR>
236 void setRow(
size_t nRow,
const VECTOR& vec,
const T& nullObject = T())
238 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
239 if (nRow >=
mRows)
throw std::logic_error(
"Out of range");
241 size_t N = vec.size();
242 if (N !=
mColumns)
throw std::logic_error(
"Wrong-sized vector");
243 for (
size_t i = 0; i < N; i++)
245 const T& obj = vec[i];
246 std::pair<size_t, size_t> index = std::make_pair(nRow, i);
247 if (obj == nullObject)
260 template <
typename VECTOR>
261 void setColumn(
size_t nCol,
const VECTOR& vec,
const T& nullObject = T())
263 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
264 if (nCol >=
mColumns)
throw std::logic_error(
"Out of range");
266 size_t N = vec.size();
267 if (N !=
mRows)
throw std::logic_error(
"Wrong-sized vector");
268 for (
size_t i = 0; i < N; i++)
270 const T& obj = vec[i];
271 std::pair<size_t, size_t> index = std::make_pair(i, nCol);
272 if (obj == nullObject)
288 std::vector<std::pair<size_t, size_t>> toErase;
291 const std::pair<size_t, size_t>& i = it->first;
292 if (i.first >= nRows || i.second >= nCols)
293 toErase.push_back(it->first);
295 for (
auto it = toErase.begin(); it != toErase.end(); ++it)
304 size_t firstRow,
size_t lastRow,
size_t firstColumn,
305 size_t lastColumn)
const
307 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
309 throw std::logic_error(
"Out of range");
310 if (firstRow > lastRow || firstColumn > lastColumn)
311 throw std::logic_error(
"Invalid size");
314 lastRow + 1 - firstRow, lastColumn + 1 - firstColumn);
315 for (
typename SparseMatrixMap::const_iterator it =
begin(); it !=
end();
318 const std::pair<size_t, size_t>& i = it->first;
319 if (i.first >= firstRow && i.first <= lastRow &&
320 i.second >= firstColumn && i.second <= lastColumn)
321 res(i.first - firstRow, i.second - firstColumn) = it->second;
329 template <
typename VECTOR>
337 vec.push_back(it->second);
361 inline bool isNull(
size_t nRow,
size_t nCol)
const
364 throw std::logic_error(
"Out of range");
365 return objectList.count(std::make_pair(nRow, nCol)) == 0;
374 throw std::logic_error(
"Out of range");
375 return objectList.count(std::make_pair(nRow, nCol)) > 0;
387 std::vector<std::pair<size_t, size_t>> nulls;
389 if (it->second == nullObject) nulls.push_back(it->first);
390 for (
auto it = nulls.begin(); it != nulls.end(); ++it)
424 if (c < r) std::swap(r, c);
434 if (c < r) std::swap(r, c);
437 throw std::logic_error(
"Out of range");
bool empty() const
Are there no elements set to !=0 ?
typename SparseMatrixMap::const_reverse_iterator const_reverse_iterator
Const reverse iterator to move through the matrix.
bool isNull(size_t nRow, size_t nCol) const
Checks whether an element of the matrix is the default object.
void resize(size_t matrixSize)
T operator()(size_t r, size_t c) const
Element access operator.
typename SparseMatrixMap::const_iterator const_iterator
Const iterator to move through the matrix.
SparseMatrixMap objectList
Actual matrix.
T operator()(size_t r, size_t c) const
const_reverse_iterator rbegin() const
Returns an iterator which points to the end of the matrix, and can be used to move backwards.
void insertMatrix(size_t row, size_t column, const MATRIX_LIKE &mat)
Inserts submatrix at a given location.
const_reverse_iterator rend() const
Returns an iterator which points to the starting point of the matrix, although it's the upper limit o...
CSparseSymmetricalMatrix(const CSparseMatrixTemplate< T > &o)
void insert(size_t row, size_t column, const T &obj)
Inserts an element into the matrix.
size_t rows() const
Returns the amount of rows in this matrix.
size_t getNonNullElements() const
Gets the amount of non-null elements inside the matrix.
T & operator()(size_t r, size_t c)
Reference access operator.
void setRow(size_t nRow, const VECTOR &vec, const T &nullObject=T())
Inserts a full row into the matrix.
void getColumn(size_t nCol, VECTOR &vec) const
Extracts a full column from the matrix.
bool isNotNull(size_t nRow, size_t nCol) const
Checks whether an element of the matrix is not the default object.
const_iterator begin() const
Returns an iterator which points to the starting point of the matrix.
void purge(T nullObject=T())
Checks each non-null elements against the basic objects, erasing unnecesary references to it.
CSparseMatrixTemplate(size_t nR, size_t nC)
Constructor with default size.
CSparseSymmetricalMatrix()
CSparseMatrixTemplate< T > operator()(size_t firstRow, size_t lastRow, size_t firstColumn, size_t lastColumn) const
Extracts a submatrix form the matrix.
void asVector(VECTOR &vec) const
Gets a vector containing all the elements of the matrix, ignoring their position.
A sparse matrix container (with cells of any type), with iterators.
void resize(size_t nRows, size_t nCols)
Changes the size of the matrix.
const_iterator end() const
Returns an iterator which points to the end of the matrix.
virtual ~CSparseSymmetricalMatrix()=default
CSparseSymmetricalMatrix(const CSparseSymmetricalMatrix &o)
void setColumn(size_t nCol, const VECTOR &vec, const T &nullObject=T())
Inserts a full column into the matrix.
bool exists(size_t r, size_t c) const
Element access operator.
size_t cols() const
Returns the amount of columns in this matrix.
void clear()
Completely removes all elements, although maintaining the matrix's size.
void getRow(size_t nRow, VECTOR &vec) const
Extracts a full row from the matrix.
This base provides a set of functions for maths stuff.
CSparseMatrixTemplate()=default
Basic constructor with no data.
typename std::map< std::pair< size_t, size_t >, T > SparseMatrixMap
Internal map type, used to store the actual matrix.
size_t getNullElements() const
Gets the amount of null elements inside the matrix.
T & operator()(size_t r, size_t c)
A sparse matrix container for square symmetrical content around the main diagonal.
size_t mRows
Size of the matrix.
Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sat Jun 27 14:00:59 UTC 2020 | |