zhegvx.c
Go to the documentation of this file.
00001 /* zhegvx.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 zhegvx_(integer *itype, char *jobz, char *range, char *
00023         uplo, integer *n, doublecomplex *a, integer *lda, doublecomplex *b, 
00024         integer *ldb, doublereal *vl, doublereal *vu, integer *il, integer *
00025         iu, doublereal *abstol, integer *m, doublereal *w, doublecomplex *z__, 
00026          integer *ldz, doublecomplex *work, integer *lwork, doublereal *rwork, 
00027          integer *iwork, integer *ifail, integer *info)
00028 {
00029     /* System generated locals */
00030     integer a_dim1, a_offset, b_dim1, b_offset, z_dim1, z_offset, i__1, i__2;
00031 
00032     /* Local variables */
00033     integer nb;
00034     extern logical lsame_(char *, char *);
00035     char trans[1];
00036     logical upper, wantz;
00037     extern /* Subroutine */ int ztrmm_(char *, char *, char *, char *, 
00038             integer *, integer *, doublecomplex *, doublecomplex *, integer *, 
00039              doublecomplex *, integer *), 
00040             ztrsm_(char *, char *, char *, char *, integer *, integer *, 
00041             doublecomplex *, doublecomplex *, integer *, doublecomplex *, 
00042             integer *);
00043     logical alleig, indeig, valeig;
00044     extern /* Subroutine */ int xerbla_(char *, 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 *), zheevx_(char *, char *, char *, integer *, 
00049             doublecomplex *, integer *, doublereal *, doublereal *, integer *, 
00050              integer *, doublereal *, integer *, doublereal *, doublecomplex *
00051 , integer *, doublecomplex *, integer *, doublereal *, integer *, 
00052             integer *, integer *);
00053     integer lwkopt;
00054     logical lquery;
00055     extern /* Subroutine */ int zpotrf_(char *, integer *, doublecomplex *, 
00056             integer *, integer *);
00057 
00058 
00059 /*  -- LAPACK driver routine (version 3.2) -- */
00060 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00061 /*     November 2006 */
00062 
00063 /*     .. Scalar Arguments .. */
00064 /*     .. */
00065 /*     .. Array Arguments .. */
00066 /*     .. */
00067 
00068 /*  Purpose */
00069 /*  ======= */
00070 
00071 /*  ZHEGVX computes selected eigenvalues, and optionally, eigenvectors */
00072 /*  of a complex generalized Hermitian-definite eigenproblem, of the form */
00073 /*  A*x=(lambda)*B*x,  A*Bx=(lambda)*x,  or B*A*x=(lambda)*x.  Here A and */
00074 /*  B are assumed to be Hermitian and B is also positive definite. */
00075 /*  Eigenvalues and eigenvectors can be selected by specifying either a */
00076 /*  range of values or a range of indices for the desired eigenvalues. */
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 /*  RANGE   (input) CHARACTER*1 */
00092 /*          = 'A': all eigenvalues will be found. */
00093 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
00094 /*                 will be found. */
00095 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
00096 /* * */
00097 /*  UPLO    (input) CHARACTER*1 */
00098 /*          = 'U':  Upper triangles of A and B are stored; */
00099 /*          = 'L':  Lower triangles of A and B are stored. */
00100 
00101 /*  N       (input) INTEGER */
00102 /*          The order of the matrices A and B.  N >= 0. */
00103 
00104 /*  A       (input/output) COMPLEX*16 array, dimension (LDA, N) */
00105 /*          On entry, the Hermitian matrix A.  If UPLO = 'U', the */
00106 /*          leading N-by-N upper triangular part of A contains the */
00107 /*          upper triangular part of the matrix A.  If UPLO = 'L', */
00108 /*          the leading N-by-N lower triangular part of A contains */
00109 /*          the lower triangular part of the matrix A. */
00110 
00111 /*          On exit,  the lower triangle (if UPLO='L') or the upper */
00112 /*          triangle (if UPLO='U') of A, including the diagonal, is */
00113 /*          destroyed. */
00114 
00115 /*  LDA     (input) INTEGER */
00116 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00117 
00118 /*  B       (input/output) COMPLEX*16 array, dimension (LDB, N) */
00119 /*          On entry, the Hermitian matrix B.  If UPLO = 'U', the */
00120 /*          leading N-by-N upper triangular part of B contains the */
00121 /*          upper triangular part of the matrix B.  If UPLO = 'L', */
00122 /*          the leading N-by-N lower triangular part of B contains */
00123 /*          the lower triangular part of the matrix B. */
00124 
00125 /*          On exit, if INFO <= N, the part of B containing the matrix is */
00126 /*          overwritten by the triangular factor U or L from the Cholesky */
00127 /*          factorization B = U**H*U or B = L*L**H. */
00128 
00129 /*  LDB     (input) INTEGER */
00130 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00131 
00132 /*  VL      (input) DOUBLE PRECISION */
00133 /*  VU      (input) DOUBLE PRECISION */
00134 /*          If RANGE='V', the lower and upper bounds of the interval to */
00135 /*          be searched for eigenvalues. VL < VU. */
00136 /*          Not referenced if RANGE = 'A' or 'I'. */
00137 
00138 /*  IL      (input) INTEGER */
00139 /*  IU      (input) INTEGER */
00140 /*          If RANGE='I', the indices (in ascending order) of the */
00141 /*          smallest and largest eigenvalues to be returned. */
00142 /*          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
00143 /*          Not referenced if RANGE = 'A' or 'V'. */
00144 
00145 /*  ABSTOL  (input) DOUBLE PRECISION */
00146 /*          The absolute error tolerance for the eigenvalues. */
00147 /*          An approximate eigenvalue is accepted as converged */
00148 /*          when it is determined to lie in an interval [a,b] */
00149 /*          of width less than or equal to */
00150 
00151 /*                  ABSTOL + EPS *   max( |a|,|b| ) , */
00152 
00153 /*          where EPS is the machine precision.  If ABSTOL is less than */
00154 /*          or equal to zero, then  EPS*|T|  will be used in its place, */
00155 /*          where |T| is the 1-norm of the tridiagonal matrix obtained */
00156 /*          by reducing A to tridiagonal form. */
00157 
00158 /*          Eigenvalues will be computed most accurately when ABSTOL is */
00159 /*          set to twice the underflow threshold 2*DLAMCH('S'), not zero. */
00160 /*          If this routine returns with INFO>0, indicating that some */
00161 /*          eigenvectors did not converge, try setting ABSTOL to */
00162 /*          2*DLAMCH('S'). */
00163 
00164 /*  M       (output) INTEGER */
00165 /*          The total number of eigenvalues found.  0 <= M <= N. */
00166 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
00167 
00168 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00169 /*          The first M elements contain the selected */
00170 /*          eigenvalues in ascending order. */
00171 
00172 /*  Z       (output) COMPLEX*16 array, dimension (LDZ, max(1,M)) */
00173 /*          If JOBZ = 'N', then Z is not referenced. */
00174 /*          If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
00175 /*          contain the orthonormal eigenvectors of the matrix A */
00176 /*          corresponding to the selected eigenvalues, with the i-th */
00177 /*          column of Z holding the eigenvector associated with W(i). */
00178 /*          The eigenvectors are normalized as follows: */
00179 /*          if ITYPE = 1 or 2, Z**T*B*Z = I; */
00180 /*          if ITYPE = 3, Z**T*inv(B)*Z = I. */
00181 
00182 /*          If an eigenvector fails to converge, then that column of Z */
00183 /*          contains the latest approximation to the eigenvector, and the */
00184 /*          index of the eigenvector is returned in IFAIL. */
00185 /*          Note: the user must ensure that at least max(1,M) columns are */
00186 /*          supplied in the array Z; if RANGE = 'V', the exact value of M */
00187 /*          is not known in advance and an upper bound must be used. */
00188 
00189 /*  LDZ     (input) INTEGER */
00190 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00191 /*          JOBZ = 'V', LDZ >= max(1,N). */
00192 
00193 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00194 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00195 
00196 /*  LWORK   (input) INTEGER */
00197 /*          The length of the array WORK.  LWORK >= max(1,2*N). */
00198 /*          For optimal efficiency, LWORK >= (NB+1)*N, */
00199 /*          where NB is the blocksize for ZHETRD returned by ILAENV. */
00200 
00201 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00202 /*          only calculates the optimal size of the WORK array, returns */
00203 /*          this value as the first entry of the WORK array, and no error */
00204 /*          message related to LWORK is issued by XERBLA. */
00205 
00206 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (7*N) */
00207 
00208 /*  IWORK   (workspace) INTEGER array, dimension (5*N) */
00209 
00210 /*  IFAIL   (output) INTEGER array, dimension (N) */
00211 /*          If JOBZ = 'V', then if INFO = 0, the first M elements of */
00212 /*          IFAIL are zero.  If INFO > 0, then IFAIL contains the */
00213 /*          indices of the eigenvectors that failed to converge. */
00214 /*          If JOBZ = 'N', then IFAIL is not referenced. */
00215 
00216 /*  INFO    (output) INTEGER */
00217 /*          = 0:  successful exit */
00218 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00219 /*          > 0:  ZPOTRF or ZHEEVX returned an error code: */
00220 /*             <= N:  if INFO = i, ZHEEVX failed to converge; */
00221 /*                    i eigenvectors failed to converge.  Their indices */
00222 /*                    are stored in array IFAIL. */
00223 /*             > N:   if INFO = N + i, for 1 <= i <= N, then the leading */
00224 /*                    minor of order i of B is not positive definite. */
00225 /*                    The factorization of B could not be completed and */
00226 /*                    no eigenvalues or eigenvectors were computed. */
00227 
00228 /*  Further Details */
00229 /*  =============== */
00230 
00231 /*  Based on contributions by */
00232 /*     Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
00233 
00234 /*  ===================================================================== */
00235 
00236 /*     .. Parameters .. */
00237 /*     .. */
00238 /*     .. Local Scalars .. */
00239 /*     .. */
00240 /*     .. External Functions .. */
00241 /*     .. */
00242 /*     .. External Subroutines .. */
00243 /*     .. */
00244 /*     .. Intrinsic Functions .. */
00245 /*     .. */
00246 /*     .. Executable Statements .. */
00247 
00248 /*     Test the input parameters. */
00249 
00250     /* Parameter adjustments */
00251     a_dim1 = *lda;
00252     a_offset = 1 + a_dim1;
00253     a -= a_offset;
00254     b_dim1 = *ldb;
00255     b_offset = 1 + b_dim1;
00256     b -= b_offset;
00257     --w;
00258     z_dim1 = *ldz;
00259     z_offset = 1 + z_dim1;
00260     z__ -= z_offset;
00261     --work;
00262     --rwork;
00263     --iwork;
00264     --ifail;
00265 
00266     /* Function Body */
00267     wantz = lsame_(jobz, "V");
00268     upper = lsame_(uplo, "U");
00269     alleig = lsame_(range, "A");
00270     valeig = lsame_(range, "V");
00271     indeig = lsame_(range, "I");
00272     lquery = *lwork == -1;
00273 
00274     *info = 0;
00275     if (*itype < 1 || *itype > 3) {
00276         *info = -1;
00277     } else if (! (wantz || lsame_(jobz, "N"))) {
00278         *info = -2;
00279     } else if (! (alleig || valeig || indeig)) {
00280         *info = -3;
00281     } else if (! (upper || lsame_(uplo, "L"))) {
00282         *info = -4;
00283     } else if (*n < 0) {
00284         *info = -5;
00285     } else if (*lda < max(1,*n)) {
00286         *info = -7;
00287     } else if (*ldb < max(1,*n)) {
00288         *info = -9;
00289     } else {
00290         if (valeig) {
00291             if (*n > 0 && *vu <= *vl) {
00292                 *info = -11;
00293             }
00294         } else if (indeig) {
00295             if (*il < 1 || *il > max(1,*n)) {
00296                 *info = -12;
00297             } else if (*iu < min(*n,*il) || *iu > *n) {
00298                 *info = -13;
00299             }
00300         }
00301     }
00302     if (*info == 0) {
00303         if (*ldz < 1 || wantz && *ldz < *n) {
00304             *info = -18;
00305         }
00306     }
00307 
00308     if (*info == 0) {
00309         nb = ilaenv_(&c__1, "ZHETRD", uplo, n, &c_n1, &c_n1, &c_n1);
00310 /* Computing MAX */
00311         i__1 = 1, i__2 = (nb + 1) * *n;
00312         lwkopt = max(i__1,i__2);
00313         work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00314 
00315 /* Computing MAX */
00316         i__1 = 1, i__2 = *n << 1;
00317         if (*lwork < max(i__1,i__2) && ! lquery) {
00318             *info = -20;
00319         }
00320     }
00321 
00322     if (*info != 0) {
00323         i__1 = -(*info);
00324         xerbla_("ZHEGVX", &i__1);
00325         return 0;
00326     } else if (lquery) {
00327         return 0;
00328     }
00329 
00330 /*     Quick return if possible */
00331 
00332     *m = 0;
00333     if (*n == 0) {
00334         return 0;
00335     }
00336 
00337 /*     Form a Cholesky factorization of B. */
00338 
00339     zpotrf_(uplo, n, &b[b_offset], ldb, info);
00340     if (*info != 0) {
00341         *info = *n + *info;
00342         return 0;
00343     }
00344 
00345 /*     Transform problem to standard eigenvalue problem and solve. */
00346 
00347     zhegst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info);
00348     zheevx_(jobz, range, uplo, n, &a[a_offset], lda, vl, vu, il, iu, abstol, 
00349             m, &w[1], &z__[z_offset], ldz, &work[1], lwork, &rwork[1], &iwork[
00350             1], &ifail[1], info);
00351 
00352     if (wantz) {
00353 
00354 /*        Backtransform eigenvectors to the original problem. */
00355 
00356         if (*info > 0) {
00357             *m = *info - 1;
00358         }
00359         if (*itype == 1 || *itype == 2) {
00360 
00361 /*           For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
00362 /*           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
00363 
00364             if (upper) {
00365                 *(unsigned char *)trans = 'N';
00366             } else {
00367                 *(unsigned char *)trans = 'C';
00368             }
00369 
00370             ztrsm_("Left", uplo, trans, "Non-unit", n, m, &c_b1, &b[b_offset], 
00371                      ldb, &z__[z_offset], ldz);
00372 
00373         } else if (*itype == 3) {
00374 
00375 /*           For B*A*x=(lambda)*x; */
00376 /*           backtransform eigenvectors: x = L*y or U'*y */
00377 
00378             if (upper) {
00379                 *(unsigned char *)trans = 'C';
00380             } else {
00381                 *(unsigned char *)trans = 'N';
00382             }
00383 
00384             ztrmm_("Left", uplo, trans, "Non-unit", n, m, &c_b1, &b[b_offset], 
00385                      ldb, &z__[z_offset], ldz);
00386         }
00387     }
00388 
00389 /*     Set WORK(1) to optimal complex workspace size. */
00390 
00391     work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00392 
00393     return 0;
00394 
00395 /*     End of ZHEGVX */
00396 
00397 } /* zhegvx_ */


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