Go to the documentation of this file.
60 typename SparseMatrixMap::const_reverse_iterator;
97 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
98 if (
r >=
mRows ||
c >=
mColumns)
throw std::logic_error(
"Out of range");
108 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
109 if (
r >=
mRows ||
c >=
mColumns)
throw std::logic_error(
"Out of range");
128 template <
typename VECTOR>
129 void getRow(
size_t nRow, VECTOR& vec)
const
131 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
132 if (nRow >=
mRows)
throw std::logic_error(
"Out of range");
135 size_t nextIndex = 0;
139 const std::pair<size_t, size_t>&
index = it->first;
140 if (
index.first < nRow)
142 else if (
index.first == nRow)
144 for (
size_t i = nextIndex; i <
index.second; i++) vec[i] = T();
145 vec[
index.second] = it->second;
146 nextIndex =
index.second + 1;
150 for (
size_t i = nextIndex; i <
mColumns; i++) vec[i] = T();
160 template <
typename VECTOR>
163 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
164 if (nCol >=
mColumns)
throw std::logic_error(
"Out of range");
167 size_t nextIndex = 0;
171 const std::pair<size_t, size_t>&
index = it->first;
172 if (
index.second == nCol)
174 for (
size_t i = nextIndex; i <
index.first; i++) vec[i] = T();
175 vec[
index.first] = it->second;
176 nextIndex =
index.first + 1;
179 for (
size_t i = nextIndex; i <
mRows; i++) vec[i] = T();
191 template <
class MATRIX_LIKE>
194 for (
size_t nr = 0; nr < mat.rows(); nr++)
195 for (
size_t nc = 0; nc < mat.cols(); nc++)
196 operator()(
row + nr,
column + nc) = mat(nr, nc);
237 template <
typename VECTOR>
238 void setRow(
size_t nRow,
const VECTOR& vec,
const T& nullObject = T())
240 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
241 if (nRow >=
mRows)
throw std::logic_error(
"Out of range");
243 size_t N = vec.size();
244 if (N !=
mColumns)
throw std::logic_error(
"Wrong-sized vector");
245 for (
size_t i = 0; i < N; i++)
247 const T&
obj = vec[i];
248 std::pair<size_t, size_t>
index = std::make_pair(nRow, i);
249 if (
obj == nullObject)
262 template <
typename VECTOR>
263 void setColumn(
size_t nCol,
const VECTOR& vec,
const T& nullObject = T())
265 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
266 if (nCol >=
mColumns)
throw std::logic_error(
"Out of range");
268 size_t N = vec.size();
269 if (N !=
mRows)
throw std::logic_error(
"Wrong-sized vector");
270 for (
size_t i = 0; i < N; i++)
272 const T&
obj = vec[i];
273 std::pair<size_t, size_t>
index = std::make_pair(i, nCol);
274 if (
obj == nullObject)
290 std::vector<std::pair<size_t, size_t>> toErase;
294 const std::pair<size_t, size_t>& i = it->first;
295 if (i.first >= nRows || i.second >= nCols)
296 toErase.push_back(it->first);
300 it != toErase.end(); ++it)
309 size_t firstRow,
size_t lastRow,
size_t firstColumn,
310 size_t lastColumn)
const
312 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
314 throw std::logic_error(
"Out of range");
315 if (firstRow > lastRow || firstColumn > lastColumn)
316 throw std::logic_error(
"Invalid size");
319 lastRow + 1 - firstRow, lastColumn + 1 - firstColumn);
323 const std::pair<size_t, size_t>& i = it->first;
324 if (i.first >= firstRow && i.first <= lastRow &&
325 i.second >= firstColumn && i.second <= lastColumn)
326 res(i.first - firstRow, i.second - firstColumn) = it->second;
334 template <
typename VECTOR>
342 vec.push_back(it->second);
366 inline bool isNull(
size_t nRow,
size_t nCol)
const
369 throw std::logic_error(
"Out of range");
370 return objectList.count(std::make_pair(nRow, nCol)) == 0;
379 throw std::logic_error(
"Out of range");
380 return objectList.count(std::make_pair(nRow, nCol)) > 0;
392 std::vector<std::pair<size_t, size_t>> nulls;
394 if (it->second == nullObject) nulls.push_back(it->first);
397 it != nulls.end(); ++it)
431 if (
c <
r) std::swap(
r,
c);
441 if (
c <
r) std::swap(
r,
c);
444 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.
void getAsVector(VECTOR &vec) const
Gets a vector containing all the elements of the matrix, ignoring their position.
CSparseMatrixTemplate()
Basic constructor with no data.
const Scalar * const_iterator
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)
virtual ~CSparseSymmetricalMatrix()
T operator()(size_t r, size_t c) const
Element access operator.
GLenum GLenum GLvoid GLvoid * column
GLsizei GLsizei GLuint * obj
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
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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...
GLdouble GLdouble GLdouble r
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.
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.
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.
GLenum GLenum GLvoid * row
void getRow(size_t nRow, VECTOR &vec) const
Extracts a full row from the matrix.
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 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |