Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/eigen3/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 // Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
0006 //
0007 // This Source Code Form is subject to the terms of the Mozilla
0008 // Public License v. 2.0. If a copy of the MPL was not distributed
0009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0010 
0011 #ifndef EIGEN_MATRIXBASEEIGENVALUES_H
0012 #define EIGEN_MATRIXBASEEIGENVALUES_H
0013 
0014 namespace Eigen { 
0015 
0016 namespace internal {
0017 
0018 template<typename Derived, bool IsComplex>
0019 struct eigenvalues_selector
0020 {
0021   // this is the implementation for the case IsComplex = true
0022   static inline typename MatrixBase<Derived>::EigenvaluesReturnType const
0023   run(const MatrixBase<Derived>& m)
0024   {
0025     typedef typename Derived::PlainObject PlainObject;
0026     PlainObject m_eval(m);
0027     return ComplexEigenSolver<PlainObject>(m_eval, false).eigenvalues();
0028   }
0029 };
0030 
0031 template<typename Derived>
0032 struct eigenvalues_selector<Derived, false>
0033 {
0034   static inline typename MatrixBase<Derived>::EigenvaluesReturnType const
0035   run(const MatrixBase<Derived>& m)
0036   {
0037     typedef typename Derived::PlainObject PlainObject;
0038     PlainObject m_eval(m);
0039     return EigenSolver<PlainObject>(m_eval, false).eigenvalues();
0040   }
0041 };
0042 
0043 } // end namespace internal
0044 
0045 /** \brief Computes the eigenvalues of a matrix 
0046   * \returns Column vector containing the eigenvalues.
0047   *
0048   * \eigenvalues_module
0049   * This function computes the eigenvalues with the help of the EigenSolver
0050   * class (for real matrices) or the ComplexEigenSolver class (for complex
0051   * matrices). 
0052   *
0053   * The eigenvalues are repeated according to their algebraic multiplicity,
0054   * so there are as many eigenvalues as rows in the matrix.
0055   *
0056   * The SelfAdjointView class provides a better algorithm for selfadjoint
0057   * matrices.
0058   *
0059   * Example: \include MatrixBase_eigenvalues.cpp
0060   * Output: \verbinclude MatrixBase_eigenvalues.out
0061   *
0062   * \sa EigenSolver::eigenvalues(), ComplexEigenSolver::eigenvalues(),
0063   *     SelfAdjointView::eigenvalues()
0064   */
0065 template<typename Derived>
0066 inline typename MatrixBase<Derived>::EigenvaluesReturnType
0067 MatrixBase<Derived>::eigenvalues() const
0068 {
0069   return internal::eigenvalues_selector<Derived, NumTraits<Scalar>::IsComplex>::run(derived());
0070 }
0071 
0072 /** \brief Computes the eigenvalues of a matrix
0073   * \returns Column vector containing the eigenvalues.
0074   *
0075   * \eigenvalues_module
0076   * This function computes the eigenvalues with the help of the
0077   * SelfAdjointEigenSolver class.  The eigenvalues are repeated according to
0078   * their algebraic multiplicity, so there are as many eigenvalues as rows in
0079   * the matrix.
0080   *
0081   * Example: \include SelfAdjointView_eigenvalues.cpp
0082   * Output: \verbinclude SelfAdjointView_eigenvalues.out
0083   *
0084   * \sa SelfAdjointEigenSolver::eigenvalues(), MatrixBase::eigenvalues()
0085   */
0086 template<typename MatrixType, unsigned int UpLo> 
0087 EIGEN_DEVICE_FUNC inline typename SelfAdjointView<MatrixType, UpLo>::EigenvaluesReturnType
0088 SelfAdjointView<MatrixType, UpLo>::eigenvalues() const
0089 {
0090   PlainObject thisAsMatrix(*this);
0091   return SelfAdjointEigenSolver<PlainObject>(thisAsMatrix, false).eigenvalues();
0092 }
0093 
0094 
0095 
0096 /** \brief Computes the L2 operator norm
0097   * \returns Operator norm of the matrix.
0098   *
0099   * \eigenvalues_module
0100   * This function computes the L2 operator norm of a matrix, which is also
0101   * known as the spectral norm. The norm of a matrix \f$ A \f$ is defined to be
0102   * \f[ \|A\|_2 = \max_x \frac{\|Ax\|_2}{\|x\|_2} \f]
0103   * where the maximum is over all vectors and the norm on the right is the
0104   * Euclidean vector norm. The norm equals the largest singular value, which is
0105   * the square root of the largest eigenvalue of the positive semi-definite
0106   * matrix \f$ A^*A \f$.
0107   *
0108   * The current implementation uses the eigenvalues of \f$ A^*A \f$, as computed
0109   * by SelfAdjointView::eigenvalues(), to compute the operator norm of a
0110   * matrix.  The SelfAdjointView class provides a better algorithm for
0111   * selfadjoint matrices.
0112   *
0113   * Example: \include MatrixBase_operatorNorm.cpp
0114   * Output: \verbinclude MatrixBase_operatorNorm.out
0115   *
0116   * \sa SelfAdjointView::eigenvalues(), SelfAdjointView::operatorNorm()
0117   */
0118 template<typename Derived>
0119 inline typename MatrixBase<Derived>::RealScalar
0120 MatrixBase<Derived>::operatorNorm() const
0121 {
0122   using std::sqrt;
0123   typename Derived::PlainObject m_eval(derived());
0124   // FIXME if it is really guaranteed that the eigenvalues are already sorted,
0125   // then we don't need to compute a maxCoeff() here, comparing the 1st and last ones is enough.
0126   return sqrt((m_eval*m_eval.adjoint())
0127                  .eval()
0128          .template selfadjointView<Lower>()
0129          .eigenvalues()
0130          .maxCoeff()
0131          );
0132 }
0133 
0134 /** \brief Computes the L2 operator norm
0135   * \returns Operator norm of the matrix.
0136   *
0137   * \eigenvalues_module
0138   * This function computes the L2 operator norm of a self-adjoint matrix. For a
0139   * self-adjoint matrix, the operator norm is the largest eigenvalue.
0140   *
0141   * The current implementation uses the eigenvalues of the matrix, as computed
0142   * by eigenvalues(), to compute the operator norm of the matrix.
0143   *
0144   * Example: \include SelfAdjointView_operatorNorm.cpp
0145   * Output: \verbinclude SelfAdjointView_operatorNorm.out
0146   *
0147   * \sa eigenvalues(), MatrixBase::operatorNorm()
0148   */
0149 template<typename MatrixType, unsigned int UpLo>
0150 EIGEN_DEVICE_FUNC inline typename SelfAdjointView<MatrixType, UpLo>::RealScalar
0151 SelfAdjointView<MatrixType, UpLo>::operatorNorm() const
0152 {
0153   return eigenvalues().cwiseAbs().maxCoeff();
0154 }
0155 
0156 } // end namespace Eigen
0157 
0158 #endif