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


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