chegv.c
Go to the documentation of this file.
00001 /* chegv.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static complex c_b1 = {1.f,0.f};
00019 static integer c__1 = 1;
00020 static integer c_n1 = -1;
00021 
00022 /* Subroutine */ int chegv_(integer *itype, char *jobz, char *uplo, integer *
00023         n, complex *a, integer *lda, complex *b, integer *ldb, real *w, 
00024         complex *work, integer *lwork, real *rwork, integer *info)
00025 {
00026     /* System generated locals */
00027     integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2;
00028 
00029     /* Local variables */
00030     integer nb, neig;
00031     extern /* Subroutine */ int cheev_(char *, char *, integer *, complex *, 
00032             integer *, real *, complex *, integer *, real *, integer *);
00033     extern logical lsame_(char *, char *);
00034     extern /* Subroutine */ int ctrmm_(char *, char *, char *, char *, 
00035             integer *, integer *, complex *, complex *, integer *, complex *, 
00036             integer *);
00037     char trans[1];
00038     extern /* Subroutine */ int ctrsm_(char *, char *, char *, char *, 
00039             integer *, integer *, complex *, complex *, integer *, complex *, 
00040             integer *);
00041     logical upper, wantz;
00042     extern /* Subroutine */ int chegst_(integer *, char *, integer *, complex 
00043             *, integer *, complex *, integer *, integer *);
00044     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00045             integer *, integer *);
00046     extern /* Subroutine */ int xerbla_(char *, integer *), cpotrf_(
00047             char *, integer *, complex *, integer *, integer *);
00048     integer lwkopt;
00049     logical lquery;
00050 
00051 
00052 /*  -- LAPACK driver routine (version 3.2) -- */
00053 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00054 /*     November 2006 */
00055 
00056 /*     .. Scalar Arguments .. */
00057 /*     .. */
00058 /*     .. Array Arguments .. */
00059 /*     .. */
00060 
00061 /*  Purpose */
00062 /*  ======= */
00063 
00064 /*  CHEGV computes all the eigenvalues, and optionally, the eigenvectors */
00065 /*  of a complex generalized Hermitian-definite eigenproblem, of the form */
00066 /*  A*x=(lambda)*B*x,  A*Bx=(lambda)*x,  or B*A*x=(lambda)*x. */
00067 /*  Here A and B are assumed to be Hermitian and B is also */
00068 /*  positive definite. */
00069 
00070 /*  Arguments */
00071 /*  ========= */
00072 
00073 /*  ITYPE   (input) INTEGER */
00074 /*          Specifies the problem type to be solved: */
00075 /*          = 1:  A*x = (lambda)*B*x */
00076 /*          = 2:  A*B*x = (lambda)*x */
00077 /*          = 3:  B*A*x = (lambda)*x */
00078 
00079 /*  JOBZ    (input) CHARACTER*1 */
00080 /*          = 'N':  Compute eigenvalues only; */
00081 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00082 
00083 /*  UPLO    (input) CHARACTER*1 */
00084 /*          = 'U':  Upper triangles of A and B are stored; */
00085 /*          = 'L':  Lower triangles of A and B are stored. */
00086 
00087 /*  N       (input) INTEGER */
00088 /*          The order of the matrices A and B.  N >= 0. */
00089 
00090 /*  A       (input/output) COMPLEX array, dimension (LDA, N) */
00091 /*          On entry, the Hermitian matrix A.  If UPLO = 'U', the */
00092 /*          leading N-by-N upper triangular part of A contains the */
00093 /*          upper triangular part of the matrix A.  If UPLO = 'L', */
00094 /*          the leading N-by-N lower triangular part of A contains */
00095 /*          the lower triangular part of the matrix A. */
00096 
00097 /*          On exit, if JOBZ = 'V', then if INFO = 0, A contains the */
00098 /*          matrix Z of eigenvectors.  The eigenvectors are normalized */
00099 /*          as follows: */
00100 /*          if ITYPE = 1 or 2, Z**H*B*Z = I; */
00101 /*          if ITYPE = 3, Z**H*inv(B)*Z = I. */
00102 /*          If JOBZ = 'N', then on exit the upper triangle (if UPLO='U') */
00103 /*          or the lower triangle (if UPLO='L') of A, including the */
00104 /*          diagonal, is destroyed. */
00105 
00106 /*  LDA     (input) INTEGER */
00107 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00108 
00109 /*  B       (input/output) COMPLEX array, dimension (LDB, N) */
00110 /*          On entry, the Hermitian positive definite matrix B. */
00111 /*          If UPLO = 'U', the leading N-by-N upper triangular part of B */
00112 /*          contains the upper triangular part of the matrix B. */
00113 /*          If UPLO = 'L', the leading N-by-N lower triangular part of B */
00114 /*          contains the lower triangular part of the matrix B. */
00115 
00116 /*          On exit, if INFO <= N, the part of B containing the matrix is */
00117 /*          overwritten by the triangular factor U or L from the Cholesky */
00118 /*          factorization B = U**H*U or B = L*L**H. */
00119 
00120 /*  LDB     (input) INTEGER */
00121 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00122 
00123 /*  W       (output) REAL array, dimension (N) */
00124 /*          If INFO = 0, the eigenvalues in ascending order. */
00125 
00126 /*  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK)) */
00127 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00128 
00129 /*  LWORK   (input) INTEGER */
00130 /*          The length of the array WORK.  LWORK >= max(1,2*N-1). */
00131 /*          For optimal efficiency, LWORK >= (NB+1)*N, */
00132 /*          where NB is the blocksize for CHETRD returned by ILAENV. */
00133 
00134 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00135 /*          only calculates the optimal size of the WORK array, returns */
00136 /*          this value as the first entry of the WORK array, and no error */
00137 /*          message related to LWORK is issued by XERBLA. */
00138 
00139 /*  RWORK   (workspace) REAL array, dimension (max(1, 3*N-2)) */
00140 
00141 /*  INFO    (output) INTEGER */
00142 /*          = 0:  successful exit */
00143 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00144 /*          > 0:  CPOTRF or CHEEV returned an error code: */
00145 /*             <= N:  if INFO = i, CHEEV failed to converge; */
00146 /*                    i off-diagonal elements of an intermediate */
00147 /*                    tridiagonal form did not converge to zero; */
00148 /*             > N:   if INFO = N + i, for 1 <= i <= N, then the leading */
00149 /*                    minor of order i of B is not positive definite. */
00150 /*                    The factorization of B could not be completed and */
00151 /*                    no eigenvalues or eigenvectors were computed. */
00152 
00153 /*  ===================================================================== */
00154 
00155 /*     .. Parameters .. */
00156 /*     .. */
00157 /*     .. Local Scalars .. */
00158 /*     .. */
00159 /*     .. External Functions .. */
00160 /*     .. */
00161 /*     .. External Subroutines .. */
00162 /*     .. */
00163 /*     .. Intrinsic Functions .. */
00164 /*     .. */
00165 /*     .. Executable Statements .. */
00166 
00167 /*     Test the input parameters. */
00168 
00169     /* Parameter adjustments */
00170     a_dim1 = *lda;
00171     a_offset = 1 + a_dim1;
00172     a -= a_offset;
00173     b_dim1 = *ldb;
00174     b_offset = 1 + b_dim1;
00175     b -= b_offset;
00176     --w;
00177     --work;
00178     --rwork;
00179 
00180     /* Function Body */
00181     wantz = lsame_(jobz, "V");
00182     upper = lsame_(uplo, "U");
00183     lquery = *lwork == -1;
00184 
00185     *info = 0;
00186     if (*itype < 1 || *itype > 3) {
00187         *info = -1;
00188     } else if (! (wantz || lsame_(jobz, "N"))) {
00189         *info = -2;
00190     } else if (! (upper || lsame_(uplo, "L"))) {
00191         *info = -3;
00192     } else if (*n < 0) {
00193         *info = -4;
00194     } else if (*lda < max(1,*n)) {
00195         *info = -6;
00196     } else if (*ldb < max(1,*n)) {
00197         *info = -8;
00198     }
00199 
00200     if (*info == 0) {
00201         nb = ilaenv_(&c__1, "CHETRD", uplo, n, &c_n1, &c_n1, &c_n1);
00202 /* Computing MAX */
00203         i__1 = 1, i__2 = (nb + 1) * *n;
00204         lwkopt = max(i__1,i__2);
00205         work[1].r = (real) lwkopt, work[1].i = 0.f;
00206 
00207 /* Computing MAX */
00208         i__1 = 1, i__2 = (*n << 1) - 1;
00209         if (*lwork < max(i__1,i__2) && ! lquery) {
00210             *info = -11;
00211         }
00212     }
00213 
00214     if (*info != 0) {
00215         i__1 = -(*info);
00216         xerbla_("CHEGV ", &i__1);
00217         return 0;
00218     } else if (lquery) {
00219         return 0;
00220     }
00221 
00222 /*     Quick return if possible */
00223 
00224     if (*n == 0) {
00225         return 0;
00226     }
00227 
00228 /*     Form a Cholesky factorization of B. */
00229 
00230     cpotrf_(uplo, n, &b[b_offset], ldb, info);
00231     if (*info != 0) {
00232         *info = *n + *info;
00233         return 0;
00234     }
00235 
00236 /*     Transform problem to standard eigenvalue problem and solve. */
00237 
00238     chegst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info);
00239     cheev_(jobz, uplo, n, &a[a_offset], lda, &w[1], &work[1], lwork, &rwork[1]
00240 , info);
00241 
00242     if (wantz) {
00243 
00244 /*        Backtransform eigenvectors to the original problem. */
00245 
00246         neig = *n;
00247         if (*info > 0) {
00248             neig = *info - 1;
00249         }
00250         if (*itype == 1 || *itype == 2) {
00251 
00252 /*           For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
00253 /*           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
00254 
00255             if (upper) {
00256                 *(unsigned char *)trans = 'N';
00257             } else {
00258                 *(unsigned char *)trans = 'C';
00259             }
00260 
00261             ctrsm_("Left", uplo, trans, "Non-unit", n, &neig, &c_b1, &b[
00262                     b_offset], ldb, &a[a_offset], lda);
00263 
00264         } else if (*itype == 3) {
00265 
00266 /*           For B*A*x=(lambda)*x; */
00267 /*           backtransform eigenvectors: x = L*y or U'*y */
00268 
00269             if (upper) {
00270                 *(unsigned char *)trans = 'C';
00271             } else {
00272                 *(unsigned char *)trans = 'N';
00273             }
00274 
00275             ctrmm_("Left", uplo, trans, "Non-unit", n, &neig, &c_b1, &b[
00276                     b_offset], ldb, &a[a_offset], lda);
00277         }
00278     }
00279 
00280     work[1].r = (real) lwkopt, work[1].i = 0.f;
00281 
00282     return 0;
00283 
00284 /*     End of CHEGV */
00285 
00286 } /* chegv_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:28