MRPT  1.9.9
CMatrixDynamic.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
12 #include <mrpt/core/exceptions.h> // ASSERT_()
13 #include <mrpt/core/format.h>
14 #include <mrpt/math/MatrixBase.h>
15 #include <mrpt/math/math_frwds.h> // forward declarations
18 #include <algorithm> // swap()
19 #include <cstring> // memset()
20 #include <type_traits>
21 
22 namespace mrpt::math
23 {
24 /** This template class provides the basic functionality for a general 2D
25  *any-size, resizable container of numerical or non-numerical elements.
26  * NOTES:
27  * - This class is not serializable since it is a template. For using
28  *serialization, see mrpt::math::CMatrixD.
29  * - First row or column index is "0".
30  * - This class includes range checks with ASSERT_() if compiling with "_DEBUG"
31  *or "MRPT_ALWAYS_CHECKS_DEBUG_MATRICES=1".
32  * - Use asEigen() to get an `Eigen::Map<>` object and to access full Algebra
33  *functionality.
34  *
35  * \sa CMatrixFixed
36  * \ingroup mrpt_math_grp
37  */
38 template <class T>
39 class CMatrixDynamic : public MatrixBase<T, CMatrixDynamic<T>>
40 {
41  private:
42  static constexpr size_t small_size = 16;
44  T, small_size, MRPT_MAX_STATIC_ALIGN_BYTES>;
45 
46  /** RowMajor matrix data */
48  size_t m_Rows{0}, m_Cols{0};
49 
50  public:
51  /** @name Matrix type definitions
52  * @{ */
53  /** The type of the matrix elements */
54  using value_type = T;
55  using Scalar = T;
56  using Index = int;
57  using reference = T&;
58  using const_reference = const T&;
59  using size_type = int;
61  constexpr static int RowsAtCompileTime = -1;
62  constexpr static int ColsAtCompileTime = -1;
63  constexpr static int SizeAtCompileTime = -1;
64  constexpr static int is_mrpt_type = 1;
65  constexpr static int StorageOrder = 1 /*rowMajor*/;
66  using eigen_t = Eigen::Matrix<
69  /** @} */
70 
71  /** @name Iterators interface
72  * @{ */
73  using iterator = typename vec_t::iterator;
75  iterator begin() { return m_data.begin(); }
76  iterator end() { return m_data.end(); }
77  const_iterator begin() const { return m_data.begin(); }
78  const_iterator end() const { return m_data.end(); }
79  const_iterator cbegin() const { return m_data.begin(); }
80  const_iterator cend() const { return m_data.end(); }
81  /** @} */
82 
83  private:
84  /** Internal use only: It reallocs the memory for the 2D matrix, maintaining
85  * the previous contents if posible.
86  */
87  void realloc(size_t row, size_t col, bool newElementsToZero = false)
88  {
89  if (row == m_Rows && col == m_Cols) return;
90  const auto old_rows = m_Rows, old_cols = m_Cols;
91  m_Rows = row;
92  m_Cols = col;
93 
94  // New buffer:
95  decltype(m_data) newData;
96  newData.resize(m_Rows * m_Cols);
97  // Copy old content:
98  const auto nRowsToCopy = m_Rows >= old_rows ? old_rows : m_Rows;
99  const auto nColsToCopy = m_Cols >= old_cols ? old_cols : m_Cols;
100  for (size_t r = 0; r < nRowsToCopy; r++)
101  {
102  if constexpr (std::is_trivial_v<T>)
103  ::memcpy(
104  &newData[r * m_Cols], &m_data[r * old_cols],
105  sizeof(T) * nColsToCopy);
106  else
107  for (size_t c = 0; c < nColsToCopy; c++)
108  newData[r * m_Cols + c] = m_data[r * old_cols + c];
109  }
110  // New rows to zero?
111  if (newElementsToZero && m_Rows > old_rows)
112  {
113  if constexpr (std::is_trivial_v<T>)
114  ::memset(
115  &newData[old_rows * m_Cols], 0,
116  sizeof(T) * (m_Rows - old_rows));
117  else
118  for (size_t r = old_rows; r < m_Rows; r++)
119  for (size_t c = 0; c < m_Cols; c++)
120  newData[r * m_Cols + c] = T();
121  }
122  // New cols to zero?
123  if (newElementsToZero && m_Cols > old_cols)
124  {
125  for (size_t r = 0; r < old_rows; r++)
126  if constexpr (std::is_trivial_v<T>)
127  ::memset(
128  &newData[r * m_Cols + old_cols], 0,
129  sizeof(T) * (m_Cols - old_cols));
130  else
131  for (size_t c = old_cols; c < m_Cols; c++)
132  newData[r * m_Cols + c] = T();
133  }
134  // Swap:
135  m_data.swap(newData);
136  }
137 
138  public:
139  /** Swap with another matrix very efficiently (just swaps a pointer and two
140  * integer values). */
141  inline void swap(CMatrixDynamic<T>& o)
142  {
143  m_data.swap(o.m_data);
144  std::swap(m_Rows, o.m_Rows);
145  std::swap(m_Cols, o.m_Cols);
146  }
147 
148  /** Constructors */
149  CMatrixDynamic(const CMatrixDynamic& m) { (*this) = m; }
150 
151  CMatrixDynamic(size_t row = 0, size_t col = 0) { realloc(row, col); }
152 
153  /** Copy (casting from if needed) from another matrix */
154  template <typename U>
156  {
157  (*this) = m;
158  }
159 
160  /** Convert from Eigen matrix */
161  template <class Derived>
163  {
164  *this = m;
165  }
166 
167  /** Convert from Eigen product */
168  template <typename _Lhs, typename _Rhs, int Option>
170  {
171  *this = p.eval();
172  }
173  /** Convert from Eigen binary op */
174  template <typename Op, typename Lhs, typename Rhs>
176  {
177  *this = p.eval();
178  }
179 
180  /** Copy constructor & crop from another matrix
181  */
183  const CMatrixDynamic& m, const size_t cropRowCount,
184  const size_t cropColCount)
185  {
186  ASSERT_(m.m_Rows >= cropRowCount);
187  ASSERT_(m.m_Cols >= cropColCount);
188  realloc(cropRowCount, cropColCount);
189  for (size_t i = 0; i < m_Rows; i++)
190  for (size_t j = 0; j < m_Cols; j++) (*this)(i, j) = m(i, j);
191  }
192 
193  /** Constructor from fixed-size matrix: */
194  template <std::size_t ROWS, std::size_t COLS>
196  {
197  *this = o;
198  }
199 
200  /** Constructor from a given size and a C array. The array length must match
201  *cols x row.
202  * \code
203  * const double numbers[] = {
204  * 1,2,3,
205  * 4,5,6 };
206  * CMatrixDouble M(3,2, numbers);
207  * \endcode
208  */
209  template <typename V, size_t N>
210  CMatrixDynamic(size_t row, size_t col, V (&theArray)[N])
211  {
212  static_assert(N != 0, "Empty array!");
213  realloc(row, col);
214  if (m_Rows * m_Cols != N)
216  "Mismatch between matrix size %lu x %lu and array of "
217  "length %lu",
218  static_cast<long unsigned>(m_Rows),
219  static_cast<long unsigned>(m_Cols),
220  static_cast<long unsigned>(N)));
221  size_t idx = 0;
222  for (size_t i = 0; i < m_Rows; i++)
223  for (size_t j = 0; j < m_Cols; j++)
224  (*this)(i, j) = static_cast<T>(theArray[idx++]);
225  }
226 
227  /** Constructor from a given size and a STL container (std::vector,
228  * std::list,...) with the initial values. The vector length must match cols
229  * x row.
230  */
231  template <typename V>
232  CMatrixDynamic(size_t row, size_t col, const V& theVector)
233  {
234  const size_t N = theVector.size();
235  realloc(row, col);
236  if (m_Rows * m_Cols != N)
238  "Mismatch between matrix size %lu x %lu and array of "
239  "length %lu",
240  static_cast<long unsigned>(m_Rows),
241  static_cast<long unsigned>(m_Cols),
242  static_cast<long unsigned>(N)));
243  typename V::const_iterator it = theVector.begin();
244  for (size_t i = 0; i < m_Rows; i++)
245  for (size_t j = 0; j < m_Cols; j++)
246  (*this)(i, j) = static_cast<T>(*(it++));
247  }
248 
249  virtual ~CMatrixDynamic() = default;
250 
251  template <class MAT>
252  void setFromMatrixLike(const MAT& m)
253  {
254  MRPT_START
255  setSize(m.rows(), m.cols());
256  for (Index r = 0; r < rows(); r++)
257  for (Index c = 0; c < cols(); c++) (*this)(r, c) = m(r, c);
258  MRPT_END
259  }
260 
261  CMatrixDynamic& operator=(const CMatrixDynamic<T>& m) = default;
262 
263  /** Assignment operator from another matrix (possibly of a different type)
264  */
265  template <typename U>
267  {
268  MRPT_START
270  return *this;
271  MRPT_END
272  }
273 
274  /** Assignment from an Eigen matrix */
275  template <class Derived>
277  {
278  MRPT_START
280  return *this;
281  MRPT_END
282  }
283  /** Assignment from a fixed matrix */
284  template <std::size_t ROWS, std::size_t COLS>
286  {
287  MRPT_START
289  return *this;
290  MRPT_END
291  }
292 
293  /** Assignment operator for initializing from a C array (The matrix must be
294  *set to the correct size before invoking this asignament)
295  * \code
296  * CMatrixDouble M(3,2);
297  * const double numbers[] = {
298  * 1,2,3,
299  * 4,5,6 };
300  * M = numbers;
301  * \endcode
302  * Refer also to the constructor with initialization data
303  *CMatrixDynamic::CMatrixDynamic
304  */
305  template <typename V, size_t N>
306  CMatrixDynamic& operator=(V (&theArray)[N])
307  {
308  static_assert(N != 0, "Empty array!");
309  if (m_Rows * m_Cols != N)
310  {
312  "Mismatch between matrix size %lu x %lu and array of "
313  "length %lu",
314  m_Rows, m_Cols, N));
315  }
316  size_t idx = 0;
317  for (size_t i = 0; i < m_Rows; i++)
318  for (size_t j = 0; j < m_Cols; j++)
319  (*this)(i, j) = static_cast<T>(theArray[idx++]);
320  return *this;
321  }
322 
323  /** Number of rows in the matrix \sa rows() */
324  inline size_type rows() const { return m_Rows; }
325 
326  /** Number of columns in the matrix \sa rows() */
327  inline size_type cols() const { return m_Cols; }
328 
329  /** Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x)) */
330  inline matrix_size_t size() const
331  {
332  matrix_size_t dims;
333  dims[0] = m_Rows;
334  dims[1] = m_Cols;
335  return dims;
336  }
337 
338  /** Changes the size of matrix, maintaining the previous contents. */
339  void setSize(size_t row, size_t col, bool zeroNewElements = false)
340  {
341  realloc(row, col, zeroNewElements);
342  }
343  void resize(size_t row, size_t col) { setSize(row, col); }
344 
345  /** Resizes as a Nx1 vector */
346  void resize(size_t vectorLen) { setSize(vectorLen, 1); }
347 
348  /** Resize the matrix */
349  inline void resize(const matrix_size_t& siz, bool zeroNewElements = false)
350  {
351  setSize(siz[0], siz[1], zeroNewElements);
352  }
353 
354  // These ones are to make template code compatible with Eigen & mrpt:
355  CMatrixDynamic& derived() { return *this; }
356  const CMatrixDynamic& derived() const { return *this; }
357  void conservativeResize(size_t row, size_t col) { setSize(row, col); }
358 
359  /** Subscript operator to get/set individual elements
360  */
361  inline T& operator()(size_t row, size_t col)
362  {
363 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
364  if (row >= m_Rows || col >= m_Cols)
366  "Indexes (%lu,%lu) out of range. Matrix is %lux%lu",
367  static_cast<unsigned long>(row),
368  static_cast<unsigned long>(col),
369  static_cast<unsigned long>(m_Rows),
370  static_cast<unsigned long>(m_Cols)));
371 #endif
372  return m_data[row * m_Cols + col];
373  }
374 
375  /** Subscript operator to get individual elements
376  */
377  inline const T& operator()(size_t row, size_t col) const
378  {
379 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
380  if (row >= m_Rows || col >= m_Cols)
382  "Indexes (%lu,%lu) out of range. Matrix is %lux%lu",
383  static_cast<unsigned long>(row),
384  static_cast<unsigned long>(col),
385  static_cast<unsigned long>(m_Rows),
386  static_cast<unsigned long>(m_Cols)));
387 #endif
388  return m_data[row * m_Cols + col];
389  }
390 
391  /** Subscript operator to get/set an individual element from a row or column
392  * matrix.
393  * \exception std::exception If the object is not a column or row matrix.
394  */
395  inline T& operator[](size_t ith)
396  {
397 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
398  ASSERT_(m_Rows == 1 || m_Cols == 1);
399 #endif
400  if (m_Rows == 1)
401  {
402 // A row matrix:
403 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
404  if (ith >= m_Cols)
406  "Index %u out of range!", static_cast<unsigned>(ith));
407 #endif
408  }
409  else
410  {
411 // A columns matrix:
412 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
413  if (ith >= m_Rows)
415  "Index %u out of range!", static_cast<unsigned>(ith));
416 #endif
417  }
418  return m_data[ith];
419  }
420 
421  /** Subscript operator to get/set an individual element from a row or column
422  * matrix. For non-vectors (NxM matrices), it returns the i-th matrix
423  * element, in RowMajor order.
424  * \exception std::exception If the object is not a column or row matrix.
425  */
426  inline const T& operator[](size_t ith) const
427  {
428 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
429  ASSERT_BELOW_(ith, m_Rows * m_Cols);
430 #endif
431  return m_data[ith];
432  }
433 
434  /** Appends a new row to the MxN matrix from a 1xN vector.
435  * The lenght of the vector must match the width of the matrix, unless
436  * it's empty: in that case the matrix is resized to 1xN.
437  * \code
438  * CMatrixDouble M(0,0);
439  * CVectorDouble v(7),w(7);
440  * // ...
441  * M.appendRow(v);
442  * M.appendRow(w);
443  * \endcode
444  * \exception std::exception On incorrect vector length.
445  * \sa extractRow
446  * \sa appendCol
447  */
448  template <typename VECTOR>
449  void appendRow(const VECTOR& in)
450  {
451  if (m_Cols == 0 || m_Rows == 0)
452  ASSERT_(!in.empty());
453  else
454  ASSERT_(in.size() == m_Cols);
455  const auto row = m_Rows;
456  realloc(row + 1, m_Cols = in.size());
457  for (size_t i = 0; i < m_Cols; i++) (*this)(row, i) = in[i];
458  }
459 
460  template <typename VECTOR>
461  void setRow(const Index row, const VECTOR& v)
462  {
463  ASSERT_EQUAL_(cols(), static_cast<size_type>(v.size()));
464  for (Index c = 0; c < cols(); c++) (*this)(row, c) = v[c];
465  }
466 
467  template <typename VECTOR>
468  void setCol(const Index col, const VECTOR& v)
469  {
470  ASSERT_EQUAL_(rows(), static_cast<size_type>(v.size()));
471  for (Index r = 0; r < rows(); r++) (*this)(r, col) = v[r];
472  }
473 
474  /** Appends a new column to the matrix from a vector.
475  * The length of the vector must match the number of rows of the matrix,
476  * unless it is (0,0).
477  * \exception std::exception On size mismatch.
478  * \sa extractCol
479  * \sa appendRow
480  */
481  template <typename VECTOR>
482  void appendCol(const VECTOR& in)
483  {
484  size_t r = m_Rows, c = m_Cols;
485  if (m_Cols == 0 || m_Rows == 0)
486  {
487  ASSERT_(!in.empty());
488  r = in.size();
489  c = 0;
490  }
491  else
492  ASSERT_EQUAL_(static_cast<decltype(m_Rows)>(in.size()), m_Rows);
493  realloc(r, c + 1);
494  for (size_t i = 0; i < m_Rows; i++) (*this)(i, m_Cols - 1) = in[i];
495  }
496 
497  /** Returns a vector containing the matrix's values.
498  */
499  template <typename VECTOR>
500  void asVector(VECTOR& out) const
501  {
502  out.clear();
503  out.reserve(m_Rows * m_Cols);
504  for (const auto& d : m_data) out.push_back(d);
505  }
506 
507  /** Get as an Eigen-compatible Eigen::Map object */
508  template <
509  typename EIGEN_MATRIX = eigen_t,
510  typename EIGEN_MAP = Eigen::Map<
511  EIGEN_MATRIX, MRPT_MAX_ALIGN_BYTES, Eigen::InnerStride<1>>>
512  EIGEN_MAP asEigen()
513  {
514  static_assert(
515  std::is_same_v<EIGEN_MATRIX, eigen_t>,
516  "Please, do not override the default template arguments of this "
517  "method.");
518  return EIGEN_MAP(&m_data[0], m_Rows, m_Cols);
519  }
520  /** \overload (const version) */
521  template <
522  typename EIGEN_MATRIX = eigen_t,
523  typename EIGEN_MAP = Eigen::Map<
524  const EIGEN_MATRIX, MRPT_MAX_ALIGN_BYTES, Eigen::InnerStride<1>>>
525  EIGEN_MAP asEigen() const
526  {
527  static_assert(
528  std::is_same_v<EIGEN_MATRIX, eigen_t>,
529  "Please, do not override the default template arguments of this "
530  "method.");
531  return EIGEN_MAP(&m_data[0], m_Rows, m_Cols);
532  }
533 
536 
537  /** Solves the linear system Ax=b, returns x, with A this **symmetric**
538  * matrix. \sa lu_solve() */
540 
541  /** Solves the linear system Ax=b, returns x, with A this **asymmetric**
542  * matrix. \sa llt_solve() */
544 
545 }; // end of class CMatrixDynamic
546 
547 /** Declares a matrix of booleans (non serializable).
548  * \sa CMatrixDouble, CMatrixFloat, CMatrixB */
550 
551 /** Declares a matrix of float numbers (non serializable).
552  * For a serializable version, use math::CMatrixF
553  * \sa CMatrixDouble, CMatrixF, CMatrixD
554  */
556 
557 /** Declares a matrix of double numbers (non serializable).
558  * For a serializable version, use math::CMatrixD
559  * \sa CMatrixFloat, CMatrixF, CMatrixD
560  */
562 
563 /** Declares a matrix of unsigned ints (non serializable).
564  * \sa CMatrixDouble, CMatrixFloat
565  */
567 
568 #ifdef HAVE_LONG_DOUBLE
569 /** Declares a matrix of "long doubles" (non serializable), or of "doubles" if
570  * the compiler does not support "long double".
571  * \sa CMatrixDouble, CMatrixFloat
572  */
574 #else
575 /** Declares a matrix of "long doubles" (non serializable), or of "doubles" if
576  * the compiler does not support "long double".
577  * \sa CMatrixDouble, CMatrixFloat
578  */
580 #endif
581 } // namespace mrpt::math
582 
583 namespace mrpt::typemeta
584 {
585 // Extensions to mrpt::typemeta::TTypeName for matrices:
586 template <typename T>
588 {
589  static auto get()
590  {
591  return literal("CMatrixDynamic<") + TTypeName<T>::get() + literal(">");
592  }
593 };
594 } // namespace mrpt::typemeta
static constexpr int SizeAtCompileTime
A compile-time fixed-size numeric matrix container.
Definition: CMatrixFixed.h:33
#define MRPT_START
Definition: exceptions.h:241
void resize(size_t row, size_t col)
void setCol(const Index col, const VECTOR &v)
Template for column vectors of dynamic size, compatible with Eigen.
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
#define ASSERT_BELOW_(__A, __B)
Definition: exceptions.h:149
CMatrixDynamic & operator=(const CMatrixDynamic< U > &m)
Assignment operator from another matrix (possibly of a different type)
const_iterator end() const
void swap(CMatrixDynamic< T > &o)
Swap with another matrix very efficiently (just swaps a pointer and two integer values).
static constexpr int ColsAtCompileTime
static constexpr int StorageOrder
void resize(const matrix_size_t &siz, bool zeroNewElements=false)
Resize the matrix.
void setRow(const Index row, const VECTOR &v)
CMatrixDynamic< double > cast_double() const
const_iterator begin() const
vec_t m_data
RowMajor matrix data.
A template to obtain the type of its argument as a string at compile time.
Definition: TTypeName.h:69
CVectorDynamic< Scalar > lu_solve(const CVectorDynamic< Scalar > &b) const
Solves the linear system Ax=b, returns x, with A this asymmetric matrix.
const_iterator cend() const
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
CMatrixDynamic & operator=(V(&theArray)[N])
Assignment operator for initializing from a C array (The matrix must be set to the correct size befor...
void setFromMatrixLike(const MAT &m)
static constexpr size_t small_size
This base provides a set of functions for maths stuff.
constexpr auto literal(const char(&lit)[N_PLUS_1]) -> string_literal< N_PLUS_1 - 1 >
Definition: static_string.h:46
Eigen::Matrix< T, RowsAtCompileTime, ColsAtCompileTime, StorageOrder, RowsAtCompileTime, ColsAtCompileTime > eigen_t
static constexpr int RowsAtCompileTime
void conservativeResize(size_t row, size_t col)
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
Definition: exceptions.h:137
const GLubyte * c
Definition: glext.h:6406
const CMatrixDynamic & derived() const
CMatrixDynamic(const CMatrixDynamic &m, const size_t cropRowCount, const size_t cropColCount)
Copy constructor & crop from another matrix.
CMatrixDynamic & derived()
typename vec_t::const_iterator const_iterator
void appendCol(const VECTOR &in)
Appends a new column to the matrix from a vector.
GLubyte GLubyte b
Definition: glext.h:6372
CMatrixDynamic & operator=(const CMatrixDynamic< T > &m)=default
CMatrixDynamic & operator=(const CMatrixFixed< T, ROWS, COLS > &m)
Assignment from a fixed matrix.
const T & operator[](size_t ith) const
Subscript operator to get/set an individual element from a row or column matrix.
KFTYPE value_type
The type of the matrix elements.
void asVector(VECTOR &out) const
Returns a vector containing the matrix&#39;s values.
size_type rows() const
Number of rows in the matrix.
CMatrixDynamic(const CMatrixDynamic &m)
Constructors.
size_type cols() const
Number of columns in the matrix.
_W64 int ptrdiff_t
Definition: glew.h:136
T & operator[](size_t ith)
Subscript operator to get/set an individual element from a row or column matrix.
CMatrixDynamic(const Eigen::MatrixBase< Derived > &m)
Convert from Eigen matrix.
CMatrixDynamic(const CMatrixDynamic< U > &m)
Copy (casting from if needed) from another matrix.
CMatrixDynamic(size_t row, size_t col, const V &theVector)
Constructor from a given size and a STL container (std::vector, std::list,...) with the initial value...
EIGEN_MAP asEigen() const
Base CRTP class for all MRPT matrices.
Definition: MatrixBase.h:23
const GLdouble * v
Definition: glext.h:3684
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLdouble GLdouble GLdouble r
Definition: glext.h:3711
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
matrix_size_t size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
GLenum GLenum GLvoid * row
Definition: glext.h:3580
void setSize(size_t row, size_t col, bool zeroNewElements=false)
Changes the size of matrix, maintaining the previous contents.
#define MRPT_END
Definition: exceptions.h:245
virtual ~CMatrixDynamic()=default
GLuint in
Definition: glext.h:7391
void resize(size_t vectorLen)
Resizes as a Nx1 vector.
CMatrixDynamic(const Eigen::Product< _Lhs, _Rhs, Option > &p)
Convert from Eigen product.
CMatrixDynamic & operator=(const Eigen::MatrixBase< Derived > &m)
Assignment from an Eigen matrix.
typename vec_t::iterator iterator
CVectorDynamic< Scalar > llt_solve(const CVectorDynamic< Scalar > &b) const
Solves the linear system Ax=b, returns x, with A this symmetric matrix.
CMatrixDynamic< float > cast_float() const
CMatrixDynamic(size_t row, size_t col, V(&theArray)[N])
Constructor from a given size and a C array.
void realloc(size_t row, size_t col, bool newElementsToZero=false)
Internal use only: It reallocs the memory for the 2D matrix, maintaining the previous contents if pos...
CMatrixDynamic(const CMatrixFixed< T, ROWS, COLS > &o)
Constructor from fixed-size matrix:
const T & operator()(size_t row, size_t col) const
Subscript operator to get individual elements.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:69
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
CMatrixDynamic(const Eigen::CwiseBinaryOp< Op, Lhs, Rhs > &p)
Convert from Eigen binary op.
const_iterator cbegin() const
This template class provides the basic functionality for a general 2D any-size, resizable container o...
GLfloat GLfloat p
Definition: glext.h:6398
Auxiliary class used in CMatrixDynamic:size(), CMatrixDynamic::resize(), CMatrixFixed::size(), CMatrixFixed::resize(), to mimic the behavior of STL-containers.
Definition: matrix_size_t.h:20
static constexpr int is_mrpt_type
T & operator()(size_t row, size_t col)
Subscript operator to get/set individual elements.
static constexpr auto get()
Definition: TTypeName.h:71
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
Definition: os.cpp:358
CMatrixDynamic(size_t row=0, size_t col=0)
void appendRow(const VECTOR &in)
Appends a new row to the MxN matrix from a 1xN vector.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019