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


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