chpevx.c
Go to the documentation of this file.
00001 /* chpevx.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 
00020 /* Subroutine */ int chpevx_(char *jobz, char *range, char *uplo, integer *n, 
00021         complex *ap, real *vl, real *vu, integer *il, integer *iu, real *
00022         abstol, integer *m, real *w, complex *z__, integer *ldz, complex *
00023         work, real *rwork, integer *iwork, integer *ifail, integer *info)
00024 {
00025     /* System generated locals */
00026     integer z_dim1, z_offset, i__1, i__2;
00027     real r__1, r__2;
00028 
00029     /* Builtin functions */
00030     double sqrt(doublereal);
00031 
00032     /* Local variables */
00033     integer i__, j, jj;
00034     real eps, vll, vuu, tmp1;
00035     integer indd, inde;
00036     real anrm;
00037     integer imax;
00038     real rmin, rmax;
00039     logical test;
00040     integer itmp1, indee;
00041     real sigma;
00042     extern logical lsame_(char *, char *);
00043     integer iinfo;
00044     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
00045     char order[1];
00046     extern /* Subroutine */ int cswap_(integer *, complex *, integer *, 
00047             complex *, integer *), scopy_(integer *, real *, integer *, real *
00048 , integer *);
00049     logical wantz, alleig, indeig;
00050     integer iscale, indibl;
00051     extern doublereal clanhp_(char *, char *, integer *, complex *, real *);
00052     logical valeig;
00053     extern doublereal slamch_(char *);
00054     extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer 
00055             *);
00056     real safmin;
00057     extern /* Subroutine */ int xerbla_(char *, integer *);
00058     real abstll, bignum;
00059     integer indiwk, indisp, indtau;
00060     extern /* Subroutine */ int chptrd_(char *, integer *, complex *, real *, 
00061             real *, complex *, integer *), cstein_(integer *, real *, 
00062             real *, integer *, real *, integer *, integer *, complex *, 
00063             integer *, real *, integer *, integer *, integer *);
00064     integer indrwk, indwrk;
00065     extern /* Subroutine */ int csteqr_(char *, integer *, real *, real *, 
00066             complex *, integer *, real *, integer *), cupgtr_(char *, 
00067             integer *, complex *, complex *, complex *, integer *, complex *, 
00068             integer *), ssterf_(integer *, real *, real *, integer *);
00069     integer nsplit;
00070     extern /* Subroutine */ int cupmtr_(char *, char *, char *, integer *, 
00071             integer *, complex *, complex *, complex *, integer *, complex *, 
00072             integer *);
00073     real smlnum;
00074     extern /* Subroutine */ int sstebz_(char *, char *, integer *, real *, 
00075             real *, integer *, integer *, real *, real *, real *, integer *, 
00076             integer *, real *, integer *, integer *, real *, integer *, 
00077             integer *);
00078 
00079 
00080 /*  -- LAPACK driver routine (version 3.2) -- */
00081 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00082 /*     November 2006 */
00083 
00084 /*     .. Scalar Arguments .. */
00085 /*     .. */
00086 /*     .. Array Arguments .. */
00087 /*     .. */
00088 
00089 /*  Purpose */
00090 /*  ======= */
00091 
00092 /*  CHPEVX computes selected eigenvalues and, optionally, eigenvectors */
00093 /*  of a complex Hermitian matrix A in packed storage. */
00094 /*  Eigenvalues/vectors can be selected by specifying either a range of */
00095 /*  values or a range of indices for the desired eigenvalues. */
00096 
00097 /*  Arguments */
00098 /*  ========= */
00099 
00100 /*  JOBZ    (input) CHARACTER*1 */
00101 /*          = 'N':  Compute eigenvalues only; */
00102 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00103 
00104 /*  RANGE   (input) CHARACTER*1 */
00105 /*          = 'A': all eigenvalues will be found; */
00106 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
00107 /*                 will be found; */
00108 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
00109 
00110 /*  UPLO    (input) CHARACTER*1 */
00111 /*          = 'U':  Upper triangle of A is stored; */
00112 /*          = 'L':  Lower triangle of A is stored. */
00113 
00114 /*  N       (input) INTEGER */
00115 /*          The order of the matrix A.  N >= 0. */
00116 
00117 /*  AP      (input/output) COMPLEX array, dimension (N*(N+1)/2) */
00118 /*          On entry, the upper or lower triangle of the Hermitian matrix */
00119 /*          A, packed columnwise in a linear array.  The j-th column of A */
00120 /*          is stored in the array AP as follows: */
00121 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00122 /*          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
00123 
00124 /*          On exit, AP is overwritten by values generated during the */
00125 /*          reduction to tridiagonal form.  If UPLO = 'U', the diagonal */
00126 /*          and first superdiagonal of the tridiagonal matrix T overwrite */
00127 /*          the corresponding elements of A, and if UPLO = 'L', the */
00128 /*          diagonal and first subdiagonal of T overwrite the */
00129 /*          corresponding elements of A. */
00130 
00131 /*  VL      (input) REAL */
00132 /*  VU      (input) REAL */
00133 /*          If RANGE='V', the lower and upper bounds of the interval to */
00134 /*          be searched for eigenvalues. VL < VU. */
00135 /*          Not referenced if RANGE = 'A' or 'I'. */
00136 
00137 /*  IL      (input) INTEGER */
00138 /*  IU      (input) INTEGER */
00139 /*          If RANGE='I', the indices (in ascending order) of the */
00140 /*          smallest and largest eigenvalues to be returned. */
00141 /*          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
00142 /*          Not referenced if RANGE = 'A' or 'V'. */
00143 
00144 /*  ABSTOL  (input) REAL */
00145 /*          The absolute error tolerance for the eigenvalues. */
00146 /*          An approximate eigenvalue is accepted as converged */
00147 /*          when it is determined to lie in an interval [a,b] */
00148 /*          of width less than or equal to */
00149 
00150 /*                  ABSTOL + EPS *   max( |a|,|b| ) , */
00151 
00152 /*          where EPS is the machine precision.  If ABSTOL is less than */
00153 /*          or equal to zero, then  EPS*|T|  will be used in its place, */
00154 /*          where |T| is the 1-norm of the tridiagonal matrix obtained */
00155 /*          by reducing AP to tridiagonal form. */
00156 
00157 /*          Eigenvalues will be computed most accurately when ABSTOL is */
00158 /*          set to twice the underflow threshold 2*SLAMCH('S'), not zero. */
00159 /*          If this routine returns with INFO>0, indicating that some */
00160 /*          eigenvectors did not converge, try setting ABSTOL to */
00161 /*          2*SLAMCH('S'). */
00162 
00163 /*          See "Computing Small Singular Values of Bidiagonal Matrices */
00164 /*          with Guaranteed High Relative Accuracy," by Demmel and */
00165 /*          Kahan, LAPACK Working Note #3. */
00166 
00167 /*  M       (output) INTEGER */
00168 /*          The total number of eigenvalues found.  0 <= M <= N. */
00169 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
00170 
00171 /*  W       (output) REAL array, dimension (N) */
00172 /*          If INFO = 0, the selected eigenvalues in ascending order. */
00173 
00174 /*  Z       (output) COMPLEX array, dimension (LDZ, max(1,M)) */
00175 /*          If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
00176 /*          contain the orthonormal eigenvectors of the matrix A */
00177 /*          corresponding to the selected eigenvalues, with the i-th */
00178 /*          column of Z holding the eigenvector associated with W(i). */
00179 /*          If an eigenvector fails to converge, then that column of Z */
00180 /*          contains the latest approximation to the eigenvector, and */
00181 /*          the index of the eigenvector is returned in IFAIL. */
00182 /*          If JOBZ = 'N', then Z is not referenced. */
00183 /*          Note: the user must ensure that at least max(1,M) columns are */
00184 /*          supplied in the array Z; if RANGE = 'V', the exact value of M */
00185 /*          is not known in advance and an upper bound must be used. */
00186 
00187 /*  LDZ     (input) INTEGER */
00188 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00189 /*          JOBZ = 'V', LDZ >= max(1,N). */
00190 
00191 /*  WORK    (workspace) COMPLEX array, dimension (2*N) */
00192 
00193 /*  RWORK   (workspace) REAL array, dimension (7*N) */
00194 
00195 /*  IWORK   (workspace) INTEGER array, dimension (5*N) */
00196 
00197 /*  IFAIL   (output) INTEGER array, dimension (N) */
00198 /*          If JOBZ = 'V', then if INFO = 0, the first M elements of */
00199 /*          IFAIL are zero.  If INFO > 0, then IFAIL contains the */
00200 /*          indices of the eigenvectors that failed to converge. */
00201 /*          If JOBZ = 'N', then IFAIL is not referenced. */
00202 
00203 /*  INFO    (output) INTEGER */
00204 /*          = 0:  successful exit */
00205 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00206 /*          > 0:  if INFO = i, then i eigenvectors failed to converge. */
00207 /*                Their indices are stored in array IFAIL. */
00208 
00209 /*  ===================================================================== */
00210 
00211 /*     .. Parameters .. */
00212 /*     .. */
00213 /*     .. Local Scalars .. */
00214 /*     .. */
00215 /*     .. External Functions .. */
00216 /*     .. */
00217 /*     .. External Subroutines .. */
00218 /*     .. */
00219 /*     .. Intrinsic Functions .. */
00220 /*     .. */
00221 /*     .. Executable Statements .. */
00222 
00223 /*     Test the input parameters. */
00224 
00225     /* Parameter adjustments */
00226     --ap;
00227     --w;
00228     z_dim1 = *ldz;
00229     z_offset = 1 + z_dim1;
00230     z__ -= z_offset;
00231     --work;
00232     --rwork;
00233     --iwork;
00234     --ifail;
00235 
00236     /* Function Body */
00237     wantz = lsame_(jobz, "V");
00238     alleig = lsame_(range, "A");
00239     valeig = lsame_(range, "V");
00240     indeig = lsame_(range, "I");
00241 
00242     *info = 0;
00243     if (! (wantz || lsame_(jobz, "N"))) {
00244         *info = -1;
00245     } else if (! (alleig || valeig || indeig)) {
00246         *info = -2;
00247     } else if (! (lsame_(uplo, "L") || lsame_(uplo, 
00248             "U"))) {
00249         *info = -3;
00250     } else if (*n < 0) {
00251         *info = -4;
00252     } else {
00253         if (valeig) {
00254             if (*n > 0 && *vu <= *vl) {
00255                 *info = -7;
00256             }
00257         } else if (indeig) {
00258             if (*il < 1 || *il > max(1,*n)) {
00259                 *info = -8;
00260             } else if (*iu < min(*n,*il) || *iu > *n) {
00261                 *info = -9;
00262             }
00263         }
00264     }
00265     if (*info == 0) {
00266         if (*ldz < 1 || wantz && *ldz < *n) {
00267             *info = -14;
00268         }
00269     }
00270 
00271     if (*info != 0) {
00272         i__1 = -(*info);
00273         xerbla_("CHPEVX", &i__1);
00274         return 0;
00275     }
00276 
00277 /*     Quick return if possible */
00278 
00279     *m = 0;
00280     if (*n == 0) {
00281         return 0;
00282     }
00283 
00284     if (*n == 1) {
00285         if (alleig || indeig) {
00286             *m = 1;
00287             w[1] = ap[1].r;
00288         } else {
00289             if (*vl < ap[1].r && *vu >= ap[1].r) {
00290                 *m = 1;
00291                 w[1] = ap[1].r;
00292             }
00293         }
00294         if (wantz) {
00295             i__1 = z_dim1 + 1;
00296             z__[i__1].r = 1.f, z__[i__1].i = 0.f;
00297         }
00298         return 0;
00299     }
00300 
00301 /*     Get machine constants. */
00302 
00303     safmin = slamch_("Safe minimum");
00304     eps = slamch_("Precision");
00305     smlnum = safmin / eps;
00306     bignum = 1.f / smlnum;
00307     rmin = sqrt(smlnum);
00308 /* Computing MIN */
00309     r__1 = sqrt(bignum), r__2 = 1.f / sqrt(sqrt(safmin));
00310     rmax = dmin(r__1,r__2);
00311 
00312 /*     Scale matrix to allowable range, if necessary. */
00313 
00314     iscale = 0;
00315     abstll = *abstol;
00316     if (valeig) {
00317         vll = *vl;
00318         vuu = *vu;
00319     } else {
00320         vll = 0.f;
00321         vuu = 0.f;
00322     }
00323     anrm = clanhp_("M", uplo, n, &ap[1], &rwork[1]);
00324     if (anrm > 0.f && anrm < rmin) {
00325         iscale = 1;
00326         sigma = rmin / anrm;
00327     } else if (anrm > rmax) {
00328         iscale = 1;
00329         sigma = rmax / anrm;
00330     }
00331     if (iscale == 1) {
00332         i__1 = *n * (*n + 1) / 2;
00333         csscal_(&i__1, &sigma, &ap[1], &c__1);
00334         if (*abstol > 0.f) {
00335             abstll = *abstol * sigma;
00336         }
00337         if (valeig) {
00338             vll = *vl * sigma;
00339             vuu = *vu * sigma;
00340         }
00341     }
00342 
00343 /*     Call CHPTRD to reduce Hermitian packed matrix to tridiagonal form. */
00344 
00345     indd = 1;
00346     inde = indd + *n;
00347     indrwk = inde + *n;
00348     indtau = 1;
00349     indwrk = indtau + *n;
00350     chptrd_(uplo, n, &ap[1], &rwork[indd], &rwork[inde], &work[indtau], &
00351             iinfo);
00352 
00353 /*     If all eigenvalues are desired and ABSTOL is less than or equal */
00354 /*     to zero, then call SSTERF or CUPGTR and CSTEQR.  If this fails */
00355 /*     for some eigenvalue, then try SSTEBZ. */
00356 
00357     test = FALSE_;
00358     if (indeig) {
00359         if (*il == 1 && *iu == *n) {
00360             test = TRUE_;
00361         }
00362     }
00363     if ((alleig || test) && *abstol <= 0.f) {
00364         scopy_(n, &rwork[indd], &c__1, &w[1], &c__1);
00365         indee = indrwk + (*n << 1);
00366         if (! wantz) {
00367             i__1 = *n - 1;
00368             scopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
00369             ssterf_(n, &w[1], &rwork[indee], info);
00370         } else {
00371             cupgtr_(uplo, n, &ap[1], &work[indtau], &z__[z_offset], ldz, &
00372                     work[indwrk], &iinfo);
00373             i__1 = *n - 1;
00374             scopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
00375             csteqr_(jobz, n, &w[1], &rwork[indee], &z__[z_offset], ldz, &
00376                     rwork[indrwk], info);
00377             if (*info == 0) {
00378                 i__1 = *n;
00379                 for (i__ = 1; i__ <= i__1; ++i__) {
00380                     ifail[i__] = 0;
00381 /* L10: */
00382                 }
00383             }
00384         }
00385         if (*info == 0) {
00386             *m = *n;
00387             goto L20;
00388         }
00389         *info = 0;
00390     }
00391 
00392 /*     Otherwise, call SSTEBZ and, if eigenvectors are desired, CSTEIN. */
00393 
00394     if (wantz) {
00395         *(unsigned char *)order = 'B';
00396     } else {
00397         *(unsigned char *)order = 'E';
00398     }
00399     indibl = 1;
00400     indisp = indibl + *n;
00401     indiwk = indisp + *n;
00402     sstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &rwork[indd], &
00403             rwork[inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &
00404             rwork[indrwk], &iwork[indiwk], info);
00405 
00406     if (wantz) {
00407         cstein_(n, &rwork[indd], &rwork[inde], m, &w[1], &iwork[indibl], &
00408                 iwork[indisp], &z__[z_offset], ldz, &rwork[indrwk], &iwork[
00409                 indiwk], &ifail[1], info);
00410 
00411 /*        Apply unitary matrix used in reduction to tridiagonal */
00412 /*        form to eigenvectors returned by CSTEIN. */
00413 
00414         indwrk = indtau + *n;
00415         cupmtr_("L", uplo, "N", n, m, &ap[1], &work[indtau], &z__[z_offset], 
00416                 ldz, &work[indwrk], &iinfo);
00417     }
00418 
00419 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00420 
00421 L20:
00422     if (iscale == 1) {
00423         if (*info == 0) {
00424             imax = *m;
00425         } else {
00426             imax = *info - 1;
00427         }
00428         r__1 = 1.f / sigma;
00429         sscal_(&imax, &r__1, &w[1], &c__1);
00430     }
00431 
00432 /*     If eigenvalues are not in order, then sort them, along with */
00433 /*     eigenvectors. */
00434 
00435     if (wantz) {
00436         i__1 = *m - 1;
00437         for (j = 1; j <= i__1; ++j) {
00438             i__ = 0;
00439             tmp1 = w[j];
00440             i__2 = *m;
00441             for (jj = j + 1; jj <= i__2; ++jj) {
00442                 if (w[jj] < tmp1) {
00443                     i__ = jj;
00444                     tmp1 = w[jj];
00445                 }
00446 /* L30: */
00447             }
00448 
00449             if (i__ != 0) {
00450                 itmp1 = iwork[indibl + i__ - 1];
00451                 w[i__] = w[j];
00452                 iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
00453                 w[j] = tmp1;
00454                 iwork[indibl + j - 1] = itmp1;
00455                 cswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], 
00456                          &c__1);
00457                 if (*info != 0) {
00458                     itmp1 = ifail[i__];
00459                     ifail[i__] = ifail[j];
00460                     ifail[j] = itmp1;
00461                 }
00462             }
00463 /* L40: */
00464         }
00465     }
00466 
00467     return 0;
00468 
00469 /*     End of CHPEVX */
00470 
00471 } /* chpevx_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:29