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


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