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-2020, 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;
60  using difference_type = std::ptrdiff_t;
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(m_Rows * m_Cols);
96  newData.fill(typename decltype(m_data)::value_type());
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  std::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++)
258  (*this)(r, c) = static_cast<T>(m(r, c));
259  MRPT_END
260  }
261 
262  CMatrixDynamic& operator=(const CMatrixDynamic<T>& m) = default;
263 
264  /** Assignment operator from another matrix (possibly of a different type)
265  */
266  template <typename U>
268  {
269  MRPT_START
271  return *this;
272  MRPT_END
273  }
274 
275  /** Assignment from an Eigen matrix */
276  template <class Derived>
278  {
279  MRPT_START
281  return *this;
282  MRPT_END
283  }
284  /** Assignment from a fixed matrix */
285  template <std::size_t ROWS, std::size_t COLS>
287  {
288  MRPT_START
290  return *this;
291  MRPT_END
292  }
293 
294  /** Assignment operator for initializing from a C array (The matrix must be
295  *set to the correct size before invoking this asignament)
296  * \code
297  * CMatrixDouble M(3,2);
298  * const double numbers[] = {
299  * 1,2,3,
300  * 4,5,6 };
301  * M = numbers;
302  * \endcode
303  * Refer also to the constructor with initialization data
304  *CMatrixDynamic::CMatrixDynamic
305  */
306  template <typename V, size_t N>
307  CMatrixDynamic& operator=(V (&theArray)[N])
308  {
309  static_assert(N != 0, "Empty array!");
310  if (m_Rows * m_Cols != N)
311  {
313  "Mismatch between matrix size %lu x %lu and array of "
314  "length %lu",
315  m_Rows, m_Cols, N));
316  }
317  size_t idx = 0;
318  for (size_t i = 0; i < m_Rows; i++)
319  for (size_t j = 0; j < m_Cols; j++)
320  (*this)(i, j) = static_cast<T>(theArray[idx++]);
321  return *this;
322  }
323 
324  /** Move ctor */
325  CMatrixDynamic(CMatrixDynamic&& m) { (*this) = std::move(m); }
326 
327  /** Move operator */
329  {
330  m_data = std::move(m.m_data);
331  m_Cols = m.m_Cols;
332  m_Rows = m.m_Rows;
333  return *this;
334  }
335 
336  /** Number of rows in the matrix \sa rows() */
337  inline size_type rows() const { return m_Rows; }
338 
339  /** Number of columns in the matrix \sa rows() */
340  inline size_type cols() const { return m_Cols; }
341 
342  /** Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x)) */
343  inline matrix_size_t size() const
344  {
345  matrix_size_t dims;
346  dims[0] = m_Rows;
347  dims[1] = m_Cols;
348  return dims;
349  }
350 
351  /** Changes the size of matrix, maintaining the previous contents. */
352  void setSize(size_t row, size_t col, bool zeroNewElements = false)
353  {
354  realloc(row, col, zeroNewElements);
355  }
356  void resize(size_t row, size_t col) { setSize(row, col); }
357 
358  /** Resizes as a Nx1 vector */
359  void resize(size_t vectorLen) { setSize(vectorLen, 1); }
360 
361  /** Resize the matrix */
362  inline void resize(const matrix_size_t& siz, bool zeroNewElements = false)
363  {
364  setSize(siz[0], siz[1], zeroNewElements);
365  }
366 
367  // These ones are to make template code compatible with Eigen & mrpt:
368  CMatrixDynamic& derived() { return *this; }
369  const CMatrixDynamic& derived() const { return *this; }
370  void conservativeResize(size_t row, size_t col) { setSize(row, col); }
371 
372  /** Return raw pointer to row-major data buffer. All matrix cells can be
373  * assumed to be stored contiguously in memory, i.e. row stride = column
374  * count. */
375  const T* data() const
376  {
377  ASSERT_(!m_data.empty());
378  return &m_data[0];
379  }
380  /// \overload
381  T* data()
382  {
383  ASSERT_(!m_data.empty());
384  return &m_data[0];
385  }
386 
387  /** Subscript operator to get/set individual elements
388  */
389  inline T& operator()(size_t row, size_t col)
390  {
391 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
392  if (row >= m_Rows || col >= m_Cols)
394  "Indexes (%lu,%lu) out of range. Matrix is %lux%lu",
395  static_cast<unsigned long>(row),
396  static_cast<unsigned long>(col),
397  static_cast<unsigned long>(m_Rows),
398  static_cast<unsigned long>(m_Cols)));
399 #endif
400  return m_data[row * m_Cols + col];
401  }
402 
403  /** Subscript operator to get individual elements
404  */
405  inline const T& operator()(size_t row, size_t col) const
406  {
407 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
408  if (row >= m_Rows || col >= m_Cols)
410  "Indexes (%lu,%lu) out of range. Matrix is %lux%lu",
411  static_cast<unsigned long>(row),
412  static_cast<unsigned long>(col),
413  static_cast<unsigned long>(m_Rows),
414  static_cast<unsigned long>(m_Cols)));
415 #endif
416  return m_data[row * m_Cols + col];
417  }
418 
419  /** Subscript operator to get/set an individual element from a row or column
420  * matrix.
421  * \exception std::exception If the object is not a column or row matrix.
422  */
423  inline T& operator[](size_t ith)
424  {
425 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
426  ASSERT_(m_Rows == 1 || m_Cols == 1);
427 #endif
428  if (m_Rows == 1)
429  {
430 // A row matrix:
431 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
432  if (ith >= m_Cols)
434  "Index %u out of range!", static_cast<unsigned>(ith));
435 #endif
436  }
437  else
438  {
439 // A columns matrix:
440 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
441  if (ith >= m_Rows)
443  "Index %u out of range!", static_cast<unsigned>(ith));
444 #endif
445  }
446  return m_data[ith];
447  }
448 
449  /** Subscript operator to get/set an individual element from a row or column
450  * matrix. For non-vectors (NxM matrices), it returns the i-th matrix
451  * element, in RowMajor order.
452  * \exception std::exception If the object is not a column or row matrix.
453  */
454  inline const T& operator[](size_t ith) const
455  {
456 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES)
457  ASSERT_BELOW_(ith, m_Rows * m_Cols);
458 #endif
459  return m_data[ith];
460  }
461 
462  /** Appends a new row to the MxN matrix from a 1xN vector.
463  * The lenght of the vector must match the width of the matrix, unless
464  * it's empty: in that case the matrix is resized to 1xN.
465  * \code
466  * CMatrixDouble M(0,0);
467  * CVectorDouble v(7),w(7);
468  * // ...
469  * M.appendRow(v);
470  * M.appendRow(w);
471  * \endcode
472  * \exception std::exception On incorrect vector length.
473  * \sa extractRow
474  * \sa appendCol
475  */
476  template <typename VECTOR>
477  void appendRow(const VECTOR& in)
478  {
479  if (m_Cols == 0 || m_Rows == 0)
480  ASSERT_(!in.empty());
481  else
482  ASSERT_(in.size() == m_Cols);
483  const auto row = m_Rows;
484  realloc(row + 1, m_Cols = in.size());
485  for (size_t i = 0; i < m_Cols; i++) (*this)(row, i) = in[i];
486  }
487 
488  template <typename VECTOR>
489  void setRow(const Index row, const VECTOR& v)
490  {
491  ASSERT_EQUAL_(cols(), static_cast<size_type>(v.size()));
492  for (Index c = 0; c < cols(); c++) (*this)(row, c) = v[c];
493  }
494 
495  template <typename VECTOR>
496  void setCol(const Index col, const VECTOR& v)
497  {
498  ASSERT_EQUAL_(rows(), static_cast<size_type>(v.size()));
499  for (Index r = 0; r < rows(); r++) (*this)(r, col) = v[r];
500  }
501 
502  /** Appends a new column to the matrix from a vector.
503  * The length of the vector must match the number of rows of the matrix,
504  * unless it is (0,0).
505  * \exception std::exception On size mismatch.
506  * \sa extractCol
507  * \sa appendRow
508  */
509  template <typename VECTOR>
510  void appendCol(const VECTOR& in)
511  {
512  size_t r = m_Rows, c = m_Cols;
513  if (m_Cols == 0 || m_Rows == 0)
514  {
515  ASSERT_(!in.empty());
516  r = in.size();
517  c = 0;
518  }
519  else
520  ASSERT_EQUAL_(static_cast<decltype(m_Rows)>(in.size()), m_Rows);
521  realloc(r, c + 1);
522  for (size_t i = 0; i < m_Rows; i++) (*this)(i, m_Cols - 1) = in[i];
523  }
524 
525  /** Returns a vector containing the matrix's values.
526  */
527  template <typename VECTOR>
528  void asVector(VECTOR& out) const
529  {
530  out.clear();
531  out.reserve(m_Rows * m_Cols);
532  for (const auto& d : m_data) out.push_back(d);
533  }
534 
535  /** Get as an Eigen-compatible Eigen::Map object */
536  template <
537  typename EIGEN_MATRIX = eigen_t,
538  typename EIGEN_MAP = Eigen::Map<
539  EIGEN_MATRIX, MRPT_MAX_ALIGN_BYTES, Eigen::InnerStride<1>>>
540  EIGEN_MAP asEigen()
541  {
542  static_assert(
543  std::is_same_v<EIGEN_MATRIX, eigen_t>,
544  "Please, do not override the default template arguments of this "
545  "method.");
546  return EIGEN_MAP(&m_data[0], m_Rows, m_Cols);
547  }
548  /** \overload (const version) */
549  template <
550  typename EIGEN_MATRIX = eigen_t,
551  typename EIGEN_MAP = Eigen::Map<
552  const EIGEN_MATRIX, MRPT_MAX_ALIGN_BYTES, Eigen::InnerStride<1>>>
553  EIGEN_MAP asEigen() const
554  {
555  static_assert(
556  std::is_same_v<EIGEN_MATRIX, eigen_t>,
557  "Please, do not override the default template arguments of this "
558  "method.");
559  return EIGEN_MAP(&m_data[0], m_Rows, m_Cols);
560  }
561 
564 
565  /** Solves the linear system Ax=b, returns x, with A this **symmetric**
566  * matrix. \sa lu_solve() */
568 
569  /** Solves the linear system Ax=b, returns x, with A this **asymmetric**
570  * matrix. \sa llt_solve() */
572 
573 }; // end of class CMatrixDynamic
574 
575 /** Declares a matrix of booleans (non serializable).
576  * \sa CMatrixDouble, CMatrixFloat, CMatrixB */
578 
579 /** Declares a matrix of float numbers (non serializable).
580  * For a serializable version, use math::CMatrixF
581  * \sa CMatrixDouble, CMatrixF, CMatrixD
582  */
584 
585 /** Declares a matrix of double numbers (non serializable).
586  * For a serializable version, use math::CMatrixD
587  * \sa CMatrixFloat, CMatrixF, CMatrixD
588  */
590 
591 /** Declares a matrix of unsigned ints (non serializable).
592  * \sa CMatrixDouble, CMatrixFloat
593  */
595 
596 /** matrix of uint8_t (non serializable). \sa CMatrixDouble */
598 
599 /** matrix of uint16_t (non serializable). \sa CMatrixDouble */
601 
602 #ifdef HAVE_LONG_DOUBLE
603 /** Declares a matrix of "long doubles" (non serializable), or of "doubles" if
604  * the compiler does not support "long double".
605  * \sa CMatrixDouble, CMatrixFloat
606  */
608 #else
609 /** Declares a matrix of "long doubles" (non serializable), or of "doubles" if
610  * the compiler does not support "long double".
611  * \sa CMatrixDouble, CMatrixFloat
612  */
614 #endif
615 } // namespace mrpt::math
616 
617 namespace mrpt::typemeta
618 {
619 // Extensions to mrpt::typemeta::TTypeName for matrices:
620 template <typename T>
622 {
623  static auto get()
624  {
625  return literal("CMatrixDynamic<") + TTypeName<T>::get() + literal(">");
626  }
627 };
628 } // 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)
Trivially copiable underlying data for TPoint3D 1-byte memory packed, no padding].
Definition: TPoint3D.h:26
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
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
const T * data() const
Return raw pointer to row-major data buffer.
#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)
CMatrixDynamic & operator=(CMatrixDynamic &&m)
Move operator.
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
Definition: exceptions.h:137
const CMatrixDynamic & derived() const
CMatrixDynamic(const CMatrixDynamic &m, const size_t cropRowCount, const size_t cropColCount)
Copy constructor & crop from another matrix.
CMatrixDynamic & derived()
void appendCol(const VECTOR &in)
Appends a new column to the matrix from a vector.
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.
T 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.
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
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::vision::TStereoCalibResults out
matrix_size_t size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
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
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.
CVectorDynamic< Scalar > llt_solve(const CVectorDynamic< Scalar > &b) const
Solves the linear system Ax=b, returns x, with A this symmetric matrix.
CMatrixDynamic(CMatrixDynamic &&m)
Move ctor.
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...
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".
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: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020