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


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