00001 /* zhegvd.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 00020 /* Subroutine */ int zhegvd_(integer *itype, char *jobz, char *uplo, integer * 00021 n, doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, 00022 doublereal *w, doublecomplex *work, integer *lwork, doublereal *rwork, 00023 integer *lrwork, integer *iwork, integer *liwork, integer *info) 00024 { 00025 /* System generated locals */ 00026 integer a_dim1, a_offset, b_dim1, b_offset, i__1; 00027 doublereal d__1, d__2; 00028 00029 /* Local variables */ 00030 integer lopt; 00031 extern logical lsame_(char *, char *); 00032 integer lwmin; 00033 char trans[1]; 00034 integer liopt; 00035 logical upper; 00036 integer lropt; 00037 logical 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 *), zheevd_(char *, char *, integer *, 00045 doublecomplex *, integer *, doublereal *, doublecomplex *, 00046 integer *, doublereal *, integer *, integer *, integer *, integer 00047 *); 00048 integer liwmin; 00049 extern /* Subroutine */ int zhegst_(integer *, char *, integer *, 00050 doublecomplex *, integer *, doublecomplex *, integer *, integer *); 00051 integer lrwmin; 00052 logical lquery; 00053 extern /* Subroutine */ int zpotrf_(char *, integer *, doublecomplex *, 00054 integer *, integer *); 00055 00056 00057 /* -- LAPACK driver routine (version 3.2) -- */ 00058 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00059 /* November 2006 */ 00060 00061 /* .. Scalar Arguments .. */ 00062 /* .. */ 00063 /* .. Array Arguments .. */ 00064 /* .. */ 00065 00066 /* Purpose */ 00067 /* ======= */ 00068 00069 /* ZHEGVD computes all the eigenvalues, and optionally, the eigenvectors */ 00070 /* of a complex generalized Hermitian-definite eigenproblem, of the form */ 00071 /* A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A and */ 00072 /* B are assumed to be Hermitian and B is also positive definite. */ 00073 /* If eigenvectors are desired, it uses a divide and conquer algorithm. */ 00074 00075 /* The divide and conquer algorithm makes very mild assumptions about */ 00076 /* floating point arithmetic. It will work on machines with a guard */ 00077 /* digit in add/subtract, or on those binary machines without guard */ 00078 /* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */ 00079 /* Cray-2. It could conceivably fail on hexadecimal or decimal machines */ 00080 /* without guard digits, but we know of none. */ 00081 00082 /* Arguments */ 00083 /* ========= */ 00084 00085 /* ITYPE (input) INTEGER */ 00086 /* Specifies the problem type to be solved: */ 00087 /* = 1: A*x = (lambda)*B*x */ 00088 /* = 2: A*B*x = (lambda)*x */ 00089 /* = 3: B*A*x = (lambda)*x */ 00090 00091 /* JOBZ (input) CHARACTER*1 */ 00092 /* = 'N': Compute eigenvalues only; */ 00093 /* = 'V': Compute eigenvalues and eigenvectors. */ 00094 00095 /* UPLO (input) CHARACTER*1 */ 00096 /* = 'U': Upper triangles of A and B are stored; */ 00097 /* = 'L': Lower triangles of A and B are stored. */ 00098 00099 /* N (input) INTEGER */ 00100 /* The order of the matrices A and B. N >= 0. */ 00101 00102 /* A (input/output) COMPLEX*16 array, dimension (LDA, N) */ 00103 /* On entry, the Hermitian matrix A. If UPLO = 'U', the */ 00104 /* leading N-by-N upper triangular part of A contains the */ 00105 /* upper triangular part of the matrix A. If UPLO = 'L', */ 00106 /* the leading N-by-N lower triangular part of A contains */ 00107 /* the lower triangular part of the matrix A. */ 00108 00109 /* On exit, if JOBZ = 'V', then if INFO = 0, A contains the */ 00110 /* matrix Z of eigenvectors. The eigenvectors are normalized */ 00111 /* as follows: */ 00112 /* if ITYPE = 1 or 2, Z**H*B*Z = I; */ 00113 /* if ITYPE = 3, Z**H*inv(B)*Z = I. */ 00114 /* If JOBZ = 'N', then on exit the upper triangle (if UPLO='U') */ 00115 /* or the lower triangle (if UPLO='L') of A, including the */ 00116 /* diagonal, is destroyed. */ 00117 00118 /* LDA (input) INTEGER */ 00119 /* The leading dimension of the array A. LDA >= max(1,N). */ 00120 00121 /* B (input/output) COMPLEX*16 array, dimension (LDB, N) */ 00122 /* On entry, the Hermitian matrix B. If UPLO = 'U', the */ 00123 /* leading N-by-N upper triangular part of B contains the */ 00124 /* upper triangular part of the matrix B. If UPLO = 'L', */ 00125 /* the leading N-by-N lower triangular part of B contains */ 00126 /* the lower triangular part of the matrix B. */ 00127 00128 /* On exit, if INFO <= N, the part of B containing the matrix is */ 00129 /* overwritten by the triangular factor U or L from the Cholesky */ 00130 /* factorization B = U**H*U or B = L*L**H. */ 00131 00132 /* LDB (input) INTEGER */ 00133 /* The leading dimension of the array B. LDB >= max(1,N). */ 00134 00135 /* W (output) DOUBLE PRECISION array, dimension (N) */ 00136 /* If INFO = 0, the eigenvalues in ascending order. */ 00137 00138 /* WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */ 00139 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ 00140 00141 /* LWORK (input) INTEGER */ 00142 /* The length of the array WORK. */ 00143 /* If N <= 1, LWORK >= 1. */ 00144 /* If JOBZ = 'N' and N > 1, LWORK >= N + 1. */ 00145 /* If JOBZ = 'V' and N > 1, LWORK >= 2*N + N**2. */ 00146 00147 /* If LWORK = -1, then a workspace query is assumed; the routine */ 00148 /* only calculates the optimal sizes of the WORK, RWORK and */ 00149 /* IWORK arrays, returns these values as the first entries of */ 00150 /* the WORK, RWORK and IWORK arrays, and no error message */ 00151 /* related to LWORK or LRWORK or LIWORK is issued by XERBLA. */ 00152 00153 /* RWORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LRWORK)) */ 00154 /* On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK. */ 00155 00156 /* LRWORK (input) INTEGER */ 00157 /* The dimension of the array RWORK. */ 00158 /* If N <= 1, LRWORK >= 1. */ 00159 /* If JOBZ = 'N' and N > 1, LRWORK >= N. */ 00160 /* If JOBZ = 'V' and N > 1, LRWORK >= 1 + 5*N + 2*N**2. */ 00161 00162 /* If LRWORK = -1, then a workspace query is assumed; the */ 00163 /* routine only calculates the optimal sizes of the WORK, RWORK */ 00164 /* and IWORK arrays, returns these values as the first entries */ 00165 /* of the WORK, RWORK and IWORK arrays, and no error message */ 00166 /* related to LWORK or LRWORK or LIWORK is issued by XERBLA. */ 00167 00168 /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ 00169 /* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */ 00170 00171 /* LIWORK (input) INTEGER */ 00172 /* The dimension of the array IWORK. */ 00173 /* If N <= 1, LIWORK >= 1. */ 00174 /* If JOBZ = 'N' and N > 1, LIWORK >= 1. */ 00175 /* If JOBZ = 'V' and N > 1, LIWORK >= 3 + 5*N. */ 00176 00177 /* If LIWORK = -1, then a workspace query is assumed; the */ 00178 /* routine only calculates the optimal sizes of the WORK, RWORK */ 00179 /* and IWORK arrays, returns these values as the first entries */ 00180 /* of the WORK, RWORK and IWORK arrays, and no error message */ 00181 /* related to LWORK or LRWORK or LIWORK is issued by XERBLA. */ 00182 00183 /* INFO (output) INTEGER */ 00184 /* = 0: successful exit */ 00185 /* < 0: if INFO = -i, the i-th argument had an illegal value */ 00186 /* > 0: ZPOTRF or ZHEEVD returned an error code: */ 00187 /* <= N: if INFO = i and JOBZ = 'N', then the algorithm */ 00188 /* failed to converge; i off-diagonal elements of an */ 00189 /* intermediate tridiagonal form did not converge to */ 00190 /* zero; */ 00191 /* if INFO = i and JOBZ = 'V', then the algorithm */ 00192 /* failed to compute an eigenvalue while working on */ 00193 /* the submatrix lying in rows and columns INFO/(N+1) */ 00194 /* through mod(INFO,N+1); */ 00195 /* > N: if INFO = N + i, for 1 <= i <= N, then the leading */ 00196 /* minor of order i of B is not positive definite. */ 00197 /* The factorization of B could not be completed and */ 00198 /* no eigenvalues or eigenvectors were computed. */ 00199 00200 /* Further Details */ 00201 /* =============== */ 00202 00203 /* Based on contributions by */ 00204 /* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */ 00205 00206 /* Modified so that no backsubstitution is performed if ZHEEVD fails to */ 00207 /* converge (NEIG in old code could be greater than N causing out of */ 00208 /* bounds reference to A - reported by Ralf Meyer). Also corrected the */ 00209 /* description of INFO and the test on ITYPE. Sven, 16 Feb 05. */ 00210 /* ===================================================================== */ 00211 00212 /* .. Parameters .. */ 00213 /* .. */ 00214 /* .. Local Scalars .. */ 00215 /* .. */ 00216 /* .. External Functions .. */ 00217 /* .. */ 00218 /* .. External Subroutines .. */ 00219 /* .. */ 00220 /* .. Intrinsic Functions .. */ 00221 /* .. */ 00222 /* .. Executable Statements .. */ 00223 00224 /* Test the input parameters. */ 00225 00226 /* Parameter adjustments */ 00227 a_dim1 = *lda; 00228 a_offset = 1 + a_dim1; 00229 a -= a_offset; 00230 b_dim1 = *ldb; 00231 b_offset = 1 + b_dim1; 00232 b -= b_offset; 00233 --w; 00234 --work; 00235 --rwork; 00236 --iwork; 00237 00238 /* Function Body */ 00239 wantz = lsame_(jobz, "V"); 00240 upper = lsame_(uplo, "U"); 00241 lquery = *lwork == -1 || *lrwork == -1 || *liwork == -1; 00242 00243 *info = 0; 00244 if (*n <= 1) { 00245 lwmin = 1; 00246 lrwmin = 1; 00247 liwmin = 1; 00248 } else if (wantz) { 00249 lwmin = (*n << 1) + *n * *n; 00250 lrwmin = *n * 5 + 1 + (*n << 1) * *n; 00251 liwmin = *n * 5 + 3; 00252 } else { 00253 lwmin = *n + 1; 00254 lrwmin = *n; 00255 liwmin = 1; 00256 } 00257 lopt = lwmin; 00258 lropt = lrwmin; 00259 liopt = liwmin; 00260 if (*itype < 1 || *itype > 3) { 00261 *info = -1; 00262 } else if (! (wantz || lsame_(jobz, "N"))) { 00263 *info = -2; 00264 } else if (! (upper || lsame_(uplo, "L"))) { 00265 *info = -3; 00266 } else if (*n < 0) { 00267 *info = -4; 00268 } else if (*lda < max(1,*n)) { 00269 *info = -6; 00270 } else if (*ldb < max(1,*n)) { 00271 *info = -8; 00272 } 00273 00274 if (*info == 0) { 00275 work[1].r = (doublereal) lopt, work[1].i = 0.; 00276 rwork[1] = (doublereal) lropt; 00277 iwork[1] = liopt; 00278 00279 if (*lwork < lwmin && ! lquery) { 00280 *info = -11; 00281 } else if (*lrwork < lrwmin && ! lquery) { 00282 *info = -13; 00283 } else if (*liwork < liwmin && ! lquery) { 00284 *info = -15; 00285 } 00286 } 00287 00288 if (*info != 0) { 00289 i__1 = -(*info); 00290 xerbla_("ZHEGVD", &i__1); 00291 return 0; 00292 } else if (lquery) { 00293 return 0; 00294 } 00295 00296 /* Quick return if possible */ 00297 00298 if (*n == 0) { 00299 return 0; 00300 } 00301 00302 /* Form a Cholesky factorization of B. */ 00303 00304 zpotrf_(uplo, n, &b[b_offset], ldb, info); 00305 if (*info != 0) { 00306 *info = *n + *info; 00307 return 0; 00308 } 00309 00310 /* Transform problem to standard eigenvalue problem and solve. */ 00311 00312 zhegst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info); 00313 zheevd_(jobz, uplo, n, &a[a_offset], lda, &w[1], &work[1], lwork, &rwork[ 00314 1], lrwork, &iwork[1], liwork, info); 00315 /* Computing MAX */ 00316 d__1 = (doublereal) lopt, d__2 = work[1].r; 00317 lopt = (integer) max(d__1,d__2); 00318 /* Computing MAX */ 00319 d__1 = (doublereal) lropt; 00320 lropt = (integer) max(d__1,rwork[1]); 00321 /* Computing MAX */ 00322 d__1 = (doublereal) liopt, d__2 = (doublereal) iwork[1]; 00323 liopt = (integer) max(d__1,d__2); 00324 00325 if (wantz && *info == 0) { 00326 00327 /* Backtransform eigenvectors to the original problem. */ 00328 00329 if (*itype == 1 || *itype == 2) { 00330 00331 /* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */ 00332 /* backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */ 00333 00334 if (upper) { 00335 *(unsigned char *)trans = 'N'; 00336 } else { 00337 *(unsigned char *)trans = 'C'; 00338 } 00339 00340 ztrsm_("Left", uplo, trans, "Non-unit", n, n, &c_b1, &b[b_offset], 00341 ldb, &a[a_offset], lda); 00342 00343 } else if (*itype == 3) { 00344 00345 /* For B*A*x=(lambda)*x; */ 00346 /* backtransform eigenvectors: x = L*y or U'*y */ 00347 00348 if (upper) { 00349 *(unsigned char *)trans = 'C'; 00350 } else { 00351 *(unsigned char *)trans = 'N'; 00352 } 00353 00354 ztrmm_("Left", uplo, trans, "Non-unit", n, n, &c_b1, &b[b_offset], 00355 ldb, &a[a_offset], lda); 00356 } 00357 } 00358 00359 work[1].r = (doublereal) lopt, work[1].i = 0.; 00360 rwork[1] = (doublereal) lropt; 00361 iwork[1] = liopt; 00362 00363 return 0; 00364 00365 /* End of ZHEGVD */ 00366 00367 } /* zhegvd_ */