00001 /* dsygv.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 integer c__1 = 1; 00019 static integer c_n1 = -1; 00020 static doublereal c_b16 = 1.; 00021 00022 /* Subroutine */ int dsygv_(integer *itype, char *jobz, char *uplo, integer * 00023 n, doublereal *a, integer *lda, doublereal *b, integer *ldb, 00024 doublereal *w, doublereal *work, integer *lwork, 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 logical lsame_(char *, char *); 00032 extern /* Subroutine */ int dtrmm_(char *, char *, char *, char *, 00033 integer *, integer *, doublereal *, doublereal *, integer *, 00034 doublereal *, integer *); 00035 char trans[1]; 00036 extern /* Subroutine */ int dtrsm_(char *, char *, char *, char *, 00037 integer *, integer *, doublereal *, doublereal *, integer *, 00038 doublereal *, integer *); 00039 logical upper; 00040 extern /* Subroutine */ int dsyev_(char *, char *, integer *, doublereal * 00041 , integer *, doublereal *, doublereal *, integer *, integer *); 00042 logical wantz; 00043 extern /* Subroutine */ int xerbla_(char *, integer *); 00044 extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 00045 integer *, integer *); 00046 extern /* Subroutine */ int dpotrf_(char *, integer *, doublereal *, 00047 integer *, integer *); 00048 integer lwkmin; 00049 extern /* Subroutine */ int dsygst_(integer *, char *, integer *, 00050 doublereal *, integer *, doublereal *, integer *, integer *); 00051 integer lwkopt; 00052 logical lquery; 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 /* DSYGV computes all the eigenvalues, and optionally, the eigenvectors */ 00068 /* of a real generalized symmetric-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 symmetric 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) DOUBLE PRECISION array, dimension (LDA, N) */ 00094 /* On entry, the symmetric 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**T*B*Z = I; */ 00104 /* if ITYPE = 3, Z**T*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) DOUBLE PRECISION array, dimension (LDB, N) */ 00113 /* On entry, the symmetric 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**T*U or B = L*L**T. */ 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) DOUBLE PRECISION 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,3*N-1). */ 00134 /* For optimal efficiency, LWORK >= (NB+2)*N, */ 00135 /* where NB is the blocksize for DSYTRD 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 /* INFO (output) INTEGER */ 00143 /* = 0: successful exit */ 00144 /* < 0: if INFO = -i, the i-th argument had an illegal value */ 00145 /* > 0: DPOTRF or DSYEV returned an error code: */ 00146 /* <= N: if INFO = i, DSYEV failed to converge; */ 00147 /* i off-diagonal elements of an intermediate */ 00148 /* tridiagonal form did not converge to zero; */ 00149 /* > N: if INFO = N + i, for 1 <= i <= N, then the leading */ 00150 /* minor of order i of B is not positive definite. */ 00151 /* The factorization of B could not be completed and */ 00152 /* no eigenvalues or eigenvectors were computed. */ 00153 00154 /* ===================================================================== */ 00155 00156 /* .. Parameters .. */ 00157 /* .. */ 00158 /* .. Local Scalars .. */ 00159 /* .. */ 00160 /* .. External Functions .. */ 00161 /* .. */ 00162 /* .. External Subroutines .. */ 00163 /* .. */ 00164 /* .. Intrinsic Functions .. */ 00165 /* .. */ 00166 /* .. Executable Statements .. */ 00167 00168 /* Test the input parameters. */ 00169 00170 /* Parameter adjustments */ 00171 a_dim1 = *lda; 00172 a_offset = 1 + a_dim1; 00173 a -= a_offset; 00174 b_dim1 = *ldb; 00175 b_offset = 1 + b_dim1; 00176 b -= b_offset; 00177 --w; 00178 --work; 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 /* Computing MAX */ 00202 i__1 = 1, i__2 = *n * 3 - 1; 00203 lwkmin = max(i__1,i__2); 00204 nb = ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1); 00205 /* Computing MAX */ 00206 i__1 = lwkmin, i__2 = (nb + 2) * *n; 00207 lwkopt = max(i__1,i__2); 00208 work[1] = (doublereal) lwkopt; 00209 00210 if (*lwork < lwkmin && ! lquery) { 00211 *info = -11; 00212 } 00213 } 00214 00215 if (*info != 0) { 00216 i__1 = -(*info); 00217 xerbla_("DSYGV ", &i__1); 00218 return 0; 00219 } else if (lquery) { 00220 return 0; 00221 } 00222 00223 /* Quick return if possible */ 00224 00225 if (*n == 0) { 00226 return 0; 00227 } 00228 00229 /* Form a Cholesky factorization of B. */ 00230 00231 dpotrf_(uplo, n, &b[b_offset], ldb, info); 00232 if (*info != 0) { 00233 *info = *n + *info; 00234 return 0; 00235 } 00236 00237 /* Transform problem to standard eigenvalue problem and solve. */ 00238 00239 dsygst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info); 00240 dsyev_(jobz, uplo, n, &a[a_offset], lda, &w[1], &work[1], lwork, 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 = 'T'; 00259 } 00260 00261 dtrsm_("Left", uplo, trans, "Non-unit", n, &neig, &c_b16, &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 = 'T'; 00271 } else { 00272 *(unsigned char *)trans = 'N'; 00273 } 00274 00275 dtrmm_("Left", uplo, trans, "Non-unit", n, &neig, &c_b16, &b[ 00276 b_offset], ldb, &a[a_offset], lda); 00277 } 00278 } 00279 00280 work[1] = (doublereal) lwkopt; 00281 return 0; 00282 00283 /* End of DSYGV */ 00284 00285 } /* dsygv_ */