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