sstein.c
Go to the documentation of this file.
00001 /* sstein.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__2 = 2;
00019 static integer c__1 = 1;
00020 static integer c_n1 = -1;
00021 
00022 /* Subroutine */ int sstein_(integer *n, real *d__, real *e, integer *m, real 
00023         *w, integer *iblock, integer *isplit, real *z__, integer *ldz, real *
00024         work, integer *iwork, integer *ifail, integer *info)
00025 {
00026     /* System generated locals */
00027     integer z_dim1, z_offset, i__1, i__2, i__3;
00028     real r__1, r__2, r__3, r__4, r__5;
00029 
00030     /* Builtin functions */
00031     double sqrt(doublereal);
00032 
00033     /* Local variables */
00034     integer i__, j, b1, j1, bn;
00035     real xj, scl, eps, ctr, sep, nrm, tol;
00036     integer its;
00037     real xjm, eps1;
00038     integer jblk, nblk, jmax;
00039     extern doublereal sdot_(integer *, real *, integer *, real *, integer *), 
00040             snrm2_(integer *, real *, integer *);
00041     integer iseed[4], gpind, iinfo;
00042     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
00043     extern doublereal sasum_(integer *, real *, integer *);
00044     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
00045             integer *);
00046     real ortol;
00047     extern /* Subroutine */ int saxpy_(integer *, real *, real *, integer *, 
00048             real *, integer *);
00049     integer indrv1, indrv2, indrv3, indrv4, indrv5;
00050     extern doublereal slamch_(char *);
00051     extern /* Subroutine */ int xerbla_(char *, integer *), slagtf_(
00052             integer *, real *, real *, real *, real *, real *, real *, 
00053             integer *, integer *);
00054     integer nrmchk;
00055     extern integer isamax_(integer *, real *, integer *);
00056     extern /* Subroutine */ int slagts_(integer *, integer *, real *, real *, 
00057             real *, real *, integer *, real *, real *, integer *);
00058     integer blksiz;
00059     real onenrm, pertol;
00060     extern /* Subroutine */ int slarnv_(integer *, integer *, integer *, real 
00061             *);
00062     real stpcrt;
00063 
00064 
00065 /*  -- LAPACK routine (version 3.2) -- */
00066 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00067 /*     November 2006 */
00068 
00069 /*     .. Scalar Arguments .. */
00070 /*     .. */
00071 /*     .. Array Arguments .. */
00072 /*     .. */
00073 
00074 /*  Purpose */
00075 /*  ======= */
00076 
00077 /*  SSTEIN computes the eigenvectors of a real symmetric tridiagonal */
00078 /*  matrix T corresponding to specified eigenvalues, using inverse */
00079 /*  iteration. */
00080 
00081 /*  The maximum number of iterations allowed for each eigenvector is */
00082 /*  specified by an internal parameter MAXITS (currently set to 5). */
00083 
00084 /*  Arguments */
00085 /*  ========= */
00086 
00087 /*  N       (input) INTEGER */
00088 /*          The order of the matrix.  N >= 0. */
00089 
00090 /*  D       (input) REAL array, dimension (N) */
00091 /*          The n diagonal elements of the tridiagonal matrix T. */
00092 
00093 /*  E       (input) REAL array, dimension (N-1) */
00094 /*          The (n-1) subdiagonal elements of the tridiagonal matrix */
00095 /*          T, in elements 1 to N-1. */
00096 
00097 /*  M       (input) INTEGER */
00098 /*          The number of eigenvectors to be found.  0 <= M <= N. */
00099 
00100 /*  W       (input) REAL array, dimension (N) */
00101 /*          The first M elements of W contain the eigenvalues for */
00102 /*          which eigenvectors are to be computed.  The eigenvalues */
00103 /*          should be grouped by split-off block and ordered from */
00104 /*          smallest to largest within the block.  ( The output array */
00105 /*          W from SSTEBZ with ORDER = 'B' is expected here. ) */
00106 
00107 /*  IBLOCK  (input) INTEGER array, dimension (N) */
00108 /*          The submatrix indices associated with the corresponding */
00109 /*          eigenvalues in W; IBLOCK(i)=1 if eigenvalue W(i) belongs to */
00110 /*          the first submatrix from the top, =2 if W(i) belongs to */
00111 /*          the second submatrix, etc.  ( The output array IBLOCK */
00112 /*          from SSTEBZ is expected here. ) */
00113 
00114 /*  ISPLIT  (input) INTEGER array, dimension (N) */
00115 /*          The splitting points, at which T breaks up into submatrices. */
00116 /*          The first submatrix consists of rows/columns 1 to */
00117 /*          ISPLIT( 1 ), the second of rows/columns ISPLIT( 1 )+1 */
00118 /*          through ISPLIT( 2 ), etc. */
00119 /*          ( The output array ISPLIT from SSTEBZ is expected here. ) */
00120 
00121 /*  Z       (output) REAL array, dimension (LDZ, M) */
00122 /*          The computed eigenvectors.  The eigenvector associated */
00123 /*          with the eigenvalue W(i) is stored in the i-th column of */
00124 /*          Z.  Any vector which fails to converge is set to its current */
00125 /*          iterate after MAXITS iterations. */
00126 
00127 /*  LDZ     (input) INTEGER */
00128 /*          The leading dimension of the array Z.  LDZ >= max(1,N). */
00129 
00130 /*  WORK    (workspace) REAL array, dimension (5*N) */
00131 
00132 /*  IWORK   (workspace) INTEGER array, dimension (N) */
00133 
00134 /*  IFAIL   (output) INTEGER array, dimension (M) */
00135 /*          On normal exit, all elements of IFAIL are zero. */
00136 /*          If one or more eigenvectors fail to converge after */
00137 /*          MAXITS iterations, then their indices are stored in */
00138 /*          array IFAIL. */
00139 
00140 /*  INFO    (output) INTEGER */
00141 /*          = 0: successful exit. */
00142 /*          < 0: if INFO = -i, the i-th argument had an illegal value */
00143 /*          > 0: if INFO = i, then i eigenvectors failed to converge */
00144 /*               in MAXITS iterations.  Their indices are stored in */
00145 /*               array IFAIL. */
00146 
00147 /*  Internal Parameters */
00148 /*  =================== */
00149 
00150 /*  MAXITS  INTEGER, default = 5 */
00151 /*          The maximum number of iterations performed. */
00152 
00153 /*  EXTRA   INTEGER, default = 2 */
00154 /*          The number of iterations performed after norm growth */
00155 /*          criterion is satisfied, should be at least 1. */
00156 
00157 /*  ===================================================================== */
00158 
00159 /*     .. Parameters .. */
00160 /*     .. */
00161 /*     .. Local Scalars .. */
00162 /*     .. */
00163 /*     .. Local Arrays .. */
00164 /*     .. */
00165 /*     .. External Functions .. */
00166 /*     .. */
00167 /*     .. External Subroutines .. */
00168 /*     .. */
00169 /*     .. Intrinsic Functions .. */
00170 /*     .. */
00171 /*     .. Executable Statements .. */
00172 
00173 /*     Test the input parameters. */
00174 
00175     /* Parameter adjustments */
00176     --d__;
00177     --e;
00178     --w;
00179     --iblock;
00180     --isplit;
00181     z_dim1 = *ldz;
00182     z_offset = 1 + z_dim1;
00183     z__ -= z_offset;
00184     --work;
00185     --iwork;
00186     --ifail;
00187 
00188     /* Function Body */
00189     *info = 0;
00190     i__1 = *m;
00191     for (i__ = 1; i__ <= i__1; ++i__) {
00192         ifail[i__] = 0;
00193 /* L10: */
00194     }
00195 
00196     if (*n < 0) {
00197         *info = -1;
00198     } else if (*m < 0 || *m > *n) {
00199         *info = -4;
00200     } else if (*ldz < max(1,*n)) {
00201         *info = -9;
00202     } else {
00203         i__1 = *m;
00204         for (j = 2; j <= i__1; ++j) {
00205             if (iblock[j] < iblock[j - 1]) {
00206                 *info = -6;
00207                 goto L30;
00208             }
00209             if (iblock[j] == iblock[j - 1] && w[j] < w[j - 1]) {
00210                 *info = -5;
00211                 goto L30;
00212             }
00213 /* L20: */
00214         }
00215 L30:
00216         ;
00217     }
00218 
00219     if (*info != 0) {
00220         i__1 = -(*info);
00221         xerbla_("SSTEIN", &i__1);
00222         return 0;
00223     }
00224 
00225 /*     Quick return if possible */
00226 
00227     if (*n == 0 || *m == 0) {
00228         return 0;
00229     } else if (*n == 1) {
00230         z__[z_dim1 + 1] = 1.f;
00231         return 0;
00232     }
00233 
00234 /*     Get machine constants. */
00235 
00236     eps = slamch_("Precision");
00237 
00238 /*     Initialize seed for random number generator SLARNV. */
00239 
00240     for (i__ = 1; i__ <= 4; ++i__) {
00241         iseed[i__ - 1] = 1;
00242 /* L40: */
00243     }
00244 
00245 /*     Initialize pointers. */
00246 
00247     indrv1 = 0;
00248     indrv2 = indrv1 + *n;
00249     indrv3 = indrv2 + *n;
00250     indrv4 = indrv3 + *n;
00251     indrv5 = indrv4 + *n;
00252 
00253 /*     Compute eigenvectors of matrix blocks. */
00254 
00255     j1 = 1;
00256     i__1 = iblock[*m];
00257     for (nblk = 1; nblk <= i__1; ++nblk) {
00258 
00259 /*        Find starting and ending indices of block nblk. */
00260 
00261         if (nblk == 1) {
00262             b1 = 1;
00263         } else {
00264             b1 = isplit[nblk - 1] + 1;
00265         }
00266         bn = isplit[nblk];
00267         blksiz = bn - b1 + 1;
00268         if (blksiz == 1) {
00269             goto L60;
00270         }
00271         gpind = b1;
00272 
00273 /*        Compute reorthogonalization criterion and stopping criterion. */
00274 
00275         onenrm = (r__1 = d__[b1], dabs(r__1)) + (r__2 = e[b1], dabs(r__2));
00276 /* Computing MAX */
00277         r__3 = onenrm, r__4 = (r__1 = d__[bn], dabs(r__1)) + (r__2 = e[bn - 1]
00278                 , dabs(r__2));
00279         onenrm = dmax(r__3,r__4);
00280         i__2 = bn - 1;
00281         for (i__ = b1 + 1; i__ <= i__2; ++i__) {
00282 /* Computing MAX */
00283             r__4 = onenrm, r__5 = (r__1 = d__[i__], dabs(r__1)) + (r__2 = e[
00284                     i__ - 1], dabs(r__2)) + (r__3 = e[i__], dabs(r__3));
00285             onenrm = dmax(r__4,r__5);
00286 /* L50: */
00287         }
00288         ortol = onenrm * .001f;
00289 
00290         stpcrt = sqrt(.1f / blksiz);
00291 
00292 /*        Loop through eigenvalues of block nblk. */
00293 
00294 L60:
00295         jblk = 0;
00296         i__2 = *m;
00297         for (j = j1; j <= i__2; ++j) {
00298             if (iblock[j] != nblk) {
00299                 j1 = j;
00300                 goto L160;
00301             }
00302             ++jblk;
00303             xj = w[j];
00304 
00305 /*           Skip all the work if the block size is one. */
00306 
00307             if (blksiz == 1) {
00308                 work[indrv1 + 1] = 1.f;
00309                 goto L120;
00310             }
00311 
00312 /*           If eigenvalues j and j-1 are too close, add a relatively */
00313 /*           small perturbation. */
00314 
00315             if (jblk > 1) {
00316                 eps1 = (r__1 = eps * xj, dabs(r__1));
00317                 pertol = eps1 * 10.f;
00318                 sep = xj - xjm;
00319                 if (sep < pertol) {
00320                     xj = xjm + pertol;
00321                 }
00322             }
00323 
00324             its = 0;
00325             nrmchk = 0;
00326 
00327 /*           Get random starting vector. */
00328 
00329             slarnv_(&c__2, iseed, &blksiz, &work[indrv1 + 1]);
00330 
00331 /*           Copy the matrix T so it won't be destroyed in factorization. */
00332 
00333             scopy_(&blksiz, &d__[b1], &c__1, &work[indrv4 + 1], &c__1);
00334             i__3 = blksiz - 1;
00335             scopy_(&i__3, &e[b1], &c__1, &work[indrv2 + 2], &c__1);
00336             i__3 = blksiz - 1;
00337             scopy_(&i__3, &e[b1], &c__1, &work[indrv3 + 1], &c__1);
00338 
00339 /*           Compute LU factors with partial pivoting  ( PT = LU ) */
00340 
00341             tol = 0.f;
00342             slagtf_(&blksiz, &work[indrv4 + 1], &xj, &work[indrv2 + 2], &work[
00343                     indrv3 + 1], &tol, &work[indrv5 + 1], &iwork[1], &iinfo);
00344 
00345 /*           Update iteration count. */
00346 
00347 L70:
00348             ++its;
00349             if (its > 5) {
00350                 goto L100;
00351             }
00352 
00353 /*           Normalize and scale the righthand side vector Pb. */
00354 
00355 /* Computing MAX */
00356             r__2 = eps, r__3 = (r__1 = work[indrv4 + blksiz], dabs(r__1));
00357             scl = blksiz * onenrm * dmax(r__2,r__3) / sasum_(&blksiz, &work[
00358                     indrv1 + 1], &c__1);
00359             sscal_(&blksiz, &scl, &work[indrv1 + 1], &c__1);
00360 
00361 /*           Solve the system LU = Pb. */
00362 
00363             slagts_(&c_n1, &blksiz, &work[indrv4 + 1], &work[indrv2 + 2], &
00364                     work[indrv3 + 1], &work[indrv5 + 1], &iwork[1], &work[
00365                     indrv1 + 1], &tol, &iinfo);
00366 
00367 /*           Reorthogonalize by modified Gram-Schmidt if eigenvalues are */
00368 /*           close enough. */
00369 
00370             if (jblk == 1) {
00371                 goto L90;
00372             }
00373             if ((r__1 = xj - xjm, dabs(r__1)) > ortol) {
00374                 gpind = j;
00375             }
00376             if (gpind != j) {
00377                 i__3 = j - 1;
00378                 for (i__ = gpind; i__ <= i__3; ++i__) {
00379                     ctr = -sdot_(&blksiz, &work[indrv1 + 1], &c__1, &z__[b1 + 
00380                             i__ * z_dim1], &c__1);
00381                     saxpy_(&blksiz, &ctr, &z__[b1 + i__ * z_dim1], &c__1, &
00382                             work[indrv1 + 1], &c__1);
00383 /* L80: */
00384                 }
00385             }
00386 
00387 /*           Check the infinity norm of the iterate. */
00388 
00389 L90:
00390             jmax = isamax_(&blksiz, &work[indrv1 + 1], &c__1);
00391             nrm = (r__1 = work[indrv1 + jmax], dabs(r__1));
00392 
00393 /*           Continue for additional iterations after norm reaches */
00394 /*           stopping criterion. */
00395 
00396             if (nrm < stpcrt) {
00397                 goto L70;
00398             }
00399             ++nrmchk;
00400             if (nrmchk < 3) {
00401                 goto L70;
00402             }
00403 
00404             goto L110;
00405 
00406 /*           If stopping criterion was not satisfied, update info and */
00407 /*           store eigenvector number in array ifail. */
00408 
00409 L100:
00410             ++(*info);
00411             ifail[*info] = j;
00412 
00413 /*           Accept iterate as jth eigenvector. */
00414 
00415 L110:
00416             scl = 1.f / snrm2_(&blksiz, &work[indrv1 + 1], &c__1);
00417             jmax = isamax_(&blksiz, &work[indrv1 + 1], &c__1);
00418             if (work[indrv1 + jmax] < 0.f) {
00419                 scl = -scl;
00420             }
00421             sscal_(&blksiz, &scl, &work[indrv1 + 1], &c__1);
00422 L120:
00423             i__3 = *n;
00424             for (i__ = 1; i__ <= i__3; ++i__) {
00425                 z__[i__ + j * z_dim1] = 0.f;
00426 /* L130: */
00427             }
00428             i__3 = blksiz;
00429             for (i__ = 1; i__ <= i__3; ++i__) {
00430                 z__[b1 + i__ - 1 + j * z_dim1] = work[indrv1 + i__];
00431 /* L140: */
00432             }
00433 
00434 /*           Save the shift to check eigenvalue spacing at next */
00435 /*           iteration. */
00436 
00437             xjm = xj;
00438 
00439 /* L150: */
00440         }
00441 L160:
00442         ;
00443     }
00444 
00445     return 0;
00446 
00447 /*     End of SSTEIN */
00448 
00449 } /* sstein_ */


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