MatrixBaseEigenvalues.h
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
14namespace Eigen {
15
16namespace internal {
17
18template<typename Derived, bool IsComplex>
19struct eigenvalues_selector
20{
21 // this is the implementation for the case IsComplex = true
22 static inline typename MatrixBase<Derived>::EigenvaluesReturnType const
23 run(const MatrixBase<Derived>& m)
24 {
25 typedef typename Derived::PlainObject PlainObject;
26 PlainObject m_eval(m);
27 return ComplexEigenSolver<PlainObject>(m_eval, false).eigenvalues();
28 }
29};
30
31template<typename Derived>
32struct eigenvalues_selector<Derived, false>
33{
34 static inline typename MatrixBase<Derived>::EigenvaluesReturnType const
35 run(const MatrixBase<Derived>& m)
36 {
37 typedef typename Derived::PlainObject PlainObject;
38 PlainObject m_eval(m);
39 return EigenSolver<PlainObject>(m_eval, false).eigenvalues();
40 }
41};
42
43} // end namespace internal
44
65template<typename Derived>
68{
69 typedef typename internal::traits<Derived>::Scalar Scalar;
70 return internal::eigenvalues_selector<Derived, NumTraits<Scalar>::IsComplex>::run(derived());
71}
72
87template<typename MatrixType, unsigned int UpLo>
90{
91 typedef typename SelfAdjointView<MatrixType, UpLo>::PlainObject PlainObject;
92 PlainObject thisAsMatrix(*this);
93 return SelfAdjointEigenSolver<PlainObject>(thisAsMatrix, false).eigenvalues();
94}
95
96
97
120template<typename Derived>
121inline typename MatrixBase<Derived>::RealScalar
123{
124 typename Derived::PlainObject m_eval(derived());
125 // FIXME if it is really guaranteed that the eigenvalues are already sorted,
126 // then we don't need to compute a maxCoeff() here, comparing the 1st and last ones is enough.
127 return internal::sqrt((m_eval*m_eval.adjoint())
128 .eval()
129 .template selfadjointView<Lower>()
130 .eigenvalues()
131 .maxCoeff()
132 );
133}
134
150template<typename MatrixType, unsigned int UpLo>
153{
154 return eigenvalues().cwiseAbs().maxCoeff();
155}
156
157} // end namespace Eigen
158
159#endif
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
EigenvaluesReturnType eigenvalues() const
Computes the eigenvalues of a matrix.
Definition MatrixBaseEigenvalues.h:67
RealScalar operatorNorm() const
Computes the L2 operator norm.
Definition MatrixBaseEigenvalues.h:122
Computes eigenvalues and eigenvectors of selfadjoint matrices.
Definition SelfAdjointEigenSolver.h:69
const RealVectorType & eigenvalues() const
Returns the eigenvalues of given matrix.
Definition SelfAdjointEigenSolver.h:250
RealScalar operatorNorm() const
Computes the L2 operator norm.
Definition MatrixBaseEigenvalues.h:152
EigenvaluesReturnType eigenvalues() const
Computes the eigenvalues of a matrix.
Definition MatrixBaseEigenvalues.h:89
NumTraits< Scalar >::Real RealScalar
Definition SelfAdjointView.h:158
Matrix< RealScalar, internal::traits< MatrixType >::ColsAtCompileTime, 1 > EigenvaluesReturnType
Definition SelfAdjointView.h:160
Definition LDLT.h:18