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


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