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


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