Eigen  5.0.1
 
Loading...
Searching...
No Matches
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// SPDX-License-Identifier: MPL-2.0
11
12#ifndef EIGEN_MATRIXBASEEIGENVALUES_H
13#define EIGEN_MATRIXBASEEIGENVALUES_H
14
15// IWYU pragma: private
16#include "./InternalHeaderCheck.h"
17
18namespace Eigen {
19
20namespace internal {
21
22template <typename Derived, bool IsComplex>
23struct eigenvalues_selector {
24 // this is the implementation for the case IsComplex = true
25 static inline typename MatrixBase<Derived>::EigenvaluesReturnType const run(const MatrixBase<Derived>& m) {
26 using PlainObject = typename Derived::PlainObject;
27 PlainObject m_eval(m);
28 return ComplexEigenSolver<PlainObject>(m_eval, false).eigenvalues();
29 }
30};
31
32template <typename Derived>
33struct eigenvalues_selector<Derived, false> {
34 static inline typename MatrixBase<Derived>::EigenvaluesReturnType const run(const MatrixBase<Derived>& m) {
35 using PlainObject = typename Derived::PlainObject;
36 PlainObject m_eval(m);
37 return EigenSolver<PlainObject>(m_eval, false).eigenvalues();
38 }
39};
40
41} // end namespace internal
42
63template <typename Derived>
64inline typename MatrixBase<Derived>::EigenvaluesReturnType MatrixBase<Derived>::eigenvalues() const {
65 return internal::eigenvalues_selector<Derived, NumTraits<Scalar>::IsComplex>::run(derived());
66}
67
82template <typename MatrixType, unsigned int UpLo>
85 PlainObject thisAsMatrix(*this);
86 return SelfAdjointEigenSolver<PlainObject>(thisAsMatrix, false).eigenvalues();
87}
88
111template <typename Derived>
112inline typename MatrixBase<Derived>::RealScalar MatrixBase<Derived>::operatorNorm() const {
113 using std::sqrt;
114 typename Derived::PlainObject m_eval(derived());
115 // FIXME: if eigenvalues are guaranteed to be sorted, comparing the first and last is sufficient.
116 return sqrt((m_eval * m_eval.adjoint()).eval().template selfadjointView<Lower>().eigenvalues().maxCoeff());
117}
118
134template <typename MatrixType, unsigned int UpLo>
135EIGEN_DEVICE_FUNC inline typename SelfAdjointView<MatrixType, UpLo>::RealScalar
137 return eigenvalues().cwiseAbs().maxCoeff();
138}
139
140} // end namespace Eigen
141
142#endif
RealScalar operatorNorm() const
Computes the L2 operator norm.
Definition MatrixBaseEigenvalues.h:112
EigenvaluesReturnType eigenvalues() const
Computes the eigenvalues of a matrix.
Definition MatrixBaseEigenvalues.h:64
const MatrixSquareRootReturnValue< Derived > sqrt() const
This function requires the <a * href="contrib/group__MatrixFunctions__Module.html"> contrib MatrixFun...
Computes eigenvalues and eigenvectors of selfadjoint matrices.
Definition SelfAdjointEigenSolver.h:83
const RealVectorType & eigenvalues() const
Returns the eigenvalues of given matrix.
Definition SelfAdjointEigenSolver.h:338
RealScalar operatorNorm() const
Computes the L2 operator norm.
Definition MatrixBaseEigenvalues.h:136
typename NumTraits< Scalar >::Real RealScalar
Definition SelfAdjointView.h:67
Matrix< RealScalar, internal::traits< MatrixType >::ColsAtCompileTime, 1 > EigenvaluesReturnType
Definition SelfAdjointView.h:230
EigenvaluesReturnType eigenvalues() const
Computes the eigenvalues of a matrix.
Definition MatrixBaseEigenvalues.h:84