MRPT  1.9.9
eigen_plugins.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 
10 // -------------------------------------------------------------------------
11 // Note: This file will be included within the body of Eigen::MatrixBase
12 // -------------------------------------------------------------------------
13 public:
14 /** @name MRPT plugin: Types
15  * @{ */
16 // size is constant
17 enum
18 {
19  static_size = RowsAtCompileTime * ColsAtCompileTime
20 };
21 /** @} */
22 
23 /** @name MRPT plugin: Basic iterators. These iterators are intended for 1D
24  * matrices only, i.e. column or row vectors.
25  * @{ */
26 using iterator = Scalar*;
27 using const_iterator = const Scalar*;
28 
29 EIGEN_STRONG_INLINE iterator begin() { return derived().data(); }
30 EIGEN_STRONG_INLINE iterator end()
31 {
32  return (&(derived().data()[size() - 1])) + 1;
33 }
34 EIGEN_STRONG_INLINE const_iterator begin() const { return derived().data(); }
35 EIGEN_STRONG_INLINE const_iterator end() const
36 {
37  return (&(derived().data()[size() - 1])) + 1;
38 }
39 
40 /** @} */
41 
42 /** @name MRPT plugin: Set/get/load/save and other miscelaneous methods
43  * @{ */
44 
45 /*! Fill all the elements with a given value */
46 EIGEN_STRONG_INLINE void fill(const Scalar v) { derived().setConstant(v); }
47 /*! Fill all the elements with a given value */
48 EIGEN_STRONG_INLINE void assign(const Scalar v) { derived().setConstant(v); }
49 /*! Resize to N and set all the elements to a given value */
50 EIGEN_STRONG_INLINE void assign(size_t N, const Scalar v)
51 {
52  derived().resize(N);
53  derived().setConstant(v);
54 }
55 
56 /** Make the matrix an identity matrix (the diagonal values can be 1.0 or any
57  * other value) */
58 EIGEN_STRONG_INLINE void unit(const size_t nRows, const Scalar diag_vals)
59 {
60  if (diag_vals == 1)
61  derived().setIdentity(nRows, nRows);
62  else
63  {
64  derived().setZero(nRows, nRows);
65  derived().diagonal().setConstant(diag_vals);
66  }
67 }
68 
69 /** Make the matrix an identity matrix */
70 EIGEN_STRONG_INLINE void unit() { derived().setIdentity(); }
71 /** Make the matrix an identity matrix */
72 EIGEN_STRONG_INLINE void eye() { derived().setIdentity(); }
73 /** Set all elements to zero */
74 EIGEN_STRONG_INLINE void zeros() { derived().setZero(); }
75 /** Resize and set all elements to zero */
76 EIGEN_STRONG_INLINE void zeros(const size_t row, const size_t col)
77 {
78  derived().setZero(row, col);
79 }
80 
81 /** Resize matrix and set all elements to one */
82 EIGEN_STRONG_INLINE void ones(const size_t row, const size_t col)
83 {
84  derived().setOnes(row, col);
85 }
86 /** Set all elements to one */
87 EIGEN_STRONG_INLINE void ones() { derived().setOnes(); }
88 /** Fast but unsafe method to obtain a pointer to a given row of the matrix (Use
89  * only in time critical applications)
90  * VERY IMPORTANT WARNING: You must be aware of the memory layout, either
91  * Column or Row-major ordering.
92  */
93 EIGEN_STRONG_INLINE Scalar* get_unsafe_row(size_t row)
94 {
95  return &derived().coeffRef(row, 0);
96 }
97 EIGEN_STRONG_INLINE const Scalar* get_unsafe_row(size_t row) const
98 {
99  return &derived().coeff(row, 0);
100 }
101 
102 /** Read-only access to one element (Use with caution, bounds are not checked!)
103  */
104 EIGEN_STRONG_INLINE Scalar get_unsafe(const size_t row, const size_t col) const
105 {
106 #ifdef _DEBUG
107  return derived()(row, col);
108 #else
109  return derived().coeff(row, col);
110 #endif
111 }
112 /** Reference access to one element (Use with caution, bounds are not checked!)
113  */
114 EIGEN_STRONG_INLINE Scalar& get_unsafe(const size_t row, const size_t col)
115 { //-V659
116 #ifdef _DEBUG
117  return derived()(row, col);
118 #else
119  return derived().coeffRef(row, col);
120 #endif
121 }
122 /** Sets an element (Use with caution, bounds are not checked!) */
123 EIGEN_STRONG_INLINE void set_unsafe(
124  const size_t row, const size_t col, const Scalar val)
125 {
126 #ifdef _DEBUG
127  derived()(row, col) = val;
128 #else
129  derived().coeffRef(row, col) = val;
130 #endif
131 }
132 
133 /** Insert an element at the end of the container (for 1D vectors/arrays) */
134 EIGEN_STRONG_INLINE void push_back(Scalar val)
135 {
136  const Index N = size();
137  derived().conservativeResize(N + 1);
138  coeffRef(N) = val;
139 }
140 
141 EIGEN_STRONG_INLINE bool isSquare() const { return cols() == rows(); }
142 EIGEN_STRONG_INLINE bool isSingular(const Scalar absThreshold = 0) const
143 {
144  return std::abs(derived().determinant()) < absThreshold;
145 }
146 
147 /** Read a matrix from a string in Matlab-like format, for example "[1 0 2; 0 4
148  * -1]"
149  * The string must start with '[' and end with ']'. Rows are separated by
150  * semicolons ';' and
151  * columns in each row by one or more whitespaces ' ', commas ',' or tabs
152  * '\t'.
153  *
154  * This format is also used for CConfigFile::read_matrix.
155  *
156  * This template method can be instantiated for matrices of the types: int,
157  * long, unsinged int, unsigned long, float, double, long double
158  *
159  * \return true on success. false if the string is malformed, and then the
160  * matrix will be resized to 0x0.
161  * \sa inMatlabFormat, CConfigFile::read_matrix
162  */
164  const std::string& s, std::ostream* dump_errors_here = nullptr);
165 // Method implemented in eigen_plugins_impl.h
166 
167 /** Dump matrix in matlab format.
168  * This template method can be instantiated for matrices of the types: int,
169  * long, unsinged int, unsigned long, float, double, long double
170  * \sa fromMatlabStringFormat
171  */
172 std::string inMatlabFormat(const size_t decimal_digits = 6) const;
173 // Method implemented in eigen_plugins_impl.h
174 
175 /** Save matrix to a text file, compatible with MATLAB text format (see also the
176  * methods of matrix classes themselves).
177  * \param theMatrix It can be a CMatrixTemplate or a CMatrixFixedNumeric.
178  * \param file The target filename.
179  * \param fileFormat See TMatrixTextFileFormat. The format of the numbers in
180  * the text file.
181  * \param appendMRPTHeader Insert this header to the file "% File generated
182  * by MRPT. Load with MATLAB with: VAR=load(FILENAME);"
183  * \param userHeader Additional text to be written at the head of the file.
184  * Typically MALAB comments "% This file blah blah". Final end-of-line is not
185  * needed.
186  * \sa loadFromTextFile, CMatrixTemplate::inMatlabFormat, SAVE_MATRIX
187  */
188 void saveToTextFile(
189  const std::string& file,
192  bool appendMRPTHeader = false,
193  const std::string& userHeader = std::string()) const;
194 // Method implemented in eigen_plugins_impl.h
195 
196 /** Load matrix from a text file, compatible with MATLAB text format.
197  * Lines starting with '%' or '#' are interpreted as comments and ignored.
198  * \sa saveToTextFile, fromMatlabStringFormat
199  */
200 void loadFromTextFile(const std::string& file);
201 // Method implemented in eigen_plugins_impl.h
202 
203 //! \overload
204 void loadFromTextFile(std::istream& _input_text_stream);
205 // Method implemented in eigen_plugins_impl.h
206 
207 EIGEN_STRONG_INLINE void multiplyColumnByScalar(size_t c, Scalar s)
208 {
209  derived().col(c) *= s;
210 }
211 EIGEN_STRONG_INLINE void multiplyRowByScalar(size_t r, Scalar s)
212 {
213  derived().row(r) *= s;
214 }
215 
216 EIGEN_STRONG_INLINE void swapCols(size_t i1, size_t i2)
217 {
218  derived().col(i1).swap(derived().col(i2));
219 }
220 EIGEN_STRONG_INLINE void swapRows(size_t i1, size_t i2)
221 {
222  derived().row(i1).swap(derived().row(i2));
223 }
224 
225 EIGEN_STRONG_INLINE size_t countNonZero() const
226 {
227  return ((*static_cast<const Derived*>(this)) != 0).count();
228 }
229 
230 /** [VECTORS OR MATRICES] Finds the maximum value
231  * \exception std::exception On an empty input container
232  */
233 EIGEN_STRONG_INLINE Scalar maximum() const
234 {
235  if (size() == 0) throw std::runtime_error("maximum: container is empty");
236  return derived().maxCoeff();
237 }
238 
239 /** [VECTORS OR MATRICES] Finds the minimum value
240  * \sa maximum, minimum_maximum
241  * \exception std::exception On an empty input container */
242 EIGEN_STRONG_INLINE Scalar minimum() const
243 {
244  if (size() == 0) throw std::runtime_error("minimum: container is empty");
245  return derived().minCoeff();
246 }
247 
248 /** [VECTORS OR MATRICES] Compute the minimum and maximum of a container at once
249  * \sa maximum, minimum
250  * \exception std::exception On an empty input container */
251 EIGEN_STRONG_INLINE void minimum_maximum(Scalar& out_min, Scalar& out_max) const
252 {
253  out_min = minimum();
254  out_max = maximum();
255 }
256 
257 /** [VECTORS ONLY] Finds the maximum value (and the corresponding zero-based
258  * index) from a given container.
259  * \exception std::exception On an empty input vector
260  */
261 EIGEN_STRONG_INLINE Scalar maximum(size_t* maxIndex) const
262 {
263  if (size() == 0) throw std::runtime_error("maximum: container is empty");
264  Index idx;
265  const Scalar m = derived().maxCoeff(&idx);
266  if (maxIndex) *maxIndex = idx;
267  return m;
268 }
269 
270 /** [VECTORS OR MATRICES] Finds the maximum value (and the corresponding
271  * zero-based index) from a given container.
272  * \exception std::exception On an empty input vector
273  */
274 void find_index_max_value(size_t& u, size_t& v, Scalar& valMax) const
275 {
276  if (cols() == 0 || rows() == 0)
277  throw std::runtime_error("find_index_max_value: container is empty");
278  Index idx1, idx2;
279  valMax = derived().maxCoeff(&idx1, &idx2);
280  u = idx1;
281  v = idx2;
282 }
283 
284 /** [VECTORS ONLY] Finds the minimum value (and the corresponding zero-based
285  * index) from a given container.
286  * \sa maximum, minimum_maximum
287  * \exception std::exception On an empty input vector */
288 EIGEN_STRONG_INLINE Scalar minimum(size_t* minIndex) const
289 {
290  if (size() == 0) throw std::runtime_error("minimum: container is empty");
291  Index idx;
292  const Scalar m = derived().minCoeff(&idx);
293  if (minIndex) *minIndex = idx;
294  return m;
295 }
296 
297 /** [VECTORS ONLY] Compute the minimum and maximum of a container at once
298  * \sa maximum, minimum
299  * \exception std::exception On an empty input vector */
300 EIGEN_STRONG_INLINE void minimum_maximum(
301  Scalar& out_min, Scalar& out_max, size_t* minIndex, size_t* maxIndex) const
302 {
303  out_min = minimum(minIndex);
304  out_max = maximum(maxIndex);
305 }
306 
307 /** Compute the norm-infinite of a vector ($f[ ||\mathbf{v}||_\infnty $f]), ie
308  * the maximum absolute value of the elements. */
309 EIGEN_STRONG_INLINE Scalar norm_inf() const
310 {
311  return lpNorm<Eigen::Infinity>();
312 }
313 
314 /** Compute the square norm of a vector/array/matrix (the Euclidean distance to
315  * the origin, taking all the elements as a single vector). \sa norm */
316 EIGEN_STRONG_INLINE Scalar squareNorm() const { return squaredNorm(); }
317 /*! Sum all the elements, returning a value of the same type than the container
318  */
319 EIGEN_STRONG_INLINE Scalar sumAll() const { return derived().sum(); }
320 /** Computes the laplacian of this square graph weight matrix.
321  * The laplacian matrix is L = D - W, with D a diagonal matrix with the degree
322  * of each node, W the
323  */
324 template <typename OtherDerived>
325 EIGEN_STRONG_INLINE void laplacian(Eigen::MatrixBase<OtherDerived>& ret) const
326 {
327  if (rows() != cols())
328  throw std::runtime_error("laplacian: Defined for square matrixes only");
329  const Index N = rows();
330  ret = -(*this);
331  for (Index i = 0; i < N; i++)
332  {
333  Scalar deg = 0;
334  for (Index j = 0; j < N; j++) deg += derived().coeff(j, i);
335  ret.coeffRef(i, i) += deg;
336  }
337 }
338 
339 /** Changes the size of matrix, maintaining its previous content as possible and
340  * padding with zeros where applicable.
341  * **WARNING**: MRPT's add-on method \a setSize() pads with zeros, while
342  * Eigen's \a resize() does NOT (new elements are undefined).
343  */
344 EIGEN_STRONG_INLINE void setSize(size_t row, size_t col)
345 {
346 #ifdef _DEBUG
347  if ((Derived::RowsAtCompileTime != Eigen::Dynamic &&
348  Derived::RowsAtCompileTime != int(row)) ||
349  (Derived::ColsAtCompileTime != Eigen::Dynamic &&
350  Derived::ColsAtCompileTime != int(col)))
351  {
352  std::stringstream ss;
353  ss << "setSize: Trying to change a fixed sized matrix from " << rows()
354  << "x" << cols() << " to " << row << "x" << col;
355  throw std::runtime_error(ss.str());
356  }
357 #endif
358  const Index oldCols = cols();
359  const Index oldRows = rows();
360  const int nNewCols = int(col) - int(cols());
361  const int nNewRows = int(row) - int(rows());
364  SizeAtCompileTime>::internal_resize(*this, row, col);
365  if (nNewCols > 0) derived().block(0, oldCols, row, nNewCols).setZero();
366  if (nNewRows > 0) derived().block(oldRows, 0, nNewRows, col).setZero();
367 }
368 
369 /** Efficiently computes only the biggest eigenvector of the matrix using the
370  * Power Method, and returns it in the passed vector "x". */
371 template <class OUTVECT>
373  OUTVECT& x, Scalar resolution = Scalar(0.01), size_t maxIterations = 6,
374  int* out_Iterations = nullptr,
375  float* out_estimatedResolution = nullptr) const
376 {
377  // Apply the iterative Power Method:
378  size_t iter = 0;
379  const Index n = rows();
380  x.resize(n);
381  x.setConstant(1); // Initially, set to all ones, for example...
382  Scalar dif;
383  do // Iterative loop:
384  {
385  Eigen::Matrix<Scalar, Derived::RowsAtCompileTime, 1> xx = (*this) * x;
386  xx *= Scalar(1.0 / xx.norm());
387  dif = (x - xx)
388  .array()
389  .abs()
390  .sum(); // Compute diference between iterations:
391  x = xx; // Set as current estimation:
392  iter++; // Iteration counter:
393  } while (iter < maxIterations && dif > resolution);
394  if (out_Iterations) *out_Iterations = static_cast<int>(iter);
395  if (out_estimatedResolution) *out_estimatedResolution = dif;
396 }
397 
398 /** Combined matrix power and assignment operator */
399 MatrixBase<Derived>& operator^=(const unsigned int pow)
400 {
401  if (pow == 0)
402  derived().setIdentity();
403  else
404  for (unsigned int i = 1; i < pow; i++) derived() *= derived();
405  return *this;
406 }
407 
408 /** Scalar power of all elements to a given power, this is diferent of ^
409  * operator. */
410 EIGEN_STRONG_INLINE void scalarPow(const Scalar s) { (*this) = array().pow(s); }
411 /** Checks for matrix type */
412 EIGEN_STRONG_INLINE bool isDiagonal() const
413 {
414  for (Index c = 0; c < cols(); c++)
415  for (Index r = 0; r < rows(); r++)
416  if (r != c && coeff(r, c) != 0) return false;
417  return true;
418 }
419 
420 /** Finds the maximum value in the diagonal of the matrix. */
421 EIGEN_STRONG_INLINE Scalar maximumDiagonal() const
422 {
423  return diagonal().maxCoeff();
424 }
425 
426 /** Computes the mean of the entire matrix
427  * \sa meanAndStdAll */
428 EIGEN_STRONG_INLINE double mean() const
429 {
430  if (size() == 0) throw std::runtime_error("mean: Empty container.");
431  return derived().sum() / static_cast<double>(size());
432 }
433 
434 /** Computes a row with the mean values of each column in the matrix and the
435  * associated vector with the standard deviation of each column.
436  * \sa mean,meanAndStdAll \exception std::exception If the matrix/vector is
437  * empty.
438  * \param unbiased_variance Standard deviation is sum(vals-mean)/K, with K=N-1
439  * or N for unbiased_variance=true or false, respectively.
440  */
441 template <class VEC>
443  VEC& outMeanVector, VEC& outStdVector,
444  const bool unbiased_variance = true) const
445 {
446  const size_t N = rows();
447  if (N == 0) throw std::runtime_error("meanAndStd: Empty container.");
448  const double N_inv = 1.0 / N;
449  const double N_ =
450  unbiased_variance ? (N > 1 ? 1.0 / (N - 1) : 1.0) : 1.0 / N;
451  outMeanVector.resize(cols());
452  outStdVector.resize(cols());
453  for (decltype(cols()) i = 0; i < cols(); i++)
454  {
455  outMeanVector[i] = this->col(i).array().sum() * N_inv;
456  outStdVector[i] = std::sqrt(
457  (this->col(i).array() - outMeanVector[i]).square().sum() * N_);
458  }
459 }
460 
461 /** Computes the mean and standard deviation of all the elements in the matrix
462  * as a whole.
463  * \sa mean,meanAndStd \exception std::exception If the matrix/vector is
464  * empty.
465  * \param unbiased_variance Standard deviation is sum(vals-mean)/K, with K=N-1
466  * or N for unbiased_variance=true or false, respectively.
467  */
469  double& outMean, double& outStd, const bool unbiased_variance = true) const
470 {
471  const size_t N = size();
472  if (N == 0) throw std::runtime_error("meanAndStdAll: Empty container.");
473  const double N_ =
474  unbiased_variance ? (N > 1 ? 1.0 / (N - 1) : 1.0) : 1.0 / N;
475  outMean = derived().array().sum() / static_cast<double>(size());
476  outStd = std::sqrt((this->array() - outMean).square().sum() * N_);
477 }
478 
479 /** Insert matrix "m" into this matrix at indices (r,c), that is,
480  * (*this)(r,c)=m(0,0) and so on */
481 template <typename MAT>
482 EIGEN_STRONG_INLINE void insertMatrix(size_t r, size_t c, const MAT& m)
483 {
484  derived().block(r, c, m.rows(), m.cols()) = m;
485 }
486 
487 template <typename MAT>
488 EIGEN_STRONG_INLINE void insertMatrixTranspose(size_t r, size_t c, const MAT& m)
489 {
490  derived().block(r, c, m.cols(), m.rows()) = m.adjoint();
491 }
492 
493 template <typename MAT>
494 EIGEN_STRONG_INLINE void insertRow(size_t nRow, const MAT& aRow)
495 {
496  this->row(nRow) = aRow;
497 }
498 template <typename MAT>
499 EIGEN_STRONG_INLINE void insertCol(size_t nCol, const MAT& aCol)
500 {
501  this->col(nCol) = aCol;
502 }
503 
504 template <typename R>
505 void insertRow(size_t nRow, const std::vector<R>& aRow)
506 {
507  if (static_cast<Index>(aRow.size()) != cols())
508  throw std::runtime_error(
509  "insertRow: Row size doesn't fit the size of this matrix.");
510  for (decltype(cols()) j = 0; j < cols(); j++) coeffRef(nRow, j) = aRow[j];
511 }
512 template <typename R>
513 void insertCol(size_t nCol, const std::vector<R>& aCol)
514 {
515  if (static_cast<Index>(aCol.size()) != rows())
516  throw std::runtime_error(
517  "insertRow: Row size doesn't fit the size of this matrix.");
518  for (decltype(cols()) j = 0; j < rows(); j++) coeffRef(j, nCol) = aCol[j];
519 }
520 
521 /** Remove columns of the matrix.*/
522 EIGEN_STRONG_INLINE void removeColumns(const std::vector<size_t>& idxsToRemove)
523 {
524  std::vector<size_t> idxs = idxsToRemove;
525  std::sort(idxs.begin(), idxs.end());
526  std::vector<size_t>::iterator itEnd = std::unique(idxs.begin(), idxs.end());
527  idxs.resize(itEnd - idxs.begin());
528 
529  unsafeRemoveColumns(idxs);
530 }
531 
532 /** Remove columns of the matrix. The unsafe version assumes that, the indices
533  * are sorted in ascending order. */
534 EIGEN_STRONG_INLINE void unsafeRemoveColumns(const std::vector<size_t>& idxs)
535 {
536  size_t k = 1;
537  for (std::vector<size_t>::const_reverse_iterator it = idxs.rbegin();
538  it != idxs.rend(); ++it, ++k)
539  {
540  const size_t nC = cols() - *it - k;
541  if (nC > 0)
542  derived().block(0, *it, rows(), nC) =
543  derived().block(0, *it + 1, rows(), nC).eval();
544  }
545  derived().conservativeResize(NoChange, cols() - idxs.size());
546 }
547 
548 /** Remove rows of the matrix. */
549 EIGEN_STRONG_INLINE void removeRows(const std::vector<size_t>& idxsToRemove)
550 {
551  std::vector<size_t> idxs = idxsToRemove;
552  std::sort(idxs.begin(), idxs.end());
553  std::vector<size_t>::iterator itEnd = std::unique(idxs.begin(), idxs.end());
554  idxs.resize(itEnd - idxs.begin());
555 
556  unsafeRemoveRows(idxs);
557 }
558 
559 /** Remove rows of the matrix. The unsafe version assumes that, the indices are
560  * sorted in ascending order. */
561 EIGEN_STRONG_INLINE void unsafeRemoveRows(const std::vector<size_t>& idxs)
562 {
563  size_t k = 1;
564  for (auto it = idxs.rbegin(); it != idxs.rend(); ++it, ++k)
565  {
566  const size_t nR = rows() - *it - k;
567  if (nR > 0)
568  derived().block(*it, 0, nR, cols()) =
569  derived().block(*it + 1, 0, nR, cols()).eval();
570  }
571  derived().conservativeResize(rows() - idxs.size(), NoChange);
572 }
573 
574 /** Transpose */
575 EIGEN_STRONG_INLINE const AdjointReturnType t() const
576 {
577  return derived().adjoint();
578 }
579 
580 EIGEN_STRONG_INLINE PlainObject inv() const
581 {
582  PlainObject outMat = derived().inverse().eval();
583  return outMat;
584 }
585 template <class MATRIX>
586 EIGEN_STRONG_INLINE void inv(MATRIX& outMat) const
587 {
588  outMat = derived().inverse().eval();
589 }
590 template <class MATRIX>
591 EIGEN_STRONG_INLINE void inv_fast(MATRIX& outMat) const
592 {
593  outMat = derived().inverse().eval();
594 }
595 EIGEN_STRONG_INLINE Scalar det() const { return derived().determinant(); }
596 /** @} */ // end miscelaneous
597 
598 /** @name MRPT plugin: Multiply and extra addition functions
599  @{ */
600 
601 EIGEN_STRONG_INLINE bool empty() const
602 {
603  return this->cols() == 0 || this->rows() == 0;
604 }
605 
606 /*! Add c (scalar) times A to this matrix: this += A * c */
607 template <typename OTHERMATRIX>
608 EIGEN_STRONG_INLINE void add_Ac(const OTHERMATRIX& m, const Scalar c)
609 {
610  (*this) += c * m;
611 }
612 /*! Substract c (scalar) times A to this matrix: this -= A * c */
613 template <typename OTHERMATRIX>
614 EIGEN_STRONG_INLINE void substract_Ac(const OTHERMATRIX& m, const Scalar c)
615 {
616  (*this) -= c * m;
617 }
618 
619 /*! Substract A transposed to this matrix: this -= A.adjoint() */
620 template <typename OTHERMATRIX>
621 EIGEN_STRONG_INLINE void substract_At(const OTHERMATRIX& m)
622 {
623  (*this) -= m.adjoint();
624 }
625 
626 /*! Substract n (integer) times A to this matrix: this -= A * n */
627 template <typename OTHERMATRIX>
628 EIGEN_STRONG_INLINE void substract_An(const OTHERMATRIX& m, const size_t n)
629 {
630  this->noalias() -= n * m;
631 }
632 
633 /*! this += A + A<sup>T</sup> */
634 template <typename OTHERMATRIX>
635 EIGEN_STRONG_INLINE void add_AAt(const OTHERMATRIX& A)
636 {
637  this->noalias() += A;
638  this->noalias() += A.adjoint();
639 }
640 
641 /*! this -= A + A<sup>T</sup> */
642 template <typename OTHERMATRIX>
643 EIGEN_STRONG_INLINE void substract_AAt(const OTHERMATRIX& A)
644 {
645  this->noalias() -= A;
646  this->noalias() -= A.adjoint();
647 }
648 
649 template <class MATRIX1, class MATRIX2>
650 EIGEN_STRONG_INLINE void multiply(
651  const MATRIX1& A, const MATRIX2& B) /*!< this = A * B */
652 {
653  (*this) = A * B;
654 }
655 
656 template <class MATRIX1, class MATRIX2>
657 EIGEN_STRONG_INLINE void multiply_AB(
658  const MATRIX1& A, const MATRIX2& B) /*!< this = A * B */
659 {
660  (*this) = A * B;
661 }
662 
663 template <typename MATRIX1, typename MATRIX2>
664 EIGEN_STRONG_INLINE void multiply_AtB(
665  const MATRIX1& A, const MATRIX2& B) /*!< this=A^t * B */
666 {
667  *this = A.adjoint() * B;
668 }
669 
670 /*! Computes the vector vOut = this * vIn, where "vIn" is a column vector of the
671  * appropriate length. */
672 template <typename OTHERVECTOR1, typename OTHERVECTOR2>
673 EIGEN_STRONG_INLINE void multiply_Ab(
674  const OTHERVECTOR1& vIn, OTHERVECTOR2& vOut,
675  bool accumToOutput = false) const
676 {
677  if (accumToOutput)
678  vOut.noalias() += (*this) * vIn;
679  else
680  vOut = (*this) * vIn;
681 }
682 
683 /*! Computes the vector vOut = this<sup>T</sup> * vIn, where "vIn" is a column
684  * vector of the appropriate length. */
685 template <typename OTHERVECTOR1, typename OTHERVECTOR2>
686 EIGEN_STRONG_INLINE void multiply_Atb(
687  const OTHERVECTOR1& vIn, OTHERVECTOR2& vOut,
688  bool accumToOutput = false) const
689 {
690  if (accumToOutput)
691  vOut.noalias() += this->adjoint() * vIn;
692  else
693  vOut = this->adjoint() * vIn;
694 }
695 
696 template <typename MAT_C, typename MAT_R>
697 EIGEN_STRONG_INLINE void multiply_HCHt(
698  const MAT_C& C, MAT_R& R, bool accumResultInOutput = false)
699  const /*!< R = this * C * this<sup>T</sup> */
700 {
701  if (accumResultInOutput)
702  R.noalias() += (*this) * C * this->adjoint();
703  else
704  R.noalias() = (*this) * C * this->adjoint();
705 }
706 
707 template <typename MAT_C, typename MAT_R>
708 EIGEN_STRONG_INLINE void multiply_HtCH(
709  const MAT_C& C, MAT_R& R, bool accumResultInOutput = false)
710  const /*!< R = this<sup>T</sup> * C * this */
711 {
712  if (accumResultInOutput)
713  R.noalias() += this->adjoint() * C * (*this);
714  else
715  R.noalias() = this->adjoint() * C * (*this);
716 }
717 
718 /*! R = H * C * H<sup>T</sup> (with a vector H and a symmetric matrix C) In fact
719  * when H is a vector, multiply_HCHt_scalar and multiply_HtCH_scalar are exactly
720  * equivalent */
721 template <typename MAT_C>
722 EIGEN_STRONG_INLINE Scalar multiply_HCHt_scalar(const MAT_C& C) const
723 {
724  return ((*this) * C * this->adjoint()).eval()(0, 0);
725 }
726 
727 /*! R = H<sup>T</sup> * C * H (with a vector H and a symmetric matrix C) In fact
728  * when H is a vector, multiply_HCHt_scalar and multiply_HtCH_scalar are exactly
729  * equivalent */
730 template <typename MAT_C>
731 EIGEN_STRONG_INLINE Scalar multiply_HtCH_scalar(const MAT_C& C) const
732 {
733  return (this->adjoint() * C * (*this)).eval()(0, 0);
734 }
735 
736 /*! this = C * C<sup>T</sup> * f (with a matrix C and a scalar f). */
737 template <typename MAT_A>
738 EIGEN_STRONG_INLINE void multiply_AAt_scalar(
739  const MAT_A& A, typename MAT_A::Scalar f)
740 {
741  *this = (A * A.adjoint()) * f;
742 }
743 
744 /*! this = C<sup>T</sup> * C * f (with a matrix C and a scalar f). */
745 template <typename MAT_A>
746 EIGEN_STRONG_INLINE void multiply_AtA_scalar(
747  const MAT_A& A, typename MAT_A::Scalar f)
748 {
749  *this = (A.adjoint() * A) * f;
750 }
751 
752 /*! this = A * skew(v), with \a v being a 3-vector (or 3-array) and skew(v) the
753  * skew symmetric matrix of v (see mrpt::math::skew_symmetric3) */
754 template <class MAT_A, class SKEW_3VECTOR>
755 void multiply_A_skew3(const MAT_A& A, const SKEW_3VECTOR& v)
756 {
758 }
759 
760 /*! this = skew(v)*A, with \a v being a 3-vector (or 3-array) and skew(v) the
761  * skew symmetric matrix of v (see mrpt::math::skew_symmetric3) */
762 template <class SKEW_3VECTOR, class MAT_A>
763 void multiply_skew3_A(const SKEW_3VECTOR& v, const MAT_A& A)
764 {
766 }
767 
768 /** outResult = this * A
769  */
770 template <class MAT_A, class MAT_OUT>
771 EIGEN_STRONG_INLINE void multiply_subMatrix(
772  const MAT_A& A, MAT_OUT& outResult, const size_t A_cols_offset,
773  const size_t A_rows_offset, const size_t A_col_count) const
774 {
775  outResult =
776  derived() *
777  A.block(A_rows_offset, A_cols_offset, derived().cols(), A_col_count);
778 }
779 
780 template <class MAT_A, class MAT_B, class MAT_C>
782  const MAT_A& A, const MAT_B& B, const MAT_C& C) /*!< this = A*B*C */
783 {
784  *this = A * B * C;
785 }
786 
787 template <class MAT_A, class MAT_B, class MAT_C>
789  const MAT_A& A, const MAT_B& B,
790  const MAT_C& C) /*!< this = A*B*(C<sup>T</sup>) */
791 {
792  *this = A * B * C.adjoint();
793 }
794 
795 template <class MAT_A, class MAT_B, class MAT_C>
797  const MAT_A& A, const MAT_B& B,
798  const MAT_C& C) /*!< this = A(<sup>T</sup>)*B*C */
799 {
800  *this = A.adjoint() * B * C;
801 }
802 
803 template <class MAT_A, class MAT_B>
804 EIGEN_STRONG_INLINE void multiply_ABt(
805  const MAT_A& A, const MAT_B& B) /*!< this = A * B<sup>T</sup> */
806 {
807  *this = A * B.adjoint();
808 }
809 
810 template <class MAT_A>
811 EIGEN_STRONG_INLINE void multiply_AAt(
812  const MAT_A& A) /*!< this = A * A<sup>T</sup> */
813 {
814  *this = A * A.adjoint();
815 }
816 
817 template <class MAT_A>
818 EIGEN_STRONG_INLINE void multiply_AtA(
819  const MAT_A& A) /*!< this = A<sup>T</sup> * A */
820 {
821  *this = A.adjoint() * A;
822 }
823 
824 template <class MAT_A, class MAT_B>
825 EIGEN_STRONG_INLINE void multiply_result_is_symmetric(
826  const MAT_A& A, const MAT_B& B) /*!< this = A * B (result is symmetric) */
827 {
828  *this = A * B;
829 }
830 
831 /** @} */ // end multiply functions
832 
833 /** @name MRPT plugin: Eigenvalue / Eigenvectors
834  @{ */
835 
836 /** [For square matrices only] Compute the eigenvectors and eigenvalues
837  * (sorted), both returned as matrices: eigenvectors are the columns in "eVecs",
838  * and eigenvalues in ascending order as the diagonal of "eVals".
839  * \note Warning: Only the real part of complex eigenvectors and eigenvalues
840  * are returned.
841  * \sa eigenVectorsSymmetric, eigenVectorsVec
842  * \return false on error
843  */
844 template <class MATRIX1, class MATRIX2>
845 EIGEN_STRONG_INLINE bool eigenVectors(MATRIX1& eVecs, MATRIX2& eVals) const;
846 // Implemented in eigen_plugins_impl.h (can't be here since
847 // Eigen::SelfAdjointEigenSolver isn't defined yet at this point.
848 
849 /** [For square matrices only] Compute the eigenvectors and eigenvalues
850  * (sorted), eigenvectors are the columns in "eVecs", and eigenvalues are
851  * returned in in ascending order in the vector "eVals".
852  * \note Warning: Only the real part of complex eigenvectors and eigenvalues
853  * are returned.
854  * \sa eigenVectorsSymmetric, eigenVectorsVec
855  * \return false on error
856  */
857 template <class MATRIX1, class VECTOR1>
858 EIGEN_STRONG_INLINE bool eigenVectorsVec(MATRIX1& eVecs, VECTOR1& eVals) const;
859 // Implemented in eigen_plugins_impl.h
860 
861 /** [For square matrices only] Compute the eigenvectors and eigenvalues
862  * (sorted), and return only the eigenvalues in the vector "eVals".
863  * \note Warning: Only the real part of complex eigenvectors and eigenvalues
864  * are returned.
865  * \sa eigenVectorsSymmetric, eigenVectorsVec
866  */
867 template <class VECTOR>
868 EIGEN_STRONG_INLINE void eigenValues(VECTOR& eVals) const
869 {
870  PlainObject eVecs;
871  eVecs.resizeLike(*this);
872  this->eigenVectorsVec(eVecs, eVals);
873 }
874 
875 /** [For symmetric matrices only] Compute the eigenvectors and eigenvalues (in
876  * no particular order), both returned as matrices: eigenvectors are the
877  * columns, and eigenvalues \sa eigenVectors
878  */
879 template <class MATRIX1, class MATRIX2>
880 EIGEN_STRONG_INLINE void eigenVectorsSymmetric(
881  MATRIX1& eVecs, MATRIX2& eVals) const;
882 // Implemented in eigen_plugins_impl.h (can't be here since
883 // Eigen::SelfAdjointEigenSolver isn't defined yet at this point.
884 
885 /** [For symmetric matrices only] Compute the eigenvectors and eigenvalues (in
886  * no particular order), both returned as matrices: eigenvectors are the
887  * columns, and eigenvalues \sa eigenVectorsVec
888  */
889 template <class MATRIX1, class VECTOR1>
890 EIGEN_STRONG_INLINE void eigenVectorsSymmetricVec(
891  MATRIX1& eVecs, VECTOR1& eVals) const;
892 // Implemented in eigen_plugins_impl.h
893 
894 /** @} */ // end eigenvalues
895 
896 /** @name MRPT plugin: Linear algebra & decomposition-based methods
897  @{ */
898 
899 /** Cholesky M=U<sup>T</sup> * U decomposition for simetric matrix (upper-half
900  * of the matrix will be actually ignored) */
901 template <class MATRIX>
902 EIGEN_STRONG_INLINE bool chol(MATRIX& U) const
903 {
904  Eigen::LLT<PlainObject> Chol =
905  derived().template selfadjointView<Eigen::Lower>().llt();
906  if (Chol.info() == Eigen::NoConvergence) return false;
907  U = PlainObject(Chol.matrixU());
908  return true;
909 }
910 
911 /** Gets the rank of the matrix via the Eigen::ColPivHouseholderQR method
912  * \param threshold If set to >0, it's used as threshold instead of Eigen's
913  * default one.
914  */
915 EIGEN_STRONG_INLINE size_t rank(double threshold = 0) const
916 {
917  Eigen::ColPivHouseholderQR<PlainObject> QR = this->colPivHouseholderQr();
918  if (threshold > 0) QR.setThreshold(threshold);
919  return QR.rank();
920 }
921 
922 /** @} */ // end linear algebra
923 
924 /** @name MRPT plugin: Scalar and element-wise extra operators
925  @{ */
926 
927 /** Scales all elements such as the minimum & maximum values are shifted to the
928  * given values */
929 void normalize(Scalar valMin, Scalar valMax)
930 {
931  if (size() == 0) return;
932  Scalar curMin, curMax;
933  minimum_maximum(curMin, curMax);
934  Scalar minMaxDelta = curMax - curMin;
935  if (minMaxDelta == 0) minMaxDelta = 1;
936  const Scalar minMaxDelta_ = (valMax - valMin) / minMaxDelta;
937  this->array() = (this->array() - curMin) * minMaxDelta_ + valMin;
938 }
939 //! \overload
940 inline void adjustRange(Scalar valMin, Scalar valMax)
941 {
942  normalize(valMin, valMax);
943 }
944 
945 /** @} */ // end Scalar
946 
947 /** Extract one row from the matrix into a row vector */
948 template <class OtherDerived>
949 EIGEN_STRONG_INLINE void extractRow(
950  size_t nRow, Eigen::EigenBase<OtherDerived>& v,
951  size_t startingCol = 0) const
952 {
953  v = derived().block(nRow, startingCol, 1, cols() - startingCol);
954 }
955 //! \overload
956 template <typename T>
957 inline void extractRow(
958  size_t nRow, std::vector<T>& v, size_t startingCol = 0) const
959 {
960  const size_t N = cols() - startingCol;
961  v.resize(N);
962  for (size_t i = 0; i < N; i++) v[i] = (*this)(nRow, startingCol + i);
963 }
964 /** Extract one row from the matrix into a column vector */
965 template <class VECTOR>
966 EIGEN_STRONG_INLINE void extractRowAsCol(
967  size_t nRow, VECTOR& v, size_t startingCol = 0) const
968 {
969  v = derived().adjoint().block(startingCol, nRow, cols() - startingCol, 1);
970 }
971 
972 /** Extract one column from the matrix into a column vector */
973 template <class VECTOR>
974 EIGEN_STRONG_INLINE void extractCol(
975  size_t nCol, VECTOR& v, size_t startingRow = 0) const
976 {
977  v = derived().block(startingRow, nCol, rows() - startingRow, 1);
978 }
979 //! \overload
980 template <typename T>
981 inline void extractCol(
982  size_t nCol, std::vector<T>& v, size_t startingRow = 0) const
983 {
984  const size_t N = rows() - startingRow;
985  v.resize(N);
986  for (size_t i = 0; i < N; i++) v[i] = (*this)(startingRow + i, nCol);
987 }
988 
989 template <class MATRIX>
990 EIGEN_STRONG_INLINE void extractMatrix(
991  const size_t firstRow, const size_t firstCol, MATRIX& m) const
992 {
993  m = derived().block(firstRow, firstCol, m.rows(), m.cols());
994 }
995 template <class MATRIX>
996 EIGEN_STRONG_INLINE void extractMatrix(
997  const size_t firstRow, const size_t firstCol, const size_t nRows,
998  const size_t nCols, MATRIX& m) const
999 {
1000  m.resize(nRows, nCols);
1001  m = derived().block(firstRow, firstCol, nRows, nCols);
1002 }
1003 
1004 /** Get a submatrix, given its bounds: first & last column and row (inclusive).
1005  */
1006 template <class MATRIX>
1007 EIGEN_STRONG_INLINE void extractSubmatrix(
1008  const size_t row_first, const size_t row_last, const size_t col_first,
1009  const size_t col_last, MATRIX& out) const
1010 {
1011  out.resize(row_last - row_first + 1, col_last - col_first + 1);
1012  out = derived().block(
1013  row_first, col_first, row_last - row_first + 1,
1014  col_last - col_first + 1);
1015 }
1016 
1017 /** Get a submatrix from a square matrix, by collecting the elements
1018  * M(idxs,idxs), where idxs is a sequence
1019  * {block_indices(i):block_indices(i)+block_size-1} for all "i" up to the size
1020  * of block_indices.
1021  * A perfect application of this method is in extracting covariance matrices
1022  * of a subset of variables from the full covariance matrix.
1023  * \sa extractSubmatrix, extractSubmatrixSymmetrical
1024  */
1025 template <class MATRIX>
1027  const size_t block_size, const std::vector<size_t>& block_indices,
1028  MATRIX& out) const
1029 {
1030  if (block_size < 1)
1031  throw std::runtime_error(
1032  "extractSubmatrixSymmetricalBlocks: block_size must be >=1");
1033  if (cols() != rows())
1034  throw std::runtime_error(
1035  "extractSubmatrixSymmetricalBlocks: Matrix is not square.");
1036 
1037  const size_t N = block_indices.size();
1038  const size_t nrows_out = N * block_size;
1039  out.resize(nrows_out, nrows_out);
1040  if (!N) return; // Done
1041  for (size_t dst_row_blk = 0; dst_row_blk < N; ++dst_row_blk)
1042  {
1043  for (size_t dst_col_blk = 0; dst_col_blk < N; ++dst_col_blk)
1044  {
1045 #if defined(_DEBUG)
1046  if (block_indices[dst_col_blk] * block_size + block_size - 1 >=
1047  size_t(cols()))
1048  throw std::runtime_error(
1049  "extractSubmatrixSymmetricalBlocks: Indices out of range!");
1050 #endif
1051  out.block(
1052  dst_row_blk * block_size, dst_col_blk * block_size, block_size,
1053  block_size) =
1054  derived().block(
1055  block_indices[dst_row_blk] * block_size,
1056  block_indices[dst_col_blk] * block_size, block_size,
1057  block_size);
1058  }
1059  }
1060 }
1061 
1062 /** Get a submatrix from a square matrix, by collecting the elements
1063  * M(idxs,idxs), where idxs is the sequence of indices passed as argument.
1064  * A perfect application of this method is in extracting covariance matrices
1065  * of a subset of variables from the full covariance matrix.
1066  * \sa extractSubmatrix, extractSubmatrixSymmetricalBlocks
1067  */
1068 template <class MATRIX>
1070  const std::vector<size_t>& indices, MATRIX& out) const
1071 {
1072  if (cols() != rows())
1073  throw std::runtime_error(
1074  "extractSubmatrixSymmetrical: Matrix is not square.");
1075 
1076  const size_t N = indices.size();
1077  const size_t nrows_out = N;
1078  out.resize(nrows_out, nrows_out);
1079  if (!N) return; // Done
1080  for (size_t dst_row_blk = 0; dst_row_blk < N; ++dst_row_blk)
1081  for (size_t dst_col_blk = 0; dst_col_blk < N; ++dst_col_blk)
1082  out.coeffRef(dst_row_blk, dst_col_blk) =
1083  this->coeff(indices[dst_row_blk], indices[dst_col_blk]);
1084 }
EIGEN_STRONG_INLINE void set_unsafe(const size_t row, const size_t col, const Scalar val)
Sets an element (Use with caution, bounds are not checked!)
EIGEN_STRONG_INLINE Scalar det() const
void meanAndStd(VEC &outMeanVector, VEC &outStdVector, const bool unbiased_variance=true) const
Computes a row with the mean values of each column in the matrix and the associated vector with the s...
void adjustRange(Scalar valMin, Scalar valMax)
EIGEN_STRONG_INLINE void extractRowAsCol(size_t nRow, VECTOR &v, size_t startingCol=0) const
Extract one row from the matrix into a column vector.
Scalar * iterator
Definition: eigen_plugins.h:26
EIGEN_STRONG_INLINE void scalarPow(const Scalar s)
Scalar power of all elements to a given power, this is diferent of ^ operator.
EIGEN_STRONG_INLINE void multiply_Ab(const OTHERVECTOR1 &vIn, OTHERVECTOR2 &vOut, bool accumToOutput=false) const
EIGEN_STRONG_INLINE bool empty() const
double Scalar
Definition: KmUtils.h:43
EIGEN_STRONG_INLINE void removeRows(const std::vector< size_t > &idxsToRemove)
Remove rows of the matrix.
EIGEN_STRONG_INLINE Scalar multiply_HCHt_scalar(const MAT_C &C) const
std::string inMatlabFormat(const size_t decimal_digits=6) const
Dump matrix in matlab format.
EIGEN_STRONG_INLINE void fill(const Scalar v)
Definition: eigen_plugins.h:46
EIGEN_STRONG_INLINE bool isSquare() const
engineering format &#39;e&#39;
Definition: math_frwds.h:62
EIGEN_STRONG_INLINE bool eigenVectors(MATRIX1 &eVecs, MATRIX2 &eVals) const
[For square matrices only] Compute the eigenvectors and eigenvalues (sorted), both returned as matric...
EIGEN_STRONG_INLINE void add_AAt(const OTHERMATRIX &A)
EIGEN_STRONG_INLINE bool chol(MATRIX &U) const
Cholesky M=UT * U decomposition for simetric matrix (upper-half of the matrix will be actually ignore...
EIGEN_STRONG_INLINE size_t rank(double threshold=0) const
Gets the rank of the matrix via the Eigen::ColPivHouseholderQR method.
EIGEN_STRONG_INLINE void multiply(const MATRIX1 &A, const MATRIX2 &B)
void extractSubmatrixSymmetricalBlocks(const size_t block_size, const std::vector< size_t > &block_indices, MATRIX &out) const
Get a submatrix from a square matrix, by collecting the elements M(idxs,idxs), where idxs is a sequen...
void multiply_skew3_A(const SKEW_3VECTOR &v, const MAT_A &A)
EIGEN_STRONG_INLINE Scalar * get_unsafe_row(size_t row)
Fast but unsafe method to obtain a pointer to a given row of the matrix (Use only in time critical ap...
Definition: eigen_plugins.h:93
EIGEN_STRONG_INLINE Scalar maximumDiagonal() const
Finds the maximum value in the diagonal of the matrix.
EIGEN_STRONG_INLINE void substract_Ac(const OTHERMATRIX &m, const Scalar c)
GLenum GLsizei n
Definition: glext.h:5136
void multiply_ABCt(const MAT_A &A, const MAT_B &B, const MAT_C &C)
void multiply_A_skew3(const MAT_A &A, const SKEW_3VECTOR &v, MAT_OUT &out)
Only for vectors/arrays "v" of length3, compute out = A * Skew(v), where Skew(v) is the skew symmetri...
Definition: ops_matrices.h:167
EIGEN_STRONG_INLINE void multiply_HCHt(const MAT_C &C, MAT_R &R, bool accumResultInOutput=false) const
EIGEN_STRONG_INLINE void swapRows(size_t i1, size_t i2)
GLuint GLuint GLsizei GLenum const GLvoid * indices
Definition: glext.h:3532
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:29
EIGEN_STRONG_INLINE void push_back(Scalar val)
Insert an element at the end of the container (for 1D vectors/arrays)
EIGEN_STRONG_INLINE bool isSingular(const Scalar absThreshold=0) const
EIGEN_STRONG_INLINE void extractCol(size_t nCol, VECTOR &v, size_t startingRow=0) const
Extract one column from the matrix into a column vector.
void find_index_max_value(size_t &u, size_t &v, Scalar &valMax) const
[VECTORS OR MATRICES] Finds the maximum value (and the corresponding zero-based index) from a given c...
EIGEN_STRONG_INLINE const AdjointReturnType t() const
Transpose.
void saveToTextFile(const std::string &file, mrpt::math::TMatrixTextFileFormat fileFormat=mrpt::math::MATRIX_FORMAT_ENG, bool appendMRPTHeader=false, const std::string &userHeader=std::string()) const
Save matrix to a text file, compatible with MATLAB text format (see also the methods of matrix classe...
EIGEN_STRONG_INLINE void eigenVectorsSymmetricVec(MATRIX1 &eVecs, VECTOR1 &eVals) const
[For symmetric matrices only] Compute the eigenvectors and eigenvalues (in no particular order)...
EIGEN_STRONG_INLINE void multiply_AtB(const MATRIX1 &A, const MATRIX2 &B)
EIGEN_STRONG_INLINE bool eigenVectorsVec(MATRIX1 &eVecs, VECTOR1 &eVals) const
[For square matrices only] Compute the eigenvectors and eigenvalues (sorted), eigenvectors are the co...
EIGEN_STRONG_INLINE Scalar get_unsafe(const size_t row, const size_t col) const
Read-only access to one element (Use with caution, bounds are not checked!)
EIGEN_STRONG_INLINE Scalar squareNorm() const
Compute the square norm of a vector/array/matrix (the Euclidean distance to the origin, taking all the elements as a single vector).
GLdouble s
Definition: glext.h:3682
EIGEN_STRONG_INLINE Scalar norm_inf() const
Compute the norm-infinite of a vector ($f[ ||{v}||_ $f]), ie the maximum absolute value of the elemen...
EIGEN_STRONG_INLINE void minimum_maximum(Scalar &out_min, Scalar &out_max) const
[VECTORS OR MATRICES] Compute the minimum and maximum of a container at once
void multiply_A_skew3(const MAT_A &A, const SKEW_3VECTOR &v)
T square(const T x)
Inline function for the square of a number.
EIGEN_STRONG_INLINE void insertMatrixTranspose(size_t r, size_t c, const MAT &m)
EIGEN_STRONG_INLINE void laplacian(Eigen::MatrixBase< OtherDerived > &ret) const
Computes the laplacian of this square graph weight matrix.
EIGEN_STRONG_INLINE void eigenVectorsSymmetric(MATRIX1 &eVecs, MATRIX2 &eVals) const
[For symmetric matrices only] Compute the eigenvectors and eigenvalues (in no particular order)...
EIGEN_STRONG_INLINE void swapCols(size_t i1, size_t i2)
EIGEN_STRONG_INLINE void multiply_Atb(const OTHERVECTOR1 &vIn, OTHERVECTOR2 &vOut, bool accumToOutput=false) const
const GLubyte * c
Definition: glext.h:6406
void largestEigenvector(OUTVECT &x, Scalar resolution=Scalar(0.01), size_t maxIterations=6, int *out_Iterations=nullptr, float *out_estimatedResolution=nullptr) const
Efficiently computes only the biggest eigenvector of the matrix using the Power Method, and returns it in the passed vector "x".
CONTAINER::Scalar sum(const CONTAINER &v)
Computes the sum of all the elements.
EIGEN_STRONG_INLINE size_t countNonZero() const
EIGEN_STRONG_INLINE void insertMatrix(size_t r, size_t c, const MAT &m)
Insert matrix "m" into this matrix at indices (r,c), that is, (*this)(r,c)=m(0,0) and so on...
EIGEN_STRONG_INLINE void substract_At(const OTHERMATRIX &m)
EIGEN_STRONG_INLINE void substract_AAt(const OTHERMATRIX &A)
int val
Definition: mrpt_jpeglib.h:957
EIGEN_STRONG_INLINE Scalar multiply_HtCH_scalar(const MAT_C &C) const
EIGEN_STRONG_INLINE void setSize(size_t row, size_t col)
Changes the size of matrix, maintaining its previous content as possible and padding with zeros where...
MatrixBase< Derived > & operator^=(const unsigned int pow)
Combined matrix power and assignment operator.
EIGEN_STRONG_INLINE void multiply_AB(const MATRIX1 &A, const MATRIX2 &B)
EIGEN_STRONG_INLINE void insertCol(size_t nCol, const MAT &aCol)
EIGEN_STRONG_INLINE void multiply_AAt_scalar(const MAT_A &A, typename MAT_A::Scalar f)
EIGEN_STRONG_INLINE void unit(const size_t nRows, const Scalar diag_vals)
Make the matrix an identity matrix (the diagonal values can be 1.0 or any other value) ...
Definition: eigen_plugins.h:58
EIGEN_STRONG_INLINE void removeColumns(const std::vector< size_t > &idxsToRemove)
Remove columns of the matrix.
EIGEN_STRONG_INLINE void unsafeRemoveRows(const std::vector< size_t > &idxs)
Remove rows of the matrix.
TMatrixTextFileFormat
Definition: math_frwds.h:59
EIGEN_STRONG_INLINE void assign(const Scalar v)
Definition: eigen_plugins.h:48
GLsizei const GLchar ** string
Definition: glext.h:4116
EIGEN_STRONG_INLINE void extractSubmatrix(const size_t row_first, const size_t row_last, const size_t col_first, const size_t col_last, MATRIX &out) const
Get a submatrix, given its bounds: first & last column and row (inclusive).
EIGEN_STRONG_INLINE void unsafeRemoveColumns(const std::vector< size_t > &idxs)
Remove columns of the matrix.
void multiply_AtBC(const MAT_A &A, const MAT_B &B, const MAT_C &C)
void meanAndStdAll(double &outMean, double &outStd, const bool unbiased_variance=true) const
Computes the mean and standard deviation of all the elements in the matrix as a whole.
EIGEN_STRONG_INLINE void insertRow(size_t nRow, const MAT &aRow)
EIGEN_STRONG_INLINE void substract_An(const OTHERMATRIX &m, const size_t n)
bool fromMatlabStringFormat(const std::string &s, std::ostream *dump_errors_here=nullptr)
Read a matrix from a string in Matlab-like format, for example "[1 0 2; 0 4 -1]" The string must star...
EIGEN_STRONG_INLINE iterator end()
Definition: eigen_plugins.h:30
EIGEN_STRONG_INLINE Scalar maximum() const
[VECTORS OR MATRICES] Finds the maximum value
void loadFromTextFile(const std::string &file)
Load matrix from a text file, compatible with MATLAB text format.
void normalize(Scalar valMin, Scalar valMax)
Scales all elements such as the minimum & maximum values are shifted to the given values...
Internal resize which compiles to nothing on fixed-size matrices.
Definition: math_frwds.h:38
const GLdouble * v
Definition: glext.h:3684
EIGEN_STRONG_INLINE Scalar sumAll() const
GLdouble GLdouble GLdouble r
Definition: glext.h:3711
EIGEN_STRONG_INLINE void multiply_ABt(const MAT_A &A, const MAT_B &B)
const float R
EIGEN_STRONG_INLINE bool isDiagonal() const
Checks for matrix type.
EIGEN_STRONG_INLINE void multiply_AtA(const MAT_A &A)
GLenum GLenum GLvoid * row
Definition: glext.h:3580
void extractSubmatrixSymmetrical(const std::vector< size_t > &indices, MATRIX &out) const
Get a submatrix from a square matrix, by collecting the elements M(idxs,idxs), where idxs is the sequ...
EIGEN_STRONG_INLINE void multiply_HtCH(const MAT_C &C, MAT_R &R, bool accumResultInOutput=false) const
EIGEN_STRONG_INLINE void add_Ac(const OTHERMATRIX &m, const Scalar c)
EIGEN_STRONG_INLINE void extractMatrix(const size_t firstRow, const size_t firstCol, MATRIX &m) const
EIGEN_STRONG_INLINE void multiply_subMatrix(const MAT_A &A, MAT_OUT &outResult, const size_t A_cols_offset, const size_t A_rows_offset, const size_t A_col_count) const
outResult = this * A
EIGEN_STRONG_INLINE void zeros()
Set all elements to zero.
Definition: eigen_plugins.h:74
EIGEN_STRONG_INLINE void inv_fast(MATRIX &outMat) const
EIGEN_STRONG_INLINE void eigenValues(VECTOR &eVals) const
[For square matrices only] Compute the eigenvectors and eigenvalues (sorted), and return only the eig...
void multiply_skew3_A(const SKEW_3VECTOR &v, const MAT_A &A, MAT_OUT &out)
Only for vectors/arrays "v" of length3, compute out = Skew(v) * A, where Skew(v) is the skew symmetri...
Definition: ops_matrices.h:191
EIGEN_STRONG_INLINE void multiply_AtA_scalar(const MAT_A &A, typename MAT_A::Scalar f)
GLsizeiptr size
Definition: glext.h:3934
void multiply_ABC(const MAT_A &A, const MAT_B &B, const MAT_C &C)
EIGEN_STRONG_INLINE void multiply_result_is_symmetric(const MAT_A &A, const MAT_B &B)
GLenum GLint x
Definition: glext.h:3542
EIGEN_STRONG_INLINE void eye()
Make the matrix an identity matrix.
Definition: eigen_plugins.h:72
EIGEN_STRONG_INLINE void multiplyRowByScalar(size_t r, Scalar s)
EIGEN_STRONG_INLINE void ones(const size_t row, const size_t col)
Resize matrix and set all elements to one.
Definition: eigen_plugins.h:82
EIGEN_STRONG_INLINE void extractRow(size_t nRow, Eigen::EigenBase< OtherDerived > &v, size_t startingCol=0) const
Extract one row from the matrix into a row vector.
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3550
EIGEN_STRONG_INLINE Scalar minimum() const
[VECTORS OR MATRICES] Finds the minimum value
const Scalar * const_iterator
Definition: eigen_plugins.h:27
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
EIGEN_STRONG_INLINE void multiplyColumnByScalar(size_t c, Scalar s)
EIGEN_STRONG_INLINE PlainObject inv() const
EIGEN_STRONG_INLINE void multiply_AAt(const MAT_A &A)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 58f856185 Mon May 20 11:43:57 2019 +0200 at lun may 20 11:50:17 CEST 2019