MatrixBaseEigenvalues.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
00006 //
00007 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_MATRIXBASEEIGENVALUES_H
00027 #define EIGEN_MATRIXBASEEIGENVALUES_H
00028 
00029 namespace internal {
00030 
00031 template<typename Derived, bool IsComplex>
00032 struct eigenvalues_selector
00033 {
00034   // this is the implementation for the case IsComplex = true
00035   static inline typename MatrixBase<Derived>::EigenvaluesReturnType const
00036   run(const MatrixBase<Derived>& m)
00037   {
00038     typedef typename Derived::PlainObject PlainObject;
00039     PlainObject m_eval(m);
00040     return ComplexEigenSolver<PlainObject>(m_eval, false).eigenvalues();
00041   }
00042 };
00043 
00044 template<typename Derived>
00045 struct eigenvalues_selector<Derived, false>
00046 {
00047   static inline typename MatrixBase<Derived>::EigenvaluesReturnType const
00048   run(const MatrixBase<Derived>& m)
00049   {
00050     typedef typename Derived::PlainObject PlainObject;
00051     PlainObject m_eval(m);
00052     return EigenSolver<PlainObject>(m_eval, false).eigenvalues();
00053   }
00054 };
00055 
00056 } // end namespace internal
00057 
00078 template<typename Derived>
00079 inline typename MatrixBase<Derived>::EigenvaluesReturnType
00080 MatrixBase<Derived>::eigenvalues() const
00081 {
00082   typedef typename internal::traits<Derived>::Scalar Scalar;
00083   return internal::eigenvalues_selector<Derived, NumTraits<Scalar>::IsComplex>::run(derived());
00084 }
00085 
00100 template<typename MatrixType, unsigned int UpLo> 
00101 inline typename SelfAdjointView<MatrixType, UpLo>::EigenvaluesReturnType
00102 SelfAdjointView<MatrixType, UpLo>::eigenvalues() const
00103 {
00104   typedef typename SelfAdjointView<MatrixType, UpLo>::PlainObject PlainObject;
00105   PlainObject thisAsMatrix(*this);
00106   return SelfAdjointEigenSolver<PlainObject>(thisAsMatrix, false).eigenvalues();
00107 }
00108 
00109 
00110 
00133 template<typename Derived>
00134 inline typename MatrixBase<Derived>::RealScalar
00135 MatrixBase<Derived>::operatorNorm() const
00136 {
00137   typename Derived::PlainObject m_eval(derived());
00138   // FIXME if it is really guaranteed that the eigenvalues are already sorted,
00139   // then we don't need to compute a maxCoeff() here, comparing the 1st and last ones is enough.
00140   return internal::sqrt((m_eval*m_eval.adjoint())
00141                  .eval()
00142                  .template selfadjointView<Lower>()
00143                  .eigenvalues()
00144                  .maxCoeff()
00145                  );
00146 }
00147 
00163 template<typename MatrixType, unsigned int UpLo>
00164 inline typename SelfAdjointView<MatrixType, UpLo>::RealScalar
00165 SelfAdjointView<MatrixType, UpLo>::operatorNorm() const
00166 {
00167   return eigenvalues().cwiseAbs().maxCoeff();
00168 }
00169 
00170 #endif


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:57