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



Page generated by Doxygen 1.8.14 for MRPT 1.1.0 SVN: at lun oct 28 00:54:49 CET 2019 Hosted on:
SourceForge.net Logo