dsyevd.c
Go to the documentation of this file.
00001 /* dsyevd.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__1 = 1;
00019 static integer c_n1 = -1;
00020 static integer c__0 = 0;
00021 static doublereal c_b17 = 1.;
00022 
00023 /* Subroutine */ int dsyevd_(char *jobz, char *uplo, integer *n, doublereal *
00024         a, integer *lda, doublereal *w, doublereal *work, integer *lwork, 
00025         integer *iwork, integer *liwork, integer *info)
00026 {
00027     /* System generated locals */
00028     integer a_dim1, a_offset, i__1, i__2, i__3;
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     integer lopt;
00039     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00040             integer *);
00041     doublereal sigma;
00042     extern logical lsame_(char *, char *);
00043     integer iinfo, lwmin, liopt;
00044     logical lower, wantz;
00045     integer indwk2, llwrk2;
00046     extern doublereal dlamch_(char *);
00047     integer iscale;
00048     extern /* Subroutine */ int dlascl_(char *, integer *, integer *, 
00049             doublereal *, doublereal *, integer *, integer *, doublereal *, 
00050             integer *, integer *), dstedc_(char *, integer *, 
00051             doublereal *, doublereal *, doublereal *, integer *, doublereal *, 
00052              integer *, integer *, integer *, integer *), dlacpy_(
00053             char *, integer *, integer *, doublereal *, integer *, doublereal 
00054             *, integer *);
00055     doublereal safmin;
00056     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00057             integer *, integer *);
00058     extern /* Subroutine */ int xerbla_(char *, integer *);
00059     doublereal bignum;
00060     integer indtau;
00061     extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *, 
00062              integer *);
00063     extern doublereal dlansy_(char *, char *, integer *, doublereal *, 
00064             integer *, doublereal *);
00065     integer indwrk, liwmin;
00066     extern /* Subroutine */ int dormtr_(char *, char *, char *, integer *, 
00067             integer *, doublereal *, integer *, doublereal *, doublereal *, 
00068             integer *, doublereal *, integer *, integer *), dsytrd_(char *, integer *, doublereal *, integer *, 
00069             doublereal *, doublereal *, doublereal *, doublereal *, integer *, 
00070              integer *);
00071     integer llwork;
00072     doublereal smlnum;
00073     logical lquery;
00074 
00075 
00076 /*  -- LAPACK driver routine (version 3.2) -- */
00077 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00078 /*     November 2006 */
00079 
00080 /*     .. Scalar Arguments .. */
00081 /*     .. */
00082 /*     .. Array Arguments .. */
00083 /*     .. */
00084 
00085 /*  Purpose */
00086 /*  ======= */
00087 
00088 /*  DSYEVD computes all eigenvalues and, optionally, eigenvectors of a */
00089 /*  real symmetric matrix A. If eigenvectors are desired, it uses a */
00090 /*  divide and conquer algorithm. */
00091 
00092 /*  The divide and conquer algorithm makes very mild assumptions about */
00093 /*  floating point arithmetic. It will work on machines with a guard */
00094 /*  digit in add/subtract, or on those binary machines without guard */
00095 /*  digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
00096 /*  Cray-2. It could conceivably fail on hexadecimal or decimal machines */
00097 /*  without guard digits, but we know of none. */
00098 
00099 /*  Because of large use of BLAS of level 3, DSYEVD needs N**2 more */
00100 /*  workspace than DSYEVX. */
00101 
00102 /*  Arguments */
00103 /*  ========= */
00104 
00105 /*  JOBZ    (input) CHARACTER*1 */
00106 /*          = 'N':  Compute eigenvalues only; */
00107 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00108 
00109 /*  UPLO    (input) CHARACTER*1 */
00110 /*          = 'U':  Upper triangle of A is stored; */
00111 /*          = 'L':  Lower triangle of A is stored. */
00112 
00113 /*  N       (input) INTEGER */
00114 /*          The order of the matrix A.  N >= 0. */
00115 
00116 /*  A       (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
00117 /*          On entry, the symmetric matrix A.  If UPLO = 'U', the */
00118 /*          leading N-by-N upper triangular part of A contains the */
00119 /*          upper triangular part of the matrix A.  If UPLO = 'L', */
00120 /*          the leading N-by-N lower triangular part of A contains */
00121 /*          the lower triangular part of the matrix A. */
00122 /*          On exit, if JOBZ = 'V', then if INFO = 0, A contains the */
00123 /*          orthonormal eigenvectors of the matrix A. */
00124 /*          If JOBZ = 'N', then on exit the lower triangle (if UPLO='L') */
00125 /*          or the upper triangle (if UPLO='U') of A, including the */
00126 /*          diagonal, is destroyed. */
00127 
00128 /*  LDA     (input) INTEGER */
00129 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00130 
00131 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00132 /*          If INFO = 0, the eigenvalues in ascending order. */
00133 
00134 /*  WORK    (workspace/output) DOUBLE PRECISION array, */
00135 /*                                         dimension (LWORK) */
00136 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00137 
00138 /*  LWORK   (input) INTEGER */
00139 /*          The dimension of the array WORK. */
00140 /*          If N <= 1,               LWORK must be at least 1. */
00141 /*          If JOBZ = 'N' and N > 1, LWORK must be at least 2*N+1. */
00142 /*          If JOBZ = 'V' and N > 1, LWORK must be at least */
00143 /*                                                1 + 6*N + 2*N**2. */
00144 
00145 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00146 /*          only calculates the optimal sizes of the WORK and IWORK */
00147 /*          arrays, returns these values as the first entries of the WORK */
00148 /*          and IWORK arrays, and no error message related to LWORK or */
00149 /*          LIWORK is issued by XERBLA. */
00150 
00151 /*  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
00152 /*          On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
00153 
00154 /*  LIWORK  (input) INTEGER */
00155 /*          The dimension of the array IWORK. */
00156 /*          If N <= 1,                LIWORK must be at least 1. */
00157 /*          If JOBZ  = 'N' and N > 1, LIWORK must be at least 1. */
00158 /*          If JOBZ  = 'V' and N > 1, LIWORK must be at least 3 + 5*N. */
00159 
00160 /*          If LIWORK = -1, then a workspace query is assumed; the */
00161 /*          routine only calculates the optimal sizes of the WORK and */
00162 /*          IWORK arrays, returns these values as the first entries of */
00163 /*          the WORK and IWORK arrays, and no error message related to */
00164 /*          LWORK or LIWORK is issued by XERBLA. */
00165 
00166 /*  INFO    (output) INTEGER */
00167 /*          = 0:  successful exit */
00168 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00169 /*          > 0:  if INFO = i and JOBZ = 'N', then the algorithm failed */
00170 /*                to converge; i off-diagonal elements of an intermediate */
00171 /*                tridiagonal form did not converge to zero; */
00172 /*                if INFO = i and JOBZ = 'V', then the algorithm failed */
00173 /*                to compute an eigenvalue while working on the submatrix */
00174 /*                lying in rows and columns INFO/(N+1) through */
00175 /*                mod(INFO,N+1). */
00176 
00177 /*  Further Details */
00178 /*  =============== */
00179 
00180 /*  Based on contributions by */
00181 /*     Jeff Rutter, Computer Science Division, University of California */
00182 /*     at Berkeley, USA */
00183 /*  Modified by Francoise Tisseur, University of Tennessee. */
00184 
00185 /*  Modified description of INFO. Sven, 16 Feb 05. */
00186 /*  ===================================================================== */
00187 
00188 /*     .. Parameters .. */
00189 /*     .. */
00190 /*     .. Local Scalars .. */
00191 
00192 /*     .. */
00193 /*     .. External Functions .. */
00194 /*     .. */
00195 /*     .. External Subroutines .. */
00196 /*     .. */
00197 /*     .. Intrinsic Functions .. */
00198 /*     .. */
00199 /*     .. Executable Statements .. */
00200 
00201 /*     Test the input parameters. */
00202 
00203     /* Parameter adjustments */
00204     a_dim1 = *lda;
00205     a_offset = 1 + a_dim1;
00206     a -= a_offset;
00207     --w;
00208     --work;
00209     --iwork;
00210 
00211     /* Function Body */
00212     wantz = lsame_(jobz, "V");
00213     lower = lsame_(uplo, "L");
00214     lquery = *lwork == -1 || *liwork == -1;
00215 
00216     *info = 0;
00217     if (! (wantz || lsame_(jobz, "N"))) {
00218         *info = -1;
00219     } else if (! (lower || lsame_(uplo, "U"))) {
00220         *info = -2;
00221     } else if (*n < 0) {
00222         *info = -3;
00223     } else if (*lda < max(1,*n)) {
00224         *info = -5;
00225     }
00226 
00227     if (*info == 0) {
00228         if (*n <= 1) {
00229             liwmin = 1;
00230             lwmin = 1;
00231             lopt = lwmin;
00232             liopt = liwmin;
00233         } else {
00234             if (wantz) {
00235                 liwmin = *n * 5 + 3;
00236 /* Computing 2nd power */
00237                 i__1 = *n;
00238                 lwmin = *n * 6 + 1 + (i__1 * i__1 << 1);
00239             } else {
00240                 liwmin = 1;
00241                 lwmin = (*n << 1) + 1;
00242             }
00243 /* Computing MAX */
00244             i__1 = lwmin, i__2 = (*n << 1) + ilaenv_(&c__1, "DSYTRD", uplo, n, 
00245                      &c_n1, &c_n1, &c_n1);
00246             lopt = max(i__1,i__2);
00247             liopt = liwmin;
00248         }
00249         work[1] = (doublereal) lopt;
00250         iwork[1] = liopt;
00251 
00252         if (*lwork < lwmin && ! lquery) {
00253             *info = -8;
00254         } else if (*liwork < liwmin && ! lquery) {
00255             *info = -10;
00256         }
00257     }
00258 
00259     if (*info != 0) {
00260         i__1 = -(*info);
00261         xerbla_("DSYEVD", &i__1);
00262         return 0;
00263     } else if (lquery) {
00264         return 0;
00265     }
00266 
00267 /*     Quick return if possible */
00268 
00269     if (*n == 0) {
00270         return 0;
00271     }
00272 
00273     if (*n == 1) {
00274         w[1] = a[a_dim1 + 1];
00275         if (wantz) {
00276             a[a_dim1 + 1] = 1.;
00277         }
00278         return 0;
00279     }
00280 
00281 /*     Get machine constants. */
00282 
00283     safmin = dlamch_("Safe minimum");
00284     eps = dlamch_("Precision");
00285     smlnum = safmin / eps;
00286     bignum = 1. / smlnum;
00287     rmin = sqrt(smlnum);
00288     rmax = sqrt(bignum);
00289 
00290 /*     Scale matrix to allowable range, if necessary. */
00291 
00292     anrm = dlansy_("M", uplo, n, &a[a_offset], lda, &work[1]);
00293     iscale = 0;
00294     if (anrm > 0. && anrm < rmin) {
00295         iscale = 1;
00296         sigma = rmin / anrm;
00297     } else if (anrm > rmax) {
00298         iscale = 1;
00299         sigma = rmax / anrm;
00300     }
00301     if (iscale == 1) {
00302         dlascl_(uplo, &c__0, &c__0, &c_b17, &sigma, n, n, &a[a_offset], lda, 
00303                 info);
00304     }
00305 
00306 /*     Call DSYTRD to reduce symmetric matrix to tridiagonal form. */
00307 
00308     inde = 1;
00309     indtau = inde + *n;
00310     indwrk = indtau + *n;
00311     llwork = *lwork - indwrk + 1;
00312     indwk2 = indwrk + *n * *n;
00313     llwrk2 = *lwork - indwk2 + 1;
00314 
00315     dsytrd_(uplo, n, &a[a_offset], lda, &w[1], &work[inde], &work[indtau], &
00316             work[indwrk], &llwork, &iinfo);
00317     lopt = (integer) ((*n << 1) + work[indwrk]);
00318 
00319 /*     For eigenvalues only, call DSTERF.  For eigenvectors, first call */
00320 /*     DSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the */
00321 /*     tridiagonal matrix, then call DORMTR to multiply it by the */
00322 /*     Householder transformations stored in A. */
00323 
00324     if (! wantz) {
00325         dsterf_(n, &w[1], &work[inde], info);
00326     } else {
00327         dstedc_("I", n, &w[1], &work[inde], &work[indwrk], n, &work[indwk2], &
00328                 llwrk2, &iwork[1], liwork, info);
00329         dormtr_("L", uplo, "N", n, n, &a[a_offset], lda, &work[indtau], &work[
00330                 indwrk], n, &work[indwk2], &llwrk2, &iinfo);
00331         dlacpy_("A", n, n, &work[indwrk], n, &a[a_offset], lda);
00332 /* Computing MAX */
00333 /* Computing 2nd power */
00334         i__3 = *n;
00335         i__1 = lopt, i__2 = *n * 6 + 1 + (i__3 * i__3 << 1);
00336         lopt = max(i__1,i__2);
00337     }
00338 
00339 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00340 
00341     if (iscale == 1) {
00342         d__1 = 1. / sigma;
00343         dscal_(n, &d__1, &w[1], &c__1);
00344     }
00345 
00346     work[1] = (doublereal) lopt;
00347     iwork[1] = liopt;
00348 
00349     return 0;
00350 
00351 /*     End of DSYEVD */
00352 
00353 } /* dsyevd_ */


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