eigenvalues.cpp
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) 2011 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #include "common.h"
00026 #include <Eigen/Eigenvalues>
00027 
00028 // computes an LU factorization of a general M-by-N matrix A using partial pivoting with row interchanges
00029 EIGEN_LAPACK_FUNC(syev,(char *jobz, char *uplo, int* n, Scalar* a, int *lda, Scalar* w, Scalar* /*work*/, int* lwork, int *info))
00030 {
00031   // TODO exploit the work buffer
00032   bool query_size = *lwork==-1;
00033   
00034   *info = 0;
00035         if(*jobz!='N' && *jobz!='V')                    *info = -1;
00036   else  if(UPLO(*uplo)==INVALID)                        *info = -2;
00037   else  if(*n<0)                                        *info = -3;
00038   else  if(*lda<std::max(1,*n))                         *info = -5;
00039   else  if((!query_size) && *lwork<std::max(1,3**n-1))  *info = -8;
00040   
00041 //   if(*info==0)
00042 //   {
00043 //     int nb = ILAENV( 1, 'SSYTRD', UPLO, N, -1, -1, -1 )
00044 //          LWKOPT = MAX( 1, ( NB+2 )*N )
00045 //          WORK( 1 ) = LWKOPT
00046 // *
00047 //          IF( LWORK.LT.MAX( 1, 3*N-1 ) .AND. .NOT.LQUERY )
00048 //      $      INFO = -8
00049 //       END IF
00050 // *
00051 //       IF( INFO.NE.0 ) THEN
00052 //          CALL XERBLA( 'SSYEV ', -INFO )
00053 //          RETURN
00054 //       ELSE IF( LQUERY ) THEN
00055 //          RETURN
00056 //       END IF
00057   
00058   if(*info!=0)
00059   {
00060     int e = -*info;
00061     return xerbla_(SCALAR_SUFFIX_UP"SYEV ", &e, 6);
00062   }
00063   
00064   if(query_size)
00065   {
00066     *lwork = 0;
00067     return 0;
00068   }
00069   
00070   if(*n==0)
00071     return 0;
00072   
00073   PlainMatrixType mat(*n,*n);
00074   if(UPLO(*uplo)==UP) mat = matrix(a,*n,*n,*lda).adjoint();
00075   else                mat = matrix(a,*n,*n,*lda);
00076   
00077   bool computeVectors = *jobz=='V' || *jobz=='v';
00078   SelfAdjointEigenSolver<PlainMatrixType> eig(mat,computeVectors?ComputeEigenvectors:EigenvaluesOnly);
00079   
00080   if(eig.info()==NoConvergence)
00081   {
00082     vector(w,*n).setZero();
00083     if(computeVectors)
00084       matrix(a,*n,*n,*lda).setIdentity();
00085     //*info = 1;
00086     return 0;
00087   }
00088   
00089   vector(w,*n) = eig.eigenvalues();
00090   if(computeVectors)
00091     matrix(a,*n,*n,*lda) = eig.eigenvectors();
00092   
00093   return 0;
00094 }


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