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