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