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.

79 lines
2.2 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 "common.h"
  10. #include <Eigen/Eigenvalues>
  11. // computes an LU factorization of a general M-by-N matrix A using partial pivoting with row interchanges
  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 nb = ILAENV( 1, 'SSYTRD', UPLO, N, -1, -1, -1 )
  25. // LWKOPT = MAX( 1, ( NB+2 )*N )
  26. // WORK( 1 ) = LWKOPT
  27. // *
  28. // IF( LWORK.LT.MAX( 1, 3*N-1 ) .AND. .NOT.LQUERY )
  29. // $ INFO = -8
  30. // END IF
  31. // *
  32. // IF( INFO.NE.0 ) THEN
  33. // CALL XERBLA( 'SSYEV ', -INFO )
  34. // RETURN
  35. // ELSE IF( LQUERY ) THEN
  36. // RETURN
  37. // END IF
  38. if(*info!=0)
  39. {
  40. int e = -*info;
  41. return xerbla_(SCALAR_SUFFIX_UP"SYEV ", &e, 6);
  42. }
  43. if(query_size)
  44. {
  45. *lwork = 0;
  46. return 0;
  47. }
  48. if(*n==0)
  49. return 0;
  50. PlainMatrixType mat(*n,*n);
  51. if(UPLO(*uplo)==UP) mat = matrix(a,*n,*n,*lda).adjoint();
  52. else mat = matrix(a,*n,*n,*lda);
  53. bool computeVectors = *jobz=='V' || *jobz=='v';
  54. SelfAdjointEigenSolver<PlainMatrixType> eig(mat,computeVectors?ComputeEigenvectors:EigenvaluesOnly);
  55. if(eig.info()==NoConvergence)
  56. {
  57. vector(w,*n).setZero();
  58. if(computeVectors)
  59. matrix(a,*n,*n,*lda).setIdentity();
  60. //*info = 1;
  61. return 0;
  62. }
  63. vector(w,*n) = eig.eigenvalues();
  64. if(computeVectors)
  65. matrix(a,*n,*n,*lda) = eig.eigenvectors();
  66. return 0;
  67. }