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


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