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


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