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


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