ssbevd.c
Go to the documentation of this file.
00001 /* ssbevd.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 real c_b11 = 1.f;
00019 static real c_b18 = 0.f;
00020 static integer c__1 = 1;
00021 
00022 /* Subroutine */ int ssbevd_(char *jobz, char *uplo, integer *n, integer *kd, 
00023         real *ab, integer *ldab, real *w, real *z__, integer *ldz, real *work, 
00024          integer *lwork, integer *iwork, integer *liwork, integer *info)
00025 {
00026     /* System generated locals */
00027     integer ab_dim1, ab_offset, z_dim1, z_offset, i__1;
00028     real r__1;
00029 
00030     /* Builtin functions */
00031     double sqrt(doublereal);
00032 
00033     /* Local variables */
00034     real eps;
00035     integer inde;
00036     real anrm, rmin, rmax, sigma;
00037     extern logical lsame_(char *, char *);
00038     integer iinfo;
00039     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *), 
00040             sgemm_(char *, char *, integer *, integer *, integer *, real *, 
00041             real *, integer *, real *, integer *, real *, real *, integer *);
00042     integer lwmin;
00043     logical lower, wantz;
00044     integer indwk2, llwrk2, iscale;
00045     extern doublereal slamch_(char *);
00046     real safmin;
00047     extern /* Subroutine */ int xerbla_(char *, integer *);
00048     real bignum;
00049     extern doublereal slansb_(char *, char *, integer *, integer *, real *, 
00050             integer *, real *);
00051     extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *, 
00052             real *, integer *, integer *, real *, integer *, integer *), sstedc_(char *, integer *, real *, real *, real *, 
00053             integer *, real *, integer *, integer *, integer *, integer *), slacpy_(char *, integer *, integer *, real *, integer *, 
00054             real *, integer *);
00055     integer indwrk, liwmin;
00056     extern /* Subroutine */ int ssbtrd_(char *, char *, integer *, integer *, 
00057             real *, integer *, real *, real *, real *, integer *, real *, 
00058             integer *), ssterf_(integer *, real *, real *, 
00059             integer *);
00060     real smlnum;
00061     logical lquery;
00062 
00063 
00064 /*  -- LAPACK driver routine (version 3.2) -- */
00065 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00066 /*     November 2006 */
00067 
00068 /*     .. Scalar Arguments .. */
00069 /*     .. */
00070 /*     .. Array Arguments .. */
00071 /*     .. */
00072 
00073 /*  Purpose */
00074 /*  ======= */
00075 
00076 /*  SSBEVD computes all the eigenvalues and, optionally, eigenvectors of */
00077 /*  a real symmetric band matrix A. If eigenvectors are desired, it uses */
00078 /*  a divide and conquer algorithm. */
00079 
00080 /*  The divide and conquer algorithm makes very mild assumptions about */
00081 /*  floating point arithmetic. It will work on machines with a guard */
00082 /*  digit in add/subtract, or on those binary machines without guard */
00083 /*  digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
00084 /*  Cray-2. It could conceivably fail on hexadecimal or decimal machines */
00085 /*  without guard digits, but we know of none. */
00086 
00087 /*  Arguments */
00088 /*  ========= */
00089 
00090 /*  JOBZ    (input) CHARACTER*1 */
00091 /*          = 'N':  Compute eigenvalues only; */
00092 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00093 
00094 /*  UPLO    (input) CHARACTER*1 */
00095 /*          = 'U':  Upper triangle of A is stored; */
00096 /*          = 'L':  Lower triangle of A is stored. */
00097 
00098 /*  N       (input) INTEGER */
00099 /*          The order of the matrix A.  N >= 0. */
00100 
00101 /*  KD      (input) INTEGER */
00102 /*          The number of superdiagonals of the matrix A if UPLO = 'U', */
00103 /*          or the number of subdiagonals if UPLO = 'L'.  KD >= 0. */
00104 
00105 /*  AB      (input/output) REAL array, dimension (LDAB, N) */
00106 /*          On entry, the upper or lower triangle of the symmetric band */
00107 /*          matrix A, stored in the first KD+1 rows of the array.  The */
00108 /*          j-th column of A is stored in the j-th column of the array AB */
00109 /*          as follows: */
00110 /*          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
00111 /*          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd). */
00112 
00113 /*          On exit, AB is overwritten by values generated during the */
00114 /*          reduction to tridiagonal form.  If UPLO = 'U', the first */
00115 /*          superdiagonal and the diagonal of the tridiagonal matrix T */
00116 /*          are returned in rows KD and KD+1 of AB, and if UPLO = 'L', */
00117 /*          the diagonal and first subdiagonal of T are returned in the */
00118 /*          first two rows of AB. */
00119 
00120 /*  LDAB    (input) INTEGER */
00121 /*          The leading dimension of the array AB.  LDAB >= KD + 1. */
00122 
00123 /*  W       (output) REAL array, dimension (N) */
00124 /*          If INFO = 0, the eigenvalues in ascending order. */
00125 
00126 /*  Z       (output) REAL array, dimension (LDZ, N) */
00127 /*          If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */
00128 /*          eigenvectors of the matrix A, with the i-th column of Z */
00129 /*          holding the eigenvector associated with W(i). */
00130 /*          If JOBZ = 'N', then Z is not referenced. */
00131 
00132 /*  LDZ     (input) INTEGER */
00133 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00134 /*          JOBZ = 'V', LDZ >= max(1,N). */
00135 
00136 /*  WORK    (workspace/output) REAL array, */
00137 /*                                         dimension (LWORK) */
00138 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00139 
00140 /*  LWORK   (input) INTEGER */
00141 /*          The dimension of the array WORK. */
00142 /*          IF N <= 1,                LWORK must be at least 1. */
00143 /*          If JOBZ  = 'N' and N > 2, LWORK must be at least 2*N. */
00144 /*          If JOBZ  = 'V' and N > 2, LWORK must be at least */
00145 /*                         ( 1 + 5*N + 2*N**2 ). */
00146 
00147 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00148 /*          only calculates the optimal sizes of the WORK and IWORK */
00149 /*          arrays, returns these values as the first entries of the WORK */
00150 /*          and IWORK arrays, and no error message related to LWORK or */
00151 /*          LIWORK is issued by XERBLA. */
00152 
00153 /*  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
00154 /*          On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
00155 
00156 /*  LIWORK  (input) INTEGER */
00157 /*          The dimension of the array LIWORK. */
00158 /*          If JOBZ  = 'N' or N <= 1, LIWORK must be at least 1. */
00159 /*          If JOBZ  = 'V' and N > 2, LIWORK must be at least 3 + 5*N. */
00160 
00161 /*          If LIWORK = -1, then a workspace query is assumed; the */
00162 /*          routine only calculates the optimal sizes of the WORK and */
00163 /*          IWORK arrays, returns these values as the first entries of */
00164 /*          the WORK and IWORK arrays, and no error message related to */
00165 /*          LWORK or LIWORK is issued by XERBLA. */
00166 
00167 /*  INFO    (output) INTEGER */
00168 /*          = 0:  successful exit */
00169 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00170 /*          > 0:  if INFO = i, the algorithm failed to converge; i */
00171 /*                off-diagonal elements of an intermediate tridiagonal */
00172 /*                form did not converge to zero. */
00173 
00174 /*  ===================================================================== */
00175 
00176 /*     .. Parameters .. */
00177 /*     .. */
00178 /*     .. Local Scalars .. */
00179 /*     .. */
00180 /*     .. External Functions .. */
00181 /*     .. */
00182 /*     .. External Subroutines .. */
00183 /*     .. */
00184 /*     .. Intrinsic Functions .. */
00185 /*     .. */
00186 /*     .. Executable Statements .. */
00187 
00188 /*     Test the input parameters. */
00189 
00190     /* Parameter adjustments */
00191     ab_dim1 = *ldab;
00192     ab_offset = 1 + ab_dim1;
00193     ab -= ab_offset;
00194     --w;
00195     z_dim1 = *ldz;
00196     z_offset = 1 + z_dim1;
00197     z__ -= z_offset;
00198     --work;
00199     --iwork;
00200 
00201     /* Function Body */
00202     wantz = lsame_(jobz, "V");
00203     lower = lsame_(uplo, "L");
00204     lquery = *lwork == -1 || *liwork == -1;
00205 
00206     *info = 0;
00207     if (*n <= 1) {
00208         liwmin = 1;
00209         lwmin = 1;
00210     } else {
00211         if (wantz) {
00212             liwmin = *n * 5 + 3;
00213 /* Computing 2nd power */
00214             i__1 = *n;
00215             lwmin = *n * 5 + 1 + (i__1 * i__1 << 1);
00216         } else {
00217             liwmin = 1;
00218             lwmin = *n << 1;
00219         }
00220     }
00221     if (! (wantz || lsame_(jobz, "N"))) {
00222         *info = -1;
00223     } else if (! (lower || lsame_(uplo, "U"))) {
00224         *info = -2;
00225     } else if (*n < 0) {
00226         *info = -3;
00227     } else if (*kd < 0) {
00228         *info = -4;
00229     } else if (*ldab < *kd + 1) {
00230         *info = -6;
00231     } else if (*ldz < 1 || wantz && *ldz < *n) {
00232         *info = -9;
00233     }
00234 
00235     if (*info == 0) {
00236         work[1] = (real) lwmin;
00237         iwork[1] = liwmin;
00238 
00239         if (*lwork < lwmin && ! lquery) {
00240             *info = -11;
00241         } else if (*liwork < liwmin && ! lquery) {
00242             *info = -13;
00243         }
00244     }
00245 
00246     if (*info != 0) {
00247         i__1 = -(*info);
00248         xerbla_("SSBEVD", &i__1);
00249         return 0;
00250     } else if (lquery) {
00251         return 0;
00252     }
00253 
00254 /*     Quick return if possible */
00255 
00256     if (*n == 0) {
00257         return 0;
00258     }
00259 
00260     if (*n == 1) {
00261         w[1] = ab[ab_dim1 + 1];
00262         if (wantz) {
00263             z__[z_dim1 + 1] = 1.f;
00264         }
00265         return 0;
00266     }
00267 
00268 /*     Get machine constants. */
00269 
00270     safmin = slamch_("Safe minimum");
00271     eps = slamch_("Precision");
00272     smlnum = safmin / eps;
00273     bignum = 1.f / smlnum;
00274     rmin = sqrt(smlnum);
00275     rmax = sqrt(bignum);
00276 
00277 /*     Scale matrix to allowable range, if necessary. */
00278 
00279     anrm = slansb_("M", uplo, n, kd, &ab[ab_offset], ldab, &work[1]);
00280     iscale = 0;
00281     if (anrm > 0.f && anrm < rmin) {
00282         iscale = 1;
00283         sigma = rmin / anrm;
00284     } else if (anrm > rmax) {
00285         iscale = 1;
00286         sigma = rmax / anrm;
00287     }
00288     if (iscale == 1) {
00289         if (lower) {
00290             slascl_("B", kd, kd, &c_b11, &sigma, n, n, &ab[ab_offset], ldab, 
00291                     info);
00292         } else {
00293             slascl_("Q", kd, kd, &c_b11, &sigma, n, n, &ab[ab_offset], ldab, 
00294                     info);
00295         }
00296     }
00297 
00298 /*     Call SSBTRD to reduce symmetric band matrix to tridiagonal form. */
00299 
00300     inde = 1;
00301     indwrk = inde + *n;
00302     indwk2 = indwrk + *n * *n;
00303     llwrk2 = *lwork - indwk2 + 1;
00304     ssbtrd_(jobz, uplo, n, kd, &ab[ab_offset], ldab, &w[1], &work[inde], &z__[
00305             z_offset], ldz, &work[indwrk], &iinfo);
00306 
00307 /*     For eigenvalues only, call SSTERF.  For eigenvectors, call SSTEDC. */
00308 
00309     if (! wantz) {
00310         ssterf_(n, &w[1], &work[inde], info);
00311     } else {
00312         sstedc_("I", n, &w[1], &work[inde], &work[indwrk], n, &work[indwk2], &
00313                 llwrk2, &iwork[1], liwork, info);
00314         sgemm_("N", "N", n, n, n, &c_b11, &z__[z_offset], ldz, &work[indwrk], 
00315                 n, &c_b18, &work[indwk2], n);
00316         slacpy_("A", n, n, &work[indwk2], n, &z__[z_offset], ldz);
00317     }
00318 
00319 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00320 
00321     if (iscale == 1) {
00322         r__1 = 1.f / sigma;
00323         sscal_(n, &r__1, &w[1], &c__1);
00324     }
00325 
00326     work[1] = (real) lwmin;
00327     iwork[1] = liwmin;
00328     return 0;
00329 
00330 /*     End of SSBEVD */
00331 
00332 } /* ssbevd_ */


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