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


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