2011-02-18 18:25:04 +08:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
// for linear algebra.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr>
|
|
|
|
//
|
2012-07-14 02:42:47 +08:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2011-02-18 18:25:04 +08:00
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include <Eigen/Eigenvalues>
|
|
|
|
|
|
|
|
// computes an LU factorization of a general M-by-N matrix A using partial pivoting with row interchanges
|
2011-02-23 16:32:55 +08:00
|
|
|
EIGEN_LAPACK_FUNC(syev,(char *jobz, char *uplo, int* n, Scalar* a, int *lda, Scalar* w, Scalar* /*work*/, int* lwork, int *info))
|
2011-02-18 18:25:04 +08:00
|
|
|
{
|
2011-02-23 16:32:55 +08:00
|
|
|
// TODO exploit the work buffer
|
2011-02-18 18:25:04 +08:00
|
|
|
bool query_size = *lwork==-1;
|
|
|
|
|
|
|
|
*info = 0;
|
|
|
|
if(*jobz!='N' && *jobz!='V') *info = -1;
|
|
|
|
else if(UPLO(*uplo)==INVALID) *info = -2;
|
|
|
|
else if(*n<0) *info = -3;
|
|
|
|
else if(*lda<std::max(1,*n)) *info = -5;
|
|
|
|
else if((!query_size) && *lwork<std::max(1,3**n-1)) *info = -8;
|
|
|
|
|
|
|
|
// if(*info==0)
|
|
|
|
// {
|
|
|
|
// int nb = ILAENV( 1, 'SSYTRD', UPLO, N, -1, -1, -1 )
|
|
|
|
// LWKOPT = MAX( 1, ( NB+2 )*N )
|
|
|
|
// WORK( 1 ) = LWKOPT
|
|
|
|
// *
|
|
|
|
// IF( LWORK.LT.MAX( 1, 3*N-1 ) .AND. .NOT.LQUERY )
|
|
|
|
// $ INFO = -8
|
|
|
|
// END IF
|
|
|
|
// *
|
|
|
|
// IF( INFO.NE.0 ) THEN
|
|
|
|
// CALL XERBLA( 'SSYEV ', -INFO )
|
|
|
|
// RETURN
|
|
|
|
// ELSE IF( LQUERY ) THEN
|
|
|
|
// RETURN
|
|
|
|
// END IF
|
|
|
|
|
|
|
|
if(*info!=0)
|
|
|
|
{
|
|
|
|
int e = -*info;
|
|
|
|
return xerbla_(SCALAR_SUFFIX_UP"SYEV ", &e, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(query_size)
|
|
|
|
{
|
|
|
|
*lwork = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*n==0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
PlainMatrixType mat(*n,*n);
|
|
|
|
if(UPLO(*uplo)==UP) mat = matrix(a,*n,*n,*lda).adjoint();
|
|
|
|
else mat = matrix(a,*n,*n,*lda);
|
|
|
|
|
|
|
|
bool computeVectors = *jobz=='V' || *jobz=='v';
|
|
|
|
SelfAdjointEigenSolver<PlainMatrixType> eig(mat,computeVectors?ComputeEigenvectors:EigenvaluesOnly);
|
|
|
|
|
|
|
|
if(eig.info()==NoConvergence)
|
|
|
|
{
|
2014-04-01 17:52:23 +08:00
|
|
|
make_vector(w,*n).setZero();
|
2011-02-18 18:25:04 +08:00
|
|
|
if(computeVectors)
|
|
|
|
matrix(a,*n,*n,*lda).setIdentity();
|
|
|
|
//*info = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-01 17:52:23 +08:00
|
|
|
make_vector(w,*n) = eig.eigenvalues();
|
2011-02-18 18:25:04 +08:00
|
|
|
if(computeVectors)
|
|
|
|
matrix(a,*n,*n,*lda) = eig.eigenvectors();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|