chegvd.c
Go to the documentation of this file.
00001 /* chegvd.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 complex c_b1 = {1.f,0.f};
00019 
00020 /* Subroutine */ int chegvd_(integer *itype, char *jobz, char *uplo, integer *
00021         n, complex *a, integer *lda, complex *b, integer *ldb, real *w, 
00022         complex *work, integer *lwork, real *rwork, integer *lrwork, integer *
00023         iwork, integer *liwork, integer *info)
00024 {
00025     /* System generated locals */
00026     integer a_dim1, a_offset, b_dim1, b_offset, i__1;
00027     real r__1, r__2;
00028 
00029     /* Local variables */
00030     integer lopt;
00031     extern logical lsame_(char *, char *);
00032     extern /* Subroutine */ int ctrmm_(char *, char *, char *, char *, 
00033             integer *, integer *, complex *, complex *, integer *, complex *, 
00034             integer *);
00035     integer lwmin;
00036     char trans[1];
00037     integer liopt;
00038     extern /* Subroutine */ int ctrsm_(char *, char *, char *, char *, 
00039             integer *, integer *, complex *, complex *, integer *, complex *, 
00040             integer *);
00041     logical upper;
00042     integer lropt;
00043     logical wantz;
00044     extern /* Subroutine */ int cheevd_(char *, char *, integer *, complex *, 
00045             integer *, real *, complex *, integer *, real *, integer *, 
00046             integer *, integer *, integer *), chegst_(integer 
00047             *, char *, integer *, complex *, integer *, complex *, integer *, 
00048             integer *), xerbla_(char *, integer *), cpotrf_(
00049             char *, integer *, complex *, integer *, integer *);
00050     integer liwmin, lrwmin;
00051     logical lquery;
00052 
00053 
00054 /*  -- LAPACK driver routine (version 3.2) -- */
00055 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00056 /*     November 2006 */
00057 
00058 /*     .. Scalar Arguments .. */
00059 /*     .. */
00060 /*     .. Array Arguments .. */
00061 /*     .. */
00062 
00063 /*  Purpose */
00064 /*  ======= */
00065 
00066 /*  CHEGVD computes all the eigenvalues, and optionally, the eigenvectors */
00067 /*  of a complex generalized Hermitian-definite eigenproblem, of the form */
00068 /*  A*x=(lambda)*B*x,  A*Bx=(lambda)*x,  or B*A*x=(lambda)*x.  Here A and */
00069 /*  B are assumed to be Hermitian and B is also positive definite. */
00070 /*  If eigenvectors are desired, it uses a divide and conquer algorithm. */
00071 
00072 /*  The divide and conquer algorithm makes very mild assumptions about */
00073 /*  floating point arithmetic. It will work on machines with a guard */
00074 /*  digit in add/subtract, or on those binary machines without guard */
00075 /*  digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
00076 /*  Cray-2. It could conceivably fail on hexadecimal or decimal machines */
00077 /*  without guard digits, but we know of none. */
00078 
00079 /*  Arguments */
00080 /*  ========= */
00081 
00082 /*  ITYPE   (input) INTEGER */
00083 /*          Specifies the problem type to be solved: */
00084 /*          = 1:  A*x = (lambda)*B*x */
00085 /*          = 2:  A*B*x = (lambda)*x */
00086 /*          = 3:  B*A*x = (lambda)*x */
00087 
00088 /*  JOBZ    (input) CHARACTER*1 */
00089 /*          = 'N':  Compute eigenvalues only; */
00090 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00091 
00092 /*  UPLO    (input) CHARACTER*1 */
00093 /*          = 'U':  Upper triangles of A and B are stored; */
00094 /*          = 'L':  Lower triangles of A and B are stored. */
00095 
00096 /*  N       (input) INTEGER */
00097 /*          The order of the matrices A and B.  N >= 0. */
00098 
00099 /*  A       (input/output) COMPLEX array, dimension (LDA, N) */
00100 /*          On entry, the Hermitian matrix A.  If UPLO = 'U', the */
00101 /*          leading N-by-N upper triangular part of A contains the */
00102 /*          upper triangular part of the matrix A.  If UPLO = 'L', */
00103 /*          the leading N-by-N lower triangular part of A contains */
00104 /*          the lower triangular part of the matrix A. */
00105 
00106 /*          On exit, if JOBZ = 'V', then if INFO = 0, A contains the */
00107 /*          matrix Z of eigenvectors.  The eigenvectors are normalized */
00108 /*          as follows: */
00109 /*          if ITYPE = 1 or 2, Z**H*B*Z = I; */
00110 /*          if ITYPE = 3, Z**H*inv(B)*Z = I. */
00111 /*          If JOBZ = 'N', then on exit the upper triangle (if UPLO='U') */
00112 /*          or the lower triangle (if UPLO='L') of A, including the */
00113 /*          diagonal, is destroyed. */
00114 
00115 /*  LDA     (input) INTEGER */
00116 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00117 
00118 /*  B       (input/output) COMPLEX array, dimension (LDB, N) */
00119 /*          On entry, the Hermitian matrix B.  If UPLO = 'U', the */
00120 /*          leading N-by-N upper triangular part of B contains the */
00121 /*          upper triangular part of the matrix B.  If UPLO = 'L', */
00122 /*          the leading N-by-N lower triangular part of B contains */
00123 /*          the lower triangular part of the matrix B. */
00124 
00125 /*          On exit, if INFO <= N, the part of B containing the matrix is */
00126 /*          overwritten by the triangular factor U or L from the Cholesky */
00127 /*          factorization B = U**H*U or B = L*L**H. */
00128 
00129 /*  LDB     (input) INTEGER */
00130 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00131 
00132 /*  W       (output) REAL array, dimension (N) */
00133 /*          If INFO = 0, the eigenvalues in ascending order. */
00134 
00135 /*  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK)) */
00136 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00137 
00138 /*  LWORK   (input) INTEGER */
00139 /*          The length of the array WORK. */
00140 /*          If N <= 1,                LWORK >= 1. */
00141 /*          If JOBZ  = 'N' and N > 1, LWORK >= N + 1. */
00142 /*          If JOBZ  = 'V' and N > 1, LWORK >= 2*N + N**2. */
00143 
00144 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00145 /*          only calculates the optimal sizes of the WORK, RWORK and */
00146 /*          IWORK arrays, returns these values as the first entries of */
00147 /*          the WORK, RWORK and IWORK arrays, and no error message */
00148 /*          related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
00149 
00150 /*  RWORK   (workspace/output) REAL array, dimension (MAX(1,LRWORK)) */
00151 /*          On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK. */
00152 
00153 /*  LRWORK  (input) INTEGER */
00154 /*          The dimension of the array RWORK. */
00155 /*          If N <= 1,                LRWORK >= 1. */
00156 /*          If JOBZ  = 'N' and N > 1, LRWORK >= N. */
00157 /*          If JOBZ  = 'V' and N > 1, LRWORK >= 1 + 5*N + 2*N**2. */
00158 
00159 /*          If LRWORK = -1, then a workspace query is assumed; the */
00160 /*          routine only calculates the optimal sizes of the WORK, RWORK */
00161 /*          and IWORK arrays, returns these values as the first entries */
00162 /*          of the WORK, RWORK and IWORK arrays, and no error message */
00163 /*          related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
00164 
00165 /*  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
00166 /*          On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
00167 
00168 /*  LIWORK  (input) INTEGER */
00169 /*          The dimension of the array IWORK. */
00170 /*          If N <= 1,                LIWORK >= 1. */
00171 /*          If JOBZ  = 'N' and N > 1, LIWORK >= 1. */
00172 /*          If JOBZ  = 'V' and N > 1, LIWORK >= 3 + 5*N. */
00173 
00174 /*          If LIWORK = -1, then a workspace query is assumed; the */
00175 /*          routine only calculates the optimal sizes of the WORK, RWORK */
00176 /*          and IWORK arrays, returns these values as the first entries */
00177 /*          of the WORK, RWORK and IWORK arrays, and no error message */
00178 /*          related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
00179 
00180 /*  INFO    (output) INTEGER */
00181 /*          = 0:  successful exit */
00182 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00183 /*          > 0:  CPOTRF or CHEEVD returned an error code: */
00184 /*             <= N:  if INFO = i and JOBZ = 'N', then the algorithm */
00185 /*                    failed to converge; i off-diagonal elements of an */
00186 /*                    intermediate tridiagonal form did not converge to */
00187 /*                    zero; */
00188 /*                    if INFO = i and JOBZ = 'V', then the algorithm */
00189 /*                    failed to compute an eigenvalue while working on */
00190 /*                    the submatrix lying in rows and columns INFO/(N+1) */
00191 /*                    through mod(INFO,N+1); */
00192 /*             > N:   if INFO = N + i, for 1 <= i <= N, then the leading */
00193 /*                    minor of order i of B is not positive definite. */
00194 /*                    The factorization of B could not be completed and */
00195 /*                    no eigenvalues or eigenvectors were computed. */
00196 
00197 /*  Further Details */
00198 /*  =============== */
00199 
00200 /*  Based on contributions by */
00201 /*     Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
00202 
00203 /*  Modified so that no backsubstitution is performed if CHEEVD fails to */
00204 /*  converge (NEIG in old code could be greater than N causing out of */
00205 /*  bounds reference to A - reported by Ralf Meyer).  Also corrected the */
00206 /*  description of INFO and the test on ITYPE. Sven, 16 Feb 05. */
00207 /*  ===================================================================== */
00208 
00209 /*     .. Parameters .. */
00210 /*     .. */
00211 /*     .. Local Scalars .. */
00212 /*     .. */
00213 /*     .. External Functions .. */
00214 /*     .. */
00215 /*     .. External Subroutines .. */
00216 /*     .. */
00217 /*     .. Intrinsic Functions .. */
00218 /*     .. */
00219 /*     .. Executable Statements .. */
00220 
00221 /*     Test the input parameters. */
00222 
00223     /* Parameter adjustments */
00224     a_dim1 = *lda;
00225     a_offset = 1 + a_dim1;
00226     a -= a_offset;
00227     b_dim1 = *ldb;
00228     b_offset = 1 + b_dim1;
00229     b -= b_offset;
00230     --w;
00231     --work;
00232     --rwork;
00233     --iwork;
00234 
00235     /* Function Body */
00236     wantz = lsame_(jobz, "V");
00237     upper = lsame_(uplo, "U");
00238     lquery = *lwork == -1 || *lrwork == -1 || *liwork == -1;
00239 
00240     *info = 0;
00241     if (*n <= 1) {
00242         lwmin = 1;
00243         lrwmin = 1;
00244         liwmin = 1;
00245     } else if (wantz) {
00246         lwmin = (*n << 1) + *n * *n;
00247         lrwmin = *n * 5 + 1 + (*n << 1) * *n;
00248         liwmin = *n * 5 + 3;
00249     } else {
00250         lwmin = *n + 1;
00251         lrwmin = *n;
00252         liwmin = 1;
00253     }
00254     lopt = lwmin;
00255     lropt = lrwmin;
00256     liopt = liwmin;
00257     if (*itype < 1 || *itype > 3) {
00258         *info = -1;
00259     } else if (! (wantz || lsame_(jobz, "N"))) {
00260         *info = -2;
00261     } else if (! (upper || lsame_(uplo, "L"))) {
00262         *info = -3;
00263     } else if (*n < 0) {
00264         *info = -4;
00265     } else if (*lda < max(1,*n)) {
00266         *info = -6;
00267     } else if (*ldb < max(1,*n)) {
00268         *info = -8;
00269     }
00270 
00271     if (*info == 0) {
00272         work[1].r = (real) lopt, work[1].i = 0.f;
00273         rwork[1] = (real) lropt;
00274         iwork[1] = liopt;
00275 
00276         if (*lwork < lwmin && ! lquery) {
00277             *info = -11;
00278         } else if (*lrwork < lrwmin && ! lquery) {
00279             *info = -13;
00280         } else if (*liwork < liwmin && ! lquery) {
00281             *info = -15;
00282         }
00283     }
00284 
00285     if (*info != 0) {
00286         i__1 = -(*info);
00287         xerbla_("CHEGVD", &i__1);
00288         return 0;
00289     } else if (lquery) {
00290         return 0;
00291     }
00292 
00293 /*     Quick return if possible */
00294 
00295     if (*n == 0) {
00296         return 0;
00297     }
00298 
00299 /*     Form a Cholesky factorization of B. */
00300 
00301     cpotrf_(uplo, n, &b[b_offset], ldb, info);
00302     if (*info != 0) {
00303         *info = *n + *info;
00304         return 0;
00305     }
00306 
00307 /*     Transform problem to standard eigenvalue problem and solve. */
00308 
00309     chegst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info);
00310     cheevd_(jobz, uplo, n, &a[a_offset], lda, &w[1], &work[1], lwork, &rwork[
00311             1], lrwork, &iwork[1], liwork, info);
00312 /* Computing MAX */
00313     r__1 = (real) lopt, r__2 = work[1].r;
00314     lopt = dmax(r__1,r__2);
00315 /* Computing MAX */
00316     r__1 = (real) lropt;
00317     lropt = dmax(r__1,rwork[1]);
00318 /* Computing MAX */
00319     r__1 = (real) liopt, r__2 = (real) iwork[1];
00320     liopt = dmax(r__1,r__2);
00321 
00322     if (wantz && *info == 0) {
00323 
00324 /*        Backtransform eigenvectors to the original problem. */
00325 
00326         if (*itype == 1 || *itype == 2) {
00327 
00328 /*           For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
00329 /*           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
00330 
00331             if (upper) {
00332                 *(unsigned char *)trans = 'N';
00333             } else {
00334                 *(unsigned char *)trans = 'C';
00335             }
00336 
00337             ctrsm_("Left", uplo, trans, "Non-unit", n, n, &c_b1, &b[b_offset], 
00338                      ldb, &a[a_offset], lda);
00339 
00340         } else if (*itype == 3) {
00341 
00342 /*           For B*A*x=(lambda)*x; */
00343 /*           backtransform eigenvectors: x = L*y or U'*y */
00344 
00345             if (upper) {
00346                 *(unsigned char *)trans = 'C';
00347             } else {
00348                 *(unsigned char *)trans = 'N';
00349             }
00350 
00351             ctrmm_("Left", uplo, trans, "Non-unit", n, n, &c_b1, &b[b_offset], 
00352                      ldb, &a[a_offset], lda);
00353         }
00354     }
00355 
00356     work[1].r = (real) lopt, work[1].i = 0.f;
00357     rwork[1] = (real) lropt;
00358     iwork[1] = liopt;
00359 
00360     return 0;
00361 
00362 /*     End of CHEGVD */
00363 
00364 } /* chegvd_ */


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