You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #include "lapack_common.h"
  10. #include <Eigen/Eigenvalues>
  11. // computes eigen values and vectors of a general N-by-N matrix A
  12. EIGEN_LAPACK_FUNC(syev,(char *jobz, char *uplo, int* n, Scalar* a, int *lda, Scalar* w, Scalar* /*work*/, int* lwork, int *info))
  13. {
  14. // TODO exploit the work buffer
  15. bool query_size = *lwork==-1;
  16. *info = 0;
  17. if(*jobz!='N' && *jobz!='V') *info = -1;
  18. else if(UPLO(*uplo)==INVALID) *info = -2;
  19. else if(*n<0) *info = -3;
  20. else if(*lda<std::max(1,*n)) *info = -5;
  21. else if((!query_size) && *lwork<std::max(1,3**n-1)) *info = -8;
  22. if(*info!=0)
  23. {
  24. int e = -*info;
  25. return xerbla_(SCALAR_SUFFIX_UP"SYEV ", &e, 6);
  26. }
  27. if(query_size)
  28. {
  29. *lwork = 0;
  30. return 0;
  31. }
  32. if(*n==0)
  33. return 0;
  34. PlainMatrixType mat(*n,*n);
  35. if(UPLO(*uplo)==UP) mat = matrix(a,*n,*n,*lda).adjoint();
  36. else mat = matrix(a,*n,*n,*lda);
  37. bool computeVectors = *jobz=='V' || *jobz=='v';
  38. SelfAdjointEigenSolver<PlainMatrixType> eig(mat,computeVectors?ComputeEigenvectors:EigenvaluesOnly);
  39. if(eig.info()==NoConvergence)
  40. {
  41. make_vector(w,*n).setZero();
  42. if(computeVectors)
  43. matrix(a,*n,*n,*lda).setIdentity();
  44. //*info = 1;
  45. return 0;
  46. }
  47. make_vector(w,*n) = eig.eigenvalues();
  48. if(computeVectors)
  49. matrix(a,*n,*n,*lda) = eig.eigenvectors();
  50. return 0;
  51. }