zheevx.c
Go to the documentation of this file.
00001 /* zheevx.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 
00021 /* Subroutine */ int zheevx_(char *jobz, char *range, char *uplo, integer *n, 
00022         doublecomplex *a, integer *lda, doublereal *vl, doublereal *vu, 
00023         integer *il, integer *iu, doublereal *abstol, integer *m, doublereal *
00024         w, doublecomplex *z__, integer *ldz, doublecomplex *work, integer *
00025         lwork, doublereal *rwork, integer *iwork, integer *ifail, integer *
00026         info)
00027 {
00028     /* System generated locals */
00029     integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2;
00030     doublereal d__1, d__2;
00031 
00032     /* Builtin functions */
00033     double sqrt(doublereal);
00034 
00035     /* Local variables */
00036     integer i__, j, nb, jj;
00037     doublereal eps, vll, vuu, tmp1;
00038     integer indd, inde;
00039     doublereal anrm;
00040     integer imax;
00041     doublereal rmin, rmax;
00042     logical test;
00043     integer itmp1, indee;
00044     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00045             integer *);
00046     doublereal sigma;
00047     extern logical lsame_(char *, char *);
00048     integer iinfo;
00049     char order[1];
00050     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00051             doublereal *, integer *);
00052     logical lower, wantz;
00053     extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *, 
00054             doublecomplex *, integer *);
00055     extern doublereal dlamch_(char *);
00056     logical alleig, indeig;
00057     integer iscale, indibl;
00058     logical valeig;
00059     doublereal safmin;
00060     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00061             integer *, integer *);
00062     extern /* Subroutine */ int xerbla_(char *, integer *), zdscal_(
00063             integer *, doublereal *, doublecomplex *, integer *);
00064     doublereal abstll, bignum;
00065     extern doublereal zlanhe_(char *, char *, integer *, doublecomplex *, 
00066             integer *, doublereal *);
00067     integer indiwk, indisp, indtau;
00068     extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *, 
00069              integer *), dstebz_(char *, char *, integer *, doublereal *, 
00070             doublereal *, integer *, integer *, doublereal *, doublereal *, 
00071             doublereal *, integer *, integer *, doublereal *, integer *, 
00072             integer *, doublereal *, integer *, integer *);
00073     integer indrwk, indwrk;
00074     extern /* Subroutine */ int zhetrd_(char *, integer *, doublecomplex *, 
00075             integer *, doublereal *, doublereal *, doublecomplex *, 
00076             doublecomplex *, integer *, integer *);
00077     integer lwkmin;
00078     extern /* Subroutine */ int zlacpy_(char *, integer *, integer *, 
00079             doublecomplex *, integer *, doublecomplex *, integer *);
00080     integer llwork, nsplit;
00081     doublereal smlnum;
00082     extern /* Subroutine */ int zstein_(integer *, doublereal *, doublereal *, 
00083              integer *, doublereal *, integer *, integer *, doublecomplex *, 
00084             integer *, doublereal *, integer *, integer *, integer *);
00085     integer lwkopt;
00086     logical lquery;
00087     extern /* Subroutine */ int zsteqr_(char *, integer *, doublereal *, 
00088             doublereal *, doublecomplex *, integer *, doublereal *, integer *), zungtr_(char *, integer *, doublecomplex *, integer *, 
00089             doublecomplex *, doublecomplex *, integer *, integer *), 
00090             zunmtr_(char *, char *, char *, integer *, integer *, 
00091             doublecomplex *, integer *, doublecomplex *, doublecomplex *, 
00092             integer *, doublecomplex *, integer *, integer *);
00093 
00094 
00095 /*  -- LAPACK driver routine (version 3.2) -- */
00096 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00097 /*     November 2006 */
00098 
00099 /*     .. Scalar Arguments .. */
00100 /*     .. */
00101 /*     .. Array Arguments .. */
00102 /*     .. */
00103 
00104 /*  Purpose */
00105 /*  ======= */
00106 
00107 /*  ZHEEVX computes selected eigenvalues and, optionally, eigenvectors */
00108 /*  of a complex Hermitian matrix A.  Eigenvalues and eigenvectors can */
00109 /*  be selected by specifying either a range of values or a range of */
00110 /*  indices for the desired eigenvalues. */
00111 
00112 /*  Arguments */
00113 /*  ========= */
00114 
00115 /*  JOBZ    (input) CHARACTER*1 */
00116 /*          = 'N':  Compute eigenvalues only; */
00117 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00118 
00119 /*  RANGE   (input) CHARACTER*1 */
00120 /*          = 'A': all eigenvalues will be found. */
00121 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
00122 /*                 will be found. */
00123 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
00124 
00125 /*  UPLO    (input) CHARACTER*1 */
00126 /*          = 'U':  Upper triangle of A is stored; */
00127 /*          = 'L':  Lower triangle of A is stored. */
00128 
00129 /*  N       (input) INTEGER */
00130 /*          The order of the matrix A.  N >= 0. */
00131 
00132 /*  A       (input/output) COMPLEX*16 array, dimension (LDA, N) */
00133 /*          On entry, the Hermitian matrix A.  If UPLO = 'U', the */
00134 /*          leading N-by-N upper triangular part of A contains the */
00135 /*          upper triangular part of the matrix A.  If UPLO = 'L', */
00136 /*          the leading N-by-N lower triangular part of A contains */
00137 /*          the lower triangular part of the matrix A. */
00138 /*          On exit, the lower triangle (if UPLO='L') or the upper */
00139 /*          triangle (if UPLO='U') of A, including the diagonal, is */
00140 /*          destroyed. */
00141 
00142 /*  LDA     (input) INTEGER */
00143 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00144 
00145 /*  VL      (input) DOUBLE PRECISION */
00146 /*  VU      (input) DOUBLE PRECISION */
00147 /*          If RANGE='V', the lower and upper bounds of the interval to */
00148 /*          be searched for eigenvalues. VL < VU. */
00149 /*          Not referenced if RANGE = 'A' or 'I'. */
00150 
00151 /*  IL      (input) INTEGER */
00152 /*  IU      (input) INTEGER */
00153 /*          If RANGE='I', the indices (in ascending order) of the */
00154 /*          smallest and largest eigenvalues to be returned. */
00155 /*          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
00156 /*          Not referenced if RANGE = 'A' or 'V'. */
00157 
00158 /*  ABSTOL  (input) DOUBLE PRECISION */
00159 /*          The absolute error tolerance for the eigenvalues. */
00160 /*          An approximate eigenvalue is accepted as converged */
00161 /*          when it is determined to lie in an interval [a,b] */
00162 /*          of width less than or equal to */
00163 
00164 /*                  ABSTOL + EPS *   max( |a|,|b| ) , */
00165 
00166 /*          where EPS is the machine precision.  If ABSTOL is less than */
00167 /*          or equal to zero, then  EPS*|T|  will be used in its place, */
00168 /*          where |T| is the 1-norm of the tridiagonal matrix obtained */
00169 /*          by reducing A to tridiagonal form. */
00170 
00171 /*          Eigenvalues will be computed most accurately when ABSTOL is */
00172 /*          set to twice the underflow threshold 2*DLAMCH('S'), not zero. */
00173 /*          If this routine returns with INFO>0, indicating that some */
00174 /*          eigenvectors did not converge, try setting ABSTOL to */
00175 /*          2*DLAMCH('S'). */
00176 
00177 /*          See "Computing Small Singular Values of Bidiagonal Matrices */
00178 /*          with Guaranteed High Relative Accuracy," by Demmel and */
00179 /*          Kahan, LAPACK Working Note #3. */
00180 
00181 /*  M       (output) INTEGER */
00182 /*          The total number of eigenvalues found.  0 <= M <= N. */
00183 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
00184 
00185 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00186 /*          On normal exit, the first M elements contain the selected */
00187 /*          eigenvalues in ascending order. */
00188 
00189 /*  Z       (output) COMPLEX*16 array, dimension (LDZ, max(1,M)) */
00190 /*          If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
00191 /*          contain the orthonormal eigenvectors of the matrix A */
00192 /*          corresponding to the selected eigenvalues, with the i-th */
00193 /*          column of Z holding the eigenvector associated with W(i). */
00194 /*          If an eigenvector fails to converge, then that column of Z */
00195 /*          contains the latest approximation to the eigenvector, and the */
00196 /*          index of the eigenvector is returned in IFAIL. */
00197 /*          If JOBZ = 'N', then Z is not referenced. */
00198 /*          Note: the user must ensure that at least max(1,M) columns are */
00199 /*          supplied in the array Z; if RANGE = 'V', the exact value of M */
00200 /*          is not known in advance and an upper bound must be used. */
00201 
00202 /*  LDZ     (input) INTEGER */
00203 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00204 /*          JOBZ = 'V', LDZ >= max(1,N). */
00205 
00206 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00207 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00208 
00209 /*  LWORK   (input) INTEGER */
00210 /*          The length of the array WORK.  LWORK >= 1, when N <= 1; */
00211 /*          otherwise 2*N. */
00212 /*          For optimal efficiency, LWORK >= (NB+1)*N, */
00213 /*          where NB is the max of the blocksize for ZHETRD and for */
00214 /*          ZUNMTR as returned by ILAENV. */
00215 
00216 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00217 /*          only calculates the optimal size of the WORK array, returns */
00218 /*          this value as the first entry of the WORK array, and no error */
00219 /*          message related to LWORK is issued by XERBLA. */
00220 
00221 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (7*N) */
00222 
00223 /*  IWORK   (workspace) INTEGER array, dimension (5*N) */
00224 
00225 /*  IFAIL   (output) INTEGER array, dimension (N) */
00226 /*          If JOBZ = 'V', then if INFO = 0, the first M elements of */
00227 /*          IFAIL are zero.  If INFO > 0, then IFAIL contains the */
00228 /*          indices of the eigenvectors that failed to converge. */
00229 /*          If JOBZ = 'N', then IFAIL is not referenced. */
00230 
00231 /*  INFO    (output) INTEGER */
00232 /*          = 0:  successful exit */
00233 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00234 /*          > 0:  if INFO = i, then i eigenvectors failed to converge. */
00235 /*                Their indices are stored in array IFAIL. */
00236 
00237 /*  ===================================================================== */
00238 
00239 /*     .. Parameters .. */
00240 /*     .. */
00241 /*     .. Local Scalars .. */
00242 /*     .. */
00243 /*     .. External Functions .. */
00244 /*     .. */
00245 /*     .. External Subroutines .. */
00246 /*     .. */
00247 /*     .. Intrinsic Functions .. */
00248 /*     .. */
00249 /*     .. Executable Statements .. */
00250 
00251 /*     Test the input parameters. */
00252 
00253     /* Parameter adjustments */
00254     a_dim1 = *lda;
00255     a_offset = 1 + a_dim1;
00256     a -= a_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     lower = lsame_(uplo, "L");
00268     wantz = lsame_(jobz, "V");
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 (! (wantz || lsame_(jobz, "N"))) {
00276         *info = -1;
00277     } else if (! (alleig || valeig || indeig)) {
00278         *info = -2;
00279     } else if (! (lower || lsame_(uplo, "U"))) {
00280         *info = -3;
00281     } else if (*n < 0) {
00282         *info = -4;
00283     } else if (*lda < max(1,*n)) {
00284         *info = -6;
00285     } else {
00286         if (valeig) {
00287             if (*n > 0 && *vu <= *vl) {
00288                 *info = -8;
00289             }
00290         } else if (indeig) {
00291             if (*il < 1 || *il > max(1,*n)) {
00292                 *info = -9;
00293             } else if (*iu < min(*n,*il) || *iu > *n) {
00294                 *info = -10;
00295             }
00296         }
00297     }
00298     if (*info == 0) {
00299         if (*ldz < 1 || wantz && *ldz < *n) {
00300             *info = -15;
00301         }
00302     }
00303 
00304     if (*info == 0) {
00305         if (*n <= 1) {
00306             lwkmin = 1;
00307             work[1].r = (doublereal) lwkmin, work[1].i = 0.;
00308         } else {
00309             lwkmin = *n << 1;
00310             nb = ilaenv_(&c__1, "ZHETRD", uplo, n, &c_n1, &c_n1, &c_n1);
00311 /* Computing MAX */
00312             i__1 = nb, i__2 = ilaenv_(&c__1, "ZUNMTR", uplo, n, &c_n1, &c_n1, 
00313                     &c_n1);
00314             nb = max(i__1,i__2);
00315 /* Computing MAX */
00316             i__1 = 1, i__2 = (nb + 1) * *n;
00317             lwkopt = max(i__1,i__2);
00318             work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00319         }
00320 
00321 /* Computing MAX */
00322         i__1 = 1, i__2 = *n << 1;
00323         if (*lwork < max(i__1,i__2) && ! lquery) {
00324             *info = -17;
00325         }
00326     }
00327 
00328     if (*info != 0) {
00329         i__1 = -(*info);
00330         xerbla_("ZHEEVX", &i__1);
00331         return 0;
00332     } else if (lquery) {
00333         return 0;
00334     }
00335 
00336 /*     Quick return if possible */
00337 
00338     *m = 0;
00339     if (*n == 0) {
00340         return 0;
00341     }
00342 
00343     if (*n == 1) {
00344         if (alleig || indeig) {
00345             *m = 1;
00346             i__1 = a_dim1 + 1;
00347             w[1] = a[i__1].r;
00348         } else if (valeig) {
00349             i__1 = a_dim1 + 1;
00350             i__2 = a_dim1 + 1;
00351             if (*vl < a[i__1].r && *vu >= a[i__2].r) {
00352                 *m = 1;
00353                 i__1 = a_dim1 + 1;
00354                 w[1] = a[i__1].r;
00355             }
00356         }
00357         if (wantz) {
00358             i__1 = z_dim1 + 1;
00359             z__[i__1].r = 1., z__[i__1].i = 0.;
00360         }
00361         return 0;
00362     }
00363 
00364 /*     Get machine constants. */
00365 
00366     safmin = dlamch_("Safe minimum");
00367     eps = dlamch_("Precision");
00368     smlnum = safmin / eps;
00369     bignum = 1. / smlnum;
00370     rmin = sqrt(smlnum);
00371 /* Computing MIN */
00372     d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
00373     rmax = min(d__1,d__2);
00374 
00375 /*     Scale matrix to allowable range, if necessary. */
00376 
00377     iscale = 0;
00378     abstll = *abstol;
00379     if (valeig) {
00380         vll = *vl;
00381         vuu = *vu;
00382     }
00383     anrm = zlanhe_("M", uplo, n, &a[a_offset], lda, &rwork[1]);
00384     if (anrm > 0. && anrm < rmin) {
00385         iscale = 1;
00386         sigma = rmin / anrm;
00387     } else if (anrm > rmax) {
00388         iscale = 1;
00389         sigma = rmax / anrm;
00390     }
00391     if (iscale == 1) {
00392         if (lower) {
00393             i__1 = *n;
00394             for (j = 1; j <= i__1; ++j) {
00395                 i__2 = *n - j + 1;
00396                 zdscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1);
00397 /* L10: */
00398             }
00399         } else {
00400             i__1 = *n;
00401             for (j = 1; j <= i__1; ++j) {
00402                 zdscal_(&j, &sigma, &a[j * a_dim1 + 1], &c__1);
00403 /* L20: */
00404             }
00405         }
00406         if (*abstol > 0.) {
00407             abstll = *abstol * sigma;
00408         }
00409         if (valeig) {
00410             vll = *vl * sigma;
00411             vuu = *vu * sigma;
00412         }
00413     }
00414 
00415 /*     Call ZHETRD to reduce Hermitian matrix to tridiagonal form. */
00416 
00417     indd = 1;
00418     inde = indd + *n;
00419     indrwk = inde + *n;
00420     indtau = 1;
00421     indwrk = indtau + *n;
00422     llwork = *lwork - indwrk + 1;
00423     zhetrd_(uplo, n, &a[a_offset], lda, &rwork[indd], &rwork[inde], &work[
00424             indtau], &work[indwrk], &llwork, &iinfo);
00425 
00426 /*     If all eigenvalues are desired and ABSTOL is less than or equal to */
00427 /*     zero, then call DSTERF or ZUNGTR and ZSTEQR.  If this fails for */
00428 /*     some eigenvalue, then try DSTEBZ. */
00429 
00430     test = FALSE_;
00431     if (indeig) {
00432         if (*il == 1 && *iu == *n) {
00433             test = TRUE_;
00434         }
00435     }
00436     if ((alleig || test) && *abstol <= 0.) {
00437         dcopy_(n, &rwork[indd], &c__1, &w[1], &c__1);
00438         indee = indrwk + (*n << 1);
00439         if (! wantz) {
00440             i__1 = *n - 1;
00441             dcopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
00442             dsterf_(n, &w[1], &rwork[indee], info);
00443         } else {
00444             zlacpy_("A", n, n, &a[a_offset], lda, &z__[z_offset], ldz);
00445             zungtr_(uplo, n, &z__[z_offset], ldz, &work[indtau], &work[indwrk]
00446 , &llwork, &iinfo);
00447             i__1 = *n - 1;
00448             dcopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
00449             zsteqr_(jobz, n, &w[1], &rwork[indee], &z__[z_offset], ldz, &
00450                     rwork[indrwk], info);
00451             if (*info == 0) {
00452                 i__1 = *n;
00453                 for (i__ = 1; i__ <= i__1; ++i__) {
00454                     ifail[i__] = 0;
00455 /* L30: */
00456                 }
00457             }
00458         }
00459         if (*info == 0) {
00460             *m = *n;
00461             goto L40;
00462         }
00463         *info = 0;
00464     }
00465 
00466 /*     Otherwise, call DSTEBZ and, if eigenvectors are desired, ZSTEIN. */
00467 
00468     if (wantz) {
00469         *(unsigned char *)order = 'B';
00470     } else {
00471         *(unsigned char *)order = 'E';
00472     }
00473     indibl = 1;
00474     indisp = indibl + *n;
00475     indiwk = indisp + *n;
00476     dstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &rwork[indd], &
00477             rwork[inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &
00478             rwork[indrwk], &iwork[indiwk], info);
00479 
00480     if (wantz) {
00481         zstein_(n, &rwork[indd], &rwork[inde], m, &w[1], &iwork[indibl], &
00482                 iwork[indisp], &z__[z_offset], ldz, &rwork[indrwk], &iwork[
00483                 indiwk], &ifail[1], info);
00484 
00485 /*        Apply unitary matrix used in reduction to tridiagonal */
00486 /*        form to eigenvectors returned by ZSTEIN. */
00487 
00488         zunmtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[
00489                 z_offset], ldz, &work[indwrk], &llwork, &iinfo);
00490     }
00491 
00492 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00493 
00494 L40:
00495     if (iscale == 1) {
00496         if (*info == 0) {
00497             imax = *m;
00498         } else {
00499             imax = *info - 1;
00500         }
00501         d__1 = 1. / sigma;
00502         dscal_(&imax, &d__1, &w[1], &c__1);
00503     }
00504 
00505 /*     If eigenvalues are not in order, then sort them, along with */
00506 /*     eigenvectors. */
00507 
00508     if (wantz) {
00509         i__1 = *m - 1;
00510         for (j = 1; j <= i__1; ++j) {
00511             i__ = 0;
00512             tmp1 = w[j];
00513             i__2 = *m;
00514             for (jj = j + 1; jj <= i__2; ++jj) {
00515                 if (w[jj] < tmp1) {
00516                     i__ = jj;
00517                     tmp1 = w[jj];
00518                 }
00519 /* L50: */
00520             }
00521 
00522             if (i__ != 0) {
00523                 itmp1 = iwork[indibl + i__ - 1];
00524                 w[i__] = w[j];
00525                 iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
00526                 w[j] = tmp1;
00527                 iwork[indibl + j - 1] = itmp1;
00528                 zswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], 
00529                          &c__1);
00530                 if (*info != 0) {
00531                     itmp1 = ifail[i__];
00532                     ifail[i__] = ifail[j];
00533                     ifail[j] = itmp1;
00534                 }
00535             }
00536 /* L60: */
00537         }
00538     }
00539 
00540 /*     Set WORK(1) to optimal complex workspace size. */
00541 
00542     work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00543 
00544     return 0;
00545 
00546 /*     End of ZHEEVX */
00547 
00548 } /* zheevx_ */


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