slaed0.c
Go to the documentation of this file.
00001 /* slaed0.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__9 = 9;
00019 static integer c__0 = 0;
00020 static integer c__2 = 2;
00021 static real c_b23 = 1.f;
00022 static real c_b24 = 0.f;
00023 static integer c__1 = 1;
00024 
00025 /* Subroutine */ int slaed0_(integer *icompq, integer *qsiz, integer *n, real 
00026         *d__, real *e, real *q, integer *ldq, real *qstore, integer *ldqs, 
00027         real *work, integer *iwork, integer *info)
00028 {
00029     /* System generated locals */
00030     integer q_dim1, q_offset, qstore_dim1, qstore_offset, i__1, i__2;
00031     real r__1;
00032 
00033     /* Builtin functions */
00034     double log(doublereal);
00035     integer pow_ii(integer *, integer *);
00036 
00037     /* Local variables */
00038     integer i__, j, k, iq, lgn, msd2, smm1, spm1, spm2;
00039     real temp;
00040     integer curr;
00041     extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *, 
00042             integer *, real *, real *, integer *, real *, integer *, real *, 
00043             real *, integer *);
00044     integer iperm, indxq, iwrem;
00045     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
00046             integer *);
00047     integer iqptr, tlvls;
00048     extern /* Subroutine */ int slaed1_(integer *, real *, real *, integer *, 
00049             integer *, real *, integer *, real *, integer *, integer *), 
00050             slaed7_(integer *, integer *, integer *, integer *, integer *, 
00051             integer *, real *, real *, integer *, integer *, real *, integer *
00052 , real *, integer *, integer *, integer *, integer *, integer *, 
00053             real *, real *, integer *, integer *);
00054     integer igivcl;
00055     extern /* Subroutine */ int xerbla_(char *, integer *);
00056     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00057             integer *, integer *);
00058     integer igivnm, submat;
00059     extern /* Subroutine */ int slacpy_(char *, integer *, integer *, real *, 
00060             integer *, real *, integer *);
00061     integer curprb, subpbs, igivpt, curlvl, matsiz, iprmpt, smlsiz;
00062     extern /* Subroutine */ int ssteqr_(char *, integer *, real *, real *, 
00063             real *, integer *, real *, integer *);
00064 
00065 
00066 /*  -- LAPACK routine (version 3.2) -- */
00067 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00068 /*     November 2006 */
00069 
00070 /*     .. Scalar Arguments .. */
00071 /*     .. */
00072 /*     .. Array Arguments .. */
00073 /*     .. */
00074 
00075 /*  Purpose */
00076 /*  ======= */
00077 
00078 /*  SLAED0 computes all eigenvalues and corresponding eigenvectors of a */
00079 /*  symmetric tridiagonal matrix using the divide and conquer method. */
00080 
00081 /*  Arguments */
00082 /*  ========= */
00083 
00084 /*  ICOMPQ  (input) INTEGER */
00085 /*          = 0:  Compute eigenvalues only. */
00086 /*          = 1:  Compute eigenvectors of original dense symmetric matrix */
00087 /*                also.  On entry, Q contains the orthogonal matrix used */
00088 /*                to reduce the original matrix to tridiagonal form. */
00089 /*          = 2:  Compute eigenvalues and eigenvectors of tridiagonal */
00090 /*                matrix. */
00091 
00092 /*  QSIZ   (input) INTEGER */
00093 /*         The dimension of the orthogonal matrix used to reduce */
00094 /*         the full matrix to tridiagonal form.  QSIZ >= N if ICOMPQ = 1. */
00095 
00096 /*  N      (input) INTEGER */
00097 /*         The dimension of the symmetric tridiagonal matrix.  N >= 0. */
00098 
00099 /*  D      (input/output) REAL array, dimension (N) */
00100 /*         On entry, the main diagonal of the tridiagonal matrix. */
00101 /*         On exit, its eigenvalues. */
00102 
00103 /*  E      (input) REAL array, dimension (N-1) */
00104 /*         The off-diagonal elements of the tridiagonal matrix. */
00105 /*         On exit, E has been destroyed. */
00106 
00107 /*  Q      (input/output) REAL array, dimension (LDQ, N) */
00108 /*         On entry, Q must contain an N-by-N orthogonal matrix. */
00109 /*         If ICOMPQ = 0    Q is not referenced. */
00110 /*         If ICOMPQ = 1    On entry, Q is a subset of the columns of the */
00111 /*                          orthogonal matrix used to reduce the full */
00112 /*                          matrix to tridiagonal form corresponding to */
00113 /*                          the subset of the full matrix which is being */
00114 /*                          decomposed at this time. */
00115 /*         If ICOMPQ = 2    On entry, Q will be the identity matrix. */
00116 /*                          On exit, Q contains the eigenvectors of the */
00117 /*                          tridiagonal matrix. */
00118 
00119 /*  LDQ    (input) INTEGER */
00120 /*         The leading dimension of the array Q.  If eigenvectors are */
00121 /*         desired, then  LDQ >= max(1,N).  In any case,  LDQ >= 1. */
00122 
00123 /*  QSTORE (workspace) REAL array, dimension (LDQS, N) */
00124 /*         Referenced only when ICOMPQ = 1.  Used to store parts of */
00125 /*         the eigenvector matrix when the updating matrix multiplies */
00126 /*         take place. */
00127 
00128 /*  LDQS   (input) INTEGER */
00129 /*         The leading dimension of the array QSTORE.  If ICOMPQ = 1, */
00130 /*         then  LDQS >= max(1,N).  In any case,  LDQS >= 1. */
00131 
00132 /*  WORK   (workspace) REAL array, */
00133 /*         If ICOMPQ = 0 or 1, the dimension of WORK must be at least */
00134 /*                     1 + 3*N + 2*N*lg N + 2*N**2 */
00135 /*                     ( lg( N ) = smallest integer k */
00136 /*                                 such that 2^k >= N ) */
00137 /*         If ICOMPQ = 2, the dimension of WORK must be at least */
00138 /*                     4*N + N**2. */
00139 
00140 /*  IWORK  (workspace) INTEGER array, */
00141 /*         If ICOMPQ = 0 or 1, the dimension of IWORK must be at least */
00142 /*                        6 + 6*N + 5*N*lg N. */
00143 /*                        ( lg( N ) = smallest integer k */
00144 /*                                    such that 2^k >= N ) */
00145 /*         If ICOMPQ = 2, the dimension of IWORK must be at least */
00146 /*                        3 + 5*N. */
00147 
00148 /*  INFO   (output) INTEGER */
00149 /*          = 0:  successful exit. */
00150 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00151 /*          > 0:  The algorithm failed to compute an eigenvalue while */
00152 /*                working on the submatrix lying in rows and columns */
00153 /*                INFO/(N+1) through mod(INFO,N+1). */
00154 
00155 /*  Further Details */
00156 /*  =============== */
00157 
00158 /*  Based on contributions by */
00159 /*     Jeff Rutter, Computer Science Division, University of California */
00160 /*     at Berkeley, USA */
00161 
00162 /*  ===================================================================== */
00163 
00164 /*     .. Parameters .. */
00165 /*     .. */
00166 /*     .. Local Scalars .. */
00167 /*     .. */
00168 /*     .. External Subroutines .. */
00169 /*     .. */
00170 /*     .. External Functions .. */
00171 /*     .. */
00172 /*     .. Intrinsic Functions .. */
00173 /*     .. */
00174 /*     .. Executable Statements .. */
00175 
00176 /*     Test the input parameters. */
00177 
00178     /* Parameter adjustments */
00179     --d__;
00180     --e;
00181     q_dim1 = *ldq;
00182     q_offset = 1 + q_dim1;
00183     q -= q_offset;
00184     qstore_dim1 = *ldqs;
00185     qstore_offset = 1 + qstore_dim1;
00186     qstore -= qstore_offset;
00187     --work;
00188     --iwork;
00189 
00190     /* Function Body */
00191     *info = 0;
00192 
00193     if (*icompq < 0 || *icompq > 2) {
00194         *info = -1;
00195     } else if (*icompq == 1 && *qsiz < max(0,*n)) {
00196         *info = -2;
00197     } else if (*n < 0) {
00198         *info = -3;
00199     } else if (*ldq < max(1,*n)) {
00200         *info = -7;
00201     } else if (*ldqs < max(1,*n)) {
00202         *info = -9;
00203     }
00204     if (*info != 0) {
00205         i__1 = -(*info);
00206         xerbla_("SLAED0", &i__1);
00207         return 0;
00208     }
00209 
00210 /*     Quick return if possible */
00211 
00212     if (*n == 0) {
00213         return 0;
00214     }
00215 
00216     smlsiz = ilaenv_(&c__9, "SLAED0", " ", &c__0, &c__0, &c__0, &c__0);
00217 
00218 /*     Determine the size and placement of the submatrices, and save in */
00219 /*     the leading elements of IWORK. */
00220 
00221     iwork[1] = *n;
00222     subpbs = 1;
00223     tlvls = 0;
00224 L10:
00225     if (iwork[subpbs] > smlsiz) {
00226         for (j = subpbs; j >= 1; --j) {
00227             iwork[j * 2] = (iwork[j] + 1) / 2;
00228             iwork[(j << 1) - 1] = iwork[j] / 2;
00229 /* L20: */
00230         }
00231         ++tlvls;
00232         subpbs <<= 1;
00233         goto L10;
00234     }
00235     i__1 = subpbs;
00236     for (j = 2; j <= i__1; ++j) {
00237         iwork[j] += iwork[j - 1];
00238 /* L30: */
00239     }
00240 
00241 /*     Divide the matrix into SUBPBS submatrices of size at most SMLSIZ+1 */
00242 /*     using rank-1 modifications (cuts). */
00243 
00244     spm1 = subpbs - 1;
00245     i__1 = spm1;
00246     for (i__ = 1; i__ <= i__1; ++i__) {
00247         submat = iwork[i__] + 1;
00248         smm1 = submat - 1;
00249         d__[smm1] -= (r__1 = e[smm1], dabs(r__1));
00250         d__[submat] -= (r__1 = e[smm1], dabs(r__1));
00251 /* L40: */
00252     }
00253 
00254     indxq = (*n << 2) + 3;
00255     if (*icompq != 2) {
00256 
00257 /*        Set up workspaces for eigenvalues only/accumulate new vectors */
00258 /*        routine */
00259 
00260         temp = log((real) (*n)) / log(2.f);
00261         lgn = (integer) temp;
00262         if (pow_ii(&c__2, &lgn) < *n) {
00263             ++lgn;
00264         }
00265         if (pow_ii(&c__2, &lgn) < *n) {
00266             ++lgn;
00267         }
00268         iprmpt = indxq + *n + 1;
00269         iperm = iprmpt + *n * lgn;
00270         iqptr = iperm + *n * lgn;
00271         igivpt = iqptr + *n + 2;
00272         igivcl = igivpt + *n * lgn;
00273 
00274         igivnm = 1;
00275         iq = igivnm + (*n << 1) * lgn;
00276 /* Computing 2nd power */
00277         i__1 = *n;
00278         iwrem = iq + i__1 * i__1 + 1;
00279 
00280 /*        Initialize pointers */
00281 
00282         i__1 = subpbs;
00283         for (i__ = 0; i__ <= i__1; ++i__) {
00284             iwork[iprmpt + i__] = 1;
00285             iwork[igivpt + i__] = 1;
00286 /* L50: */
00287         }
00288         iwork[iqptr] = 1;
00289     }
00290 
00291 /*     Solve each submatrix eigenproblem at the bottom of the divide and */
00292 /*     conquer tree. */
00293 
00294     curr = 0;
00295     i__1 = spm1;
00296     for (i__ = 0; i__ <= i__1; ++i__) {
00297         if (i__ == 0) {
00298             submat = 1;
00299             matsiz = iwork[1];
00300         } else {
00301             submat = iwork[i__] + 1;
00302             matsiz = iwork[i__ + 1] - iwork[i__];
00303         }
00304         if (*icompq == 2) {
00305             ssteqr_("I", &matsiz, &d__[submat], &e[submat], &q[submat + 
00306                     submat * q_dim1], ldq, &work[1], info);
00307             if (*info != 0) {
00308                 goto L130;
00309             }
00310         } else {
00311             ssteqr_("I", &matsiz, &d__[submat], &e[submat], &work[iq - 1 + 
00312                     iwork[iqptr + curr]], &matsiz, &work[1], info);
00313             if (*info != 0) {
00314                 goto L130;
00315             }
00316             if (*icompq == 1) {
00317                 sgemm_("N", "N", qsiz, &matsiz, &matsiz, &c_b23, &q[submat * 
00318                         q_dim1 + 1], ldq, &work[iq - 1 + iwork[iqptr + curr]], 
00319                          &matsiz, &c_b24, &qstore[submat * qstore_dim1 + 1], 
00320                         ldqs);
00321             }
00322 /* Computing 2nd power */
00323             i__2 = matsiz;
00324             iwork[iqptr + curr + 1] = iwork[iqptr + curr] + i__2 * i__2;
00325             ++curr;
00326         }
00327         k = 1;
00328         i__2 = iwork[i__ + 1];
00329         for (j = submat; j <= i__2; ++j) {
00330             iwork[indxq + j] = k;
00331             ++k;
00332 /* L60: */
00333         }
00334 /* L70: */
00335     }
00336 
00337 /*     Successively merge eigensystems of adjacent submatrices */
00338 /*     into eigensystem for the corresponding larger matrix. */
00339 
00340 /*     while ( SUBPBS > 1 ) */
00341 
00342     curlvl = 1;
00343 L80:
00344     if (subpbs > 1) {
00345         spm2 = subpbs - 2;
00346         i__1 = spm2;
00347         for (i__ = 0; i__ <= i__1; i__ += 2) {
00348             if (i__ == 0) {
00349                 submat = 1;
00350                 matsiz = iwork[2];
00351                 msd2 = iwork[1];
00352                 curprb = 0;
00353             } else {
00354                 submat = iwork[i__] + 1;
00355                 matsiz = iwork[i__ + 2] - iwork[i__];
00356                 msd2 = matsiz / 2;
00357                 ++curprb;
00358             }
00359 
00360 /*     Merge lower order eigensystems (of size MSD2 and MATSIZ - MSD2) */
00361 /*     into an eigensystem of size MATSIZ. */
00362 /*     SLAED1 is used only for the full eigensystem of a tridiagonal */
00363 /*     matrix. */
00364 /*     SLAED7 handles the cases in which eigenvalues only or eigenvalues */
00365 /*     and eigenvectors of a full symmetric matrix (which was reduced to */
00366 /*     tridiagonal form) are desired. */
00367 
00368             if (*icompq == 2) {
00369                 slaed1_(&matsiz, &d__[submat], &q[submat + submat * q_dim1], 
00370                         ldq, &iwork[indxq + submat], &e[submat + msd2 - 1], &
00371                         msd2, &work[1], &iwork[subpbs + 1], info);
00372             } else {
00373                 slaed7_(icompq, &matsiz, qsiz, &tlvls, &curlvl, &curprb, &d__[
00374                         submat], &qstore[submat * qstore_dim1 + 1], ldqs, &
00375                         iwork[indxq + submat], &e[submat + msd2 - 1], &msd2, &
00376                         work[iq], &iwork[iqptr], &iwork[iprmpt], &iwork[iperm]
00377 , &iwork[igivpt], &iwork[igivcl], &work[igivnm], &
00378                         work[iwrem], &iwork[subpbs + 1], info);
00379             }
00380             if (*info != 0) {
00381                 goto L130;
00382             }
00383             iwork[i__ / 2 + 1] = iwork[i__ + 2];
00384 /* L90: */
00385         }
00386         subpbs /= 2;
00387         ++curlvl;
00388         goto L80;
00389     }
00390 
00391 /*     end while */
00392 
00393 /*     Re-merge the eigenvalues/vectors which were deflated at the final */
00394 /*     merge step. */
00395 
00396     if (*icompq == 1) {
00397         i__1 = *n;
00398         for (i__ = 1; i__ <= i__1; ++i__) {
00399             j = iwork[indxq + i__];
00400             work[i__] = d__[j];
00401             scopy_(qsiz, &qstore[j * qstore_dim1 + 1], &c__1, &q[i__ * q_dim1 
00402                     + 1], &c__1);
00403 /* L100: */
00404         }
00405         scopy_(n, &work[1], &c__1, &d__[1], &c__1);
00406     } else if (*icompq == 2) {
00407         i__1 = *n;
00408         for (i__ = 1; i__ <= i__1; ++i__) {
00409             j = iwork[indxq + i__];
00410             work[i__] = d__[j];
00411             scopy_(n, &q[j * q_dim1 + 1], &c__1, &work[*n * i__ + 1], &c__1);
00412 /* L110: */
00413         }
00414         scopy_(n, &work[1], &c__1, &d__[1], &c__1);
00415         slacpy_("A", n, n, &work[*n + 1], n, &q[q_offset], ldq);
00416     } else {
00417         i__1 = *n;
00418         for (i__ = 1; i__ <= i__1; ++i__) {
00419             j = iwork[indxq + i__];
00420             work[i__] = d__[j];
00421 /* L120: */
00422         }
00423         scopy_(n, &work[1], &c__1, &d__[1], &c__1);
00424     }
00425     goto L140;
00426 
00427 L130:
00428     *info = submat * (*n + 1) + submat + matsiz - 1;
00429 
00430 L140:
00431     return 0;
00432 
00433 /*     End of SLAED0 */
00434 
00435 } /* slaed0_ */


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