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 // Eigen is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 3 of the License, or (at your option) any later version.
11 //
12 // Alternatively, you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License as
14 // published by the Free Software Foundation; either version 2 of
15 // the License, or (at your option) any later version.
16 //
17 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License and a copy of the GNU General Public License along with
24 // Eigen. If not, see <http://www.gnu.org/licenses/>.
25 
26 #ifndef EIGEN_MATRIXBASEEIGENVALUES_H
27 #define EIGEN_MATRIXBASEEIGENVALUES_H
28 
29 namespace Eigen {
30 
31 namespace internal {
32 
33 template<typename Derived, bool IsComplex>
34 struct eigenvalues_selector
35 {
36  // this is the implementation for the case IsComplex = true
37  static inline typename MatrixBase<Derived>::EigenvaluesReturnType const
38  run(const MatrixBase<Derived>& m)
39  {
40  typedef typename Derived::PlainObject PlainObject;
41  PlainObject m_eval(m);
42  return ComplexEigenSolver<PlainObject>(m_eval, false).eigenvalues();
43  }
44 };
45 
46 template<typename Derived>
47 struct eigenvalues_selector<Derived, false>
48 {
49  static inline typename MatrixBase<Derived>::EigenvaluesReturnType const
50  run(const MatrixBase<Derived>& m)
51  {
52  typedef typename Derived::PlainObject PlainObject;
53  PlainObject m_eval(m);
54  return EigenSolver<PlainObject>(m_eval, false).eigenvalues();
55  }
56 };
57 
58 } // end namespace internal
59 
80 template<typename Derived>
81 inline typename MatrixBase<Derived>::EigenvaluesReturnType
83 {
84  typedef typename internal::traits<Derived>::Scalar Scalar;
86 }
87 
102 template<typename MatrixType, unsigned int UpLo>
105 {
107  PlainObject thisAsMatrix(*this);
108  return SelfAdjointEigenSolver<PlainObject>(thisAsMatrix, false).eigenvalues();
109 }
110 
111 
112 
135 template<typename Derived>
136 inline typename MatrixBase<Derived>::RealScalar
138 {
139  typename Derived::PlainObject m_eval(derived());
140  // FIXME if it is really guaranteed that the eigenvalues are already sorted,
141  // then we don't need to compute a maxCoeff() here, comparing the 1st and last ones is enough.
142  return internal::sqrt((m_eval*m_eval.adjoint())
143  .eval()
144  .template selfadjointView<Lower>()
145  .eigenvalues()
146  .maxCoeff()
147  );
148 }
149 
165 template<typename MatrixType, unsigned int UpLo>
168 {
169  return eigenvalues().cwiseAbs().maxCoeff();
170 }
171 
172 } // end namespace Eigen
173 
174 #endif