sstedc.c
Go to the documentation of this file.
00001 /* sstedc.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_b17 = 0.f;
00022 static real c_b18 = 1.f;
00023 static integer c__1 = 1;
00024 
00025 /* Subroutine */ int sstedc_(char *compz, integer *n, real *d__, real *e, 
00026         real *z__, integer *ldz, real *work, integer *lwork, integer *iwork, 
00027         integer *liwork, integer *info)
00028 {
00029     /* System generated locals */
00030     integer z_dim1, z_offset, i__1, i__2;
00031     real r__1, r__2;
00032 
00033     /* Builtin functions */
00034     double log(doublereal);
00035     integer pow_ii(integer *, integer *);
00036     double sqrt(doublereal);
00037 
00038     /* Local variables */
00039     integer i__, j, k, m;
00040     real p;
00041     integer ii, lgn;
00042     real eps, tiny;
00043     extern logical lsame_(char *, char *);
00044     extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *, 
00045             integer *, real *, real *, integer *, real *, integer *, real *, 
00046             real *, integer *);
00047     integer lwmin, start;
00048     extern /* Subroutine */ int sswap_(integer *, real *, integer *, real *, 
00049             integer *), slaed0_(integer *, integer *, integer *, real *, real 
00050             *, real *, integer *, real *, integer *, real *, integer *, 
00051             integer *);
00052     extern doublereal slamch_(char *);
00053     extern /* Subroutine */ int xerbla_(char *, integer *);
00054     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00055             integer *, integer *);
00056     integer finish;
00057     extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *, 
00058             real *, integer *, integer *, real *, integer *, integer *), slacpy_(char *, integer *, integer *, real *, integer *, 
00059             real *, integer *), slaset_(char *, integer *, integer *, 
00060             real *, real *, real *, integer *);
00061     integer liwmin, icompz;
00062     real orgnrm;
00063     extern doublereal slanst_(char *, integer *, real *, real *);
00064     extern /* Subroutine */ int ssterf_(integer *, real *, real *, integer *),
00065              slasrt_(char *, integer *, real *, integer *);
00066     logical lquery;
00067     integer smlsiz;
00068     extern /* Subroutine */ int ssteqr_(char *, integer *, real *, real *, 
00069             real *, integer *, real *, integer *);
00070     integer storez, strtrw;
00071 
00072 
00073 /*  -- LAPACK driver routine (version 3.2) -- */
00074 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00075 /*     November 2006 */
00076 
00077 /*     .. Scalar Arguments .. */
00078 /*     .. */
00079 /*     .. Array Arguments .. */
00080 /*     .. */
00081 
00082 /*  Purpose */
00083 /*  ======= */
00084 
00085 /*  SSTEDC computes all eigenvalues and, optionally, eigenvectors of a */
00086 /*  symmetric tridiagonal matrix using the divide and conquer method. */
00087 /*  The eigenvectors of a full or band real symmetric matrix can also be */
00088 /*  found if SSYTRD or SSPTRD or SSBTRD has been used to reduce this */
00089 /*  matrix to tridiagonal form. */
00090 
00091 /*  This code makes very mild assumptions about floating point */
00092 /*  arithmetic. It will work on machines with a guard digit in */
00093 /*  add/subtract, or on those binary machines without guard digits */
00094 /*  which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or Cray-2. */
00095 /*  It could conceivably fail on hexadecimal or decimal machines */
00096 /*  without guard digits, but we know of none.  See SLAED3 for details. */
00097 
00098 /*  Arguments */
00099 /*  ========= */
00100 
00101 /*  COMPZ   (input) CHARACTER*1 */
00102 /*          = 'N':  Compute eigenvalues only. */
00103 /*          = 'I':  Compute eigenvectors of tridiagonal matrix also. */
00104 /*          = 'V':  Compute eigenvectors of original dense symmetric */
00105 /*                  matrix also.  On entry, Z contains the orthogonal */
00106 /*                  matrix used to reduce the original matrix to */
00107 /*                  tridiagonal form. */
00108 
00109 /*  N       (input) INTEGER */
00110 /*          The dimension of the symmetric tridiagonal matrix.  N >= 0. */
00111 
00112 /*  D       (input/output) REAL array, dimension (N) */
00113 /*          On entry, the diagonal elements of the tridiagonal matrix. */
00114 /*          On exit, if INFO = 0, the eigenvalues in ascending order. */
00115 
00116 /*  E       (input/output) REAL array, dimension (N-1) */
00117 /*          On entry, the subdiagonal elements of the tridiagonal matrix. */
00118 /*          On exit, E has been destroyed. */
00119 
00120 /*  Z       (input/output) REAL array, dimension (LDZ,N) */
00121 /*          On entry, if COMPZ = 'V', then Z contains the orthogonal */
00122 /*          matrix used in the reduction to tridiagonal form. */
00123 /*          On exit, if INFO = 0, then if COMPZ = 'V', Z contains the */
00124 /*          orthonormal eigenvectors of the original symmetric matrix, */
00125 /*          and if COMPZ = 'I', Z contains the orthonormal eigenvectors */
00126 /*          of the symmetric tridiagonal matrix. */
00127 /*          If  COMPZ = 'N', then Z is not referenced. */
00128 
00129 /*  LDZ     (input) INTEGER */
00130 /*          The leading dimension of the array Z.  LDZ >= 1. */
00131 /*          If eigenvectors are desired, then LDZ >= max(1,N). */
00132 
00133 /*  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK)) */
00134 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00135 
00136 /*  LWORK   (input) INTEGER */
00137 /*          The dimension of the array WORK. */
00138 /*          If COMPZ = 'N' or N <= 1 then LWORK must be at least 1. */
00139 /*          If COMPZ = 'V' and N > 1 then LWORK must be at least */
00140 /*                         ( 1 + 3*N + 2*N*lg N + 3*N**2 ), */
00141 /*                         where lg( N ) = smallest integer k such */
00142 /*                         that 2**k >= N. */
00143 /*          If COMPZ = 'I' and N > 1 then LWORK must be at least */
00144 /*                         ( 1 + 4*N + N**2 ). */
00145 /*          Note that for COMPZ = 'I' or 'V', then if N is less than or */
00146 /*          equal to the minimum divide size, usually 25, then LWORK need */
00147 /*          only be max(1,2*(N-1)). */
00148 
00149 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00150 /*          only calculates the optimal size of the WORK array, returns */
00151 /*          this value as the first entry of the WORK array, and no error */
00152 /*          message related to LWORK is issued by XERBLA. */
00153 
00154 /*  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
00155 /*          On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
00156 
00157 /*  LIWORK  (input) INTEGER */
00158 /*          The dimension of the array IWORK. */
00159 /*          If COMPZ = 'N' or N <= 1 then LIWORK must be at least 1. */
00160 /*          If COMPZ = 'V' and N > 1 then LIWORK must be at least */
00161 /*                         ( 6 + 6*N + 5*N*lg N ). */
00162 /*          If COMPZ = 'I' and N > 1 then LIWORK must be at least */
00163 /*                         ( 3 + 5*N ). */
00164 /*          Note that for COMPZ = 'I' or 'V', then if N is less than or */
00165 /*          equal to the minimum divide size, usually 25, then LIWORK */
00166 /*          need only be 1. */
00167 
00168 /*          If LIWORK = -1, then a workspace query is assumed; the */
00169 /*          routine only calculates the optimal size of the IWORK array, */
00170 /*          returns this value as the first entry of the IWORK array, and */
00171 /*          no error message related to LIWORK is issued by XERBLA. */
00172 
00173 /*  INFO    (output) INTEGER */
00174 /*          = 0:  successful exit. */
00175 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00176 /*          > 0:  The algorithm failed to compute an eigenvalue while */
00177 /*                working on the submatrix lying in rows and columns */
00178 /*                INFO/(N+1) through mod(INFO,N+1). */
00179 
00180 /*  Further Details */
00181 /*  =============== */
00182 
00183 /*  Based on contributions by */
00184 /*     Jeff Rutter, Computer Science Division, University of California */
00185 /*     at Berkeley, USA */
00186 /*  Modified by Francoise Tisseur, University of Tennessee. */
00187 
00188 /*  ===================================================================== */
00189 
00190 /*     .. Parameters .. */
00191 /*     .. */
00192 /*     .. Local Scalars .. */
00193 /*     .. */
00194 /*     .. External Functions .. */
00195 /*     .. */
00196 /*     .. External Subroutines .. */
00197 /*     .. */
00198 /*     .. Intrinsic Functions .. */
00199 /*     .. */
00200 /*     .. Executable Statements .. */
00201 
00202 /*     Test the input parameters. */
00203 
00204     /* Parameter adjustments */
00205     --d__;
00206     --e;
00207     z_dim1 = *ldz;
00208     z_offset = 1 + z_dim1;
00209     z__ -= z_offset;
00210     --work;
00211     --iwork;
00212 
00213     /* Function Body */
00214     *info = 0;
00215     lquery = *lwork == -1 || *liwork == -1;
00216 
00217     if (lsame_(compz, "N")) {
00218         icompz = 0;
00219     } else if (lsame_(compz, "V")) {
00220         icompz = 1;
00221     } else if (lsame_(compz, "I")) {
00222         icompz = 2;
00223     } else {
00224         icompz = -1;
00225     }
00226     if (icompz < 0) {
00227         *info = -1;
00228     } else if (*n < 0) {
00229         *info = -2;
00230     } else if (*ldz < 1 || icompz > 0 && *ldz < max(1,*n)) {
00231         *info = -6;
00232     }
00233 
00234     if (*info == 0) {
00235 
00236 /*        Compute the workspace requirements */
00237 
00238         smlsiz = ilaenv_(&c__9, "SSTEDC", " ", &c__0, &c__0, &c__0, &c__0);
00239         if (*n <= 1 || icompz == 0) {
00240             liwmin = 1;
00241             lwmin = 1;
00242         } else if (*n <= smlsiz) {
00243             liwmin = 1;
00244             lwmin = *n - 1 << 1;
00245         } else {
00246             lgn = (integer) (log((real) (*n)) / log(2.f));
00247             if (pow_ii(&c__2, &lgn) < *n) {
00248                 ++lgn;
00249             }
00250             if (pow_ii(&c__2, &lgn) < *n) {
00251                 ++lgn;
00252             }
00253             if (icompz == 1) {
00254 /* Computing 2nd power */
00255                 i__1 = *n;
00256                 lwmin = *n * 3 + 1 + (*n << 1) * lgn + i__1 * i__1 * 3;
00257                 liwmin = *n * 6 + 6 + *n * 5 * lgn;
00258             } else if (icompz == 2) {
00259 /* Computing 2nd power */
00260                 i__1 = *n;
00261                 lwmin = (*n << 2) + 1 + i__1 * i__1;
00262                 liwmin = *n * 5 + 3;
00263             }
00264         }
00265         work[1] = (real) lwmin;
00266         iwork[1] = liwmin;
00267 
00268         if (*lwork < lwmin && ! lquery) {
00269             *info = -8;
00270         } else if (*liwork < liwmin && ! lquery) {
00271             *info = -10;
00272         }
00273     }
00274 
00275     if (*info != 0) {
00276         i__1 = -(*info);
00277         xerbla_("SSTEDC", &i__1);
00278         return 0;
00279     } else if (lquery) {
00280         return 0;
00281     }
00282 
00283 /*     Quick return if possible */
00284 
00285     if (*n == 0) {
00286         return 0;
00287     }
00288     if (*n == 1) {
00289         if (icompz != 0) {
00290             z__[z_dim1 + 1] = 1.f;
00291         }
00292         return 0;
00293     }
00294 
00295 /*     If the following conditional clause is removed, then the routine */
00296 /*     will use the Divide and Conquer routine to compute only the */
00297 /*     eigenvalues, which requires (3N + 3N**2) real workspace and */
00298 /*     (2 + 5N + 2N lg(N)) integer workspace. */
00299 /*     Since on many architectures SSTERF is much faster than any other */
00300 /*     algorithm for finding eigenvalues only, it is used here */
00301 /*     as the default. If the conditional clause is removed, then */
00302 /*     information on the size of workspace needs to be changed. */
00303 
00304 /*     If COMPZ = 'N', use SSTERF to compute the eigenvalues. */
00305 
00306     if (icompz == 0) {
00307         ssterf_(n, &d__[1], &e[1], info);
00308         goto L50;
00309     }
00310 
00311 /*     If N is smaller than the minimum divide size (SMLSIZ+1), then */
00312 /*     solve the problem with another solver. */
00313 
00314     if (*n <= smlsiz) {
00315 
00316         ssteqr_(compz, n, &d__[1], &e[1], &z__[z_offset], ldz, &work[1], info);
00317 
00318     } else {
00319 
00320 /*        If COMPZ = 'V', the Z matrix must be stored elsewhere for later */
00321 /*        use. */
00322 
00323         if (icompz == 1) {
00324             storez = *n * *n + 1;
00325         } else {
00326             storez = 1;
00327         }
00328 
00329         if (icompz == 2) {
00330             slaset_("Full", n, n, &c_b17, &c_b18, &z__[z_offset], ldz);
00331         }
00332 
00333 /*        Scale. */
00334 
00335         orgnrm = slanst_("M", n, &d__[1], &e[1]);
00336         if (orgnrm == 0.f) {
00337             goto L50;
00338         }
00339 
00340         eps = slamch_("Epsilon");
00341 
00342         start = 1;
00343 
00344 /*        while ( START <= N ) */
00345 
00346 L10:
00347         if (start <= *n) {
00348 
00349 /*           Let FINISH be the position of the next subdiagonal entry */
00350 /*           such that E( FINISH ) <= TINY or FINISH = N if no such */
00351 /*           subdiagonal exists.  The matrix identified by the elements */
00352 /*           between START and FINISH constitutes an independent */
00353 /*           sub-problem. */
00354 
00355             finish = start;
00356 L20:
00357             if (finish < *n) {
00358                 tiny = eps * sqrt((r__1 = d__[finish], dabs(r__1))) * sqrt((
00359                         r__2 = d__[finish + 1], dabs(r__2)));
00360                 if ((r__1 = e[finish], dabs(r__1)) > tiny) {
00361                     ++finish;
00362                     goto L20;
00363                 }
00364             }
00365 
00366 /*           (Sub) Problem determined.  Compute its size and solve it. */
00367 
00368             m = finish - start + 1;
00369             if (m == 1) {
00370                 start = finish + 1;
00371                 goto L10;
00372             }
00373             if (m > smlsiz) {
00374 
00375 /*              Scale. */
00376 
00377                 orgnrm = slanst_("M", &m, &d__[start], &e[start]);
00378                 slascl_("G", &c__0, &c__0, &orgnrm, &c_b18, &m, &c__1, &d__[
00379                         start], &m, info);
00380                 i__1 = m - 1;
00381                 i__2 = m - 1;
00382                 slascl_("G", &c__0, &c__0, &orgnrm, &c_b18, &i__1, &c__1, &e[
00383                         start], &i__2, info);
00384 
00385                 if (icompz == 1) {
00386                     strtrw = 1;
00387                 } else {
00388                     strtrw = start;
00389                 }
00390                 slaed0_(&icompz, n, &m, &d__[start], &e[start], &z__[strtrw + 
00391                         start * z_dim1], ldz, &work[1], n, &work[storez], &
00392                         iwork[1], info);
00393                 if (*info != 0) {
00394                     *info = (*info / (m + 1) + start - 1) * (*n + 1) + *info %
00395                              (m + 1) + start - 1;
00396                     goto L50;
00397                 }
00398 
00399 /*              Scale back. */
00400 
00401                 slascl_("G", &c__0, &c__0, &c_b18, &orgnrm, &m, &c__1, &d__[
00402                         start], &m, info);
00403 
00404             } else {
00405                 if (icompz == 1) {
00406 
00407 /*                 Since QR won't update a Z matrix which is larger than */
00408 /*                 the length of D, we must solve the sub-problem in a */
00409 /*                 workspace and then multiply back into Z. */
00410 
00411                     ssteqr_("I", &m, &d__[start], &e[start], &work[1], &m, &
00412                             work[m * m + 1], info);
00413                     slacpy_("A", n, &m, &z__[start * z_dim1 + 1], ldz, &work[
00414                             storez], n);
00415                     sgemm_("N", "N", n, &m, &m, &c_b18, &work[storez], n, &
00416                             work[1], &m, &c_b17, &z__[start * z_dim1 + 1], 
00417                             ldz);
00418                 } else if (icompz == 2) {
00419                     ssteqr_("I", &m, &d__[start], &e[start], &z__[start + 
00420                             start * z_dim1], ldz, &work[1], info);
00421                 } else {
00422                     ssterf_(&m, &d__[start], &e[start], info);
00423                 }
00424                 if (*info != 0) {
00425                     *info = start * (*n + 1) + finish;
00426                     goto L50;
00427                 }
00428             }
00429 
00430             start = finish + 1;
00431             goto L10;
00432         }
00433 
00434 /*        endwhile */
00435 
00436 /*        If the problem split any number of times, then the eigenvalues */
00437 /*        will not be properly ordered.  Here we permute the eigenvalues */
00438 /*        (and the associated eigenvectors) into ascending order. */
00439 
00440         if (m != *n) {
00441             if (icompz == 0) {
00442 
00443 /*              Use Quick Sort */
00444 
00445                 slasrt_("I", n, &d__[1], info);
00446 
00447             } else {
00448 
00449 /*              Use Selection Sort to minimize swaps of eigenvectors */
00450 
00451                 i__1 = *n;
00452                 for (ii = 2; ii <= i__1; ++ii) {
00453                     i__ = ii - 1;
00454                     k = i__;
00455                     p = d__[i__];
00456                     i__2 = *n;
00457                     for (j = ii; j <= i__2; ++j) {
00458                         if (d__[j] < p) {
00459                             k = j;
00460                             p = d__[j];
00461                         }
00462 /* L30: */
00463                     }
00464                     if (k != i__) {
00465                         d__[k] = d__[i__];
00466                         d__[i__] = p;
00467                         sswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[k * 
00468                                 z_dim1 + 1], &c__1);
00469                     }
00470 /* L40: */
00471                 }
00472             }
00473         }
00474     }
00475 
00476 L50:
00477     work[1] = (real) lwmin;
00478     iwork[1] = liwmin;
00479 
00480     return 0;
00481 
00482 /*     End of SSTEDC */
00483 
00484 } /* sstedc_ */


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