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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:37