MatrixBaseEigenvalues.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_MATRIXBASEEIGENVALUES_H
12 #define EIGEN_MATRIXBASEEIGENVALUES_H
13 
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 
20 template<typename Derived, bool IsComplex>
21 struct eigenvalues_selector
22 {
23  // this is the implementation for the case IsComplex = true
24  static inline typename MatrixBase<Derived>::EigenvaluesReturnType const
25  run(const MatrixBase<Derived>& m)
26  {
27  typedef typename Derived::PlainObject PlainObject;
28  PlainObject m_eval(m);
29  return ComplexEigenSolver<PlainObject>(m_eval, false).eigenvalues();
30  }
31 };
32 
33 template<typename Derived>
34 struct eigenvalues_selector<Derived, false>
35 {
36  static inline typename MatrixBase<Derived>::EigenvaluesReturnType const
37  run(const MatrixBase<Derived>& m)
38  {
39  typedef typename Derived::PlainObject PlainObject;
40  PlainObject m_eval(m);
41  return EigenSolver<PlainObject>(m_eval, false).eigenvalues();
42  }
43 };
44 
45 } // end namespace internal
46 
67 template<typename Derived>
68 inline typename MatrixBase<Derived>::EigenvaluesReturnType
70 {
71  return internal::eigenvalues_selector<Derived, NumTraits<Scalar>::IsComplex>::run(derived());
72 }
73 
88 template<typename MatrixType, unsigned int UpLo>
91 {
92  PlainObject thisAsMatrix(*this);
93  return SelfAdjointEigenSolver<PlainObject>(thisAsMatrix, false).eigenvalues();
94 }
95 
96 
97 
120 template<typename Derived>
121 inline typename MatrixBase<Derived>::RealScalar
123 {
124  using std::sqrt;
125  typename Derived::PlainObject m_eval(derived());
126  // FIXME if it is really guaranteed that the eigenvalues are already sorted,
127  // then we don't need to compute a maxCoeff() here, comparing the 1st and last ones is enough.
128  return sqrt((m_eval*m_eval.adjoint())
129  .eval()
130  .template selfadjointView<Lower>()
131  .eigenvalues()
132  .maxCoeff()
133  );
134 }
135 
151 template<typename MatrixType, unsigned int UpLo>
154 {
155  return eigenvalues().cwiseAbs().maxCoeff();
156 }
157 
158 } // end namespace Eigen
159 
160 #endif
Matrix3f m
const SqrtReturnType sqrt() const
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
NumTraits< Scalar >::Real RealScalar
Definition: DenseBase.h:68
RealScalar operatorNorm() const
Computes the L2 operator norm.
EigenvaluesReturnType eigenvalues() const
Computes the eigenvalues of a matrix.
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
Computes eigenvalues and eigenvectors of selfadjoint matrices.
const RealVectorType & eigenvalues() const
Returns the eigenvalues of given matrix.
RealScalar operatorNorm() const
Computes the L2 operator norm.
MatrixType::PlainObject PlainObject
NumTraits< Scalar >::Real RealScalar
EigenvaluesReturnType eigenvalues() const
Computes the eigenvalues of a matrix.
: InteropHeaders
Definition: Core:139
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)