chegvx.c
Go to the documentation of this file.
00001 /* chegvx.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 static integer c__1 = 1;
00020 static integer c_n1 = -1;
00021 
00022 /* Subroutine */ int chegvx_(integer *itype, char *jobz, char *range, char *
00023         uplo, integer *n, complex *a, integer *lda, complex *b, integer *ldb, 
00024         real *vl, real *vu, integer *il, integer *iu, real *abstol, integer *
00025         m, real *w, complex *z__, integer *ldz, complex *work, integer *lwork, 
00026          real *rwork, integer *iwork, integer *ifail, integer *info)
00027 {
00028     /* System generated locals */
00029     integer a_dim1, a_offset, b_dim1, b_offset, z_dim1, z_offset, i__1, i__2;
00030 
00031     /* Local variables */
00032     integer nb;
00033     extern logical lsame_(char *, char *);
00034     extern /* Subroutine */ int ctrmm_(char *, char *, char *, char *, 
00035             integer *, integer *, complex *, complex *, integer *, complex *, 
00036             integer *);
00037     char trans[1];
00038     extern /* Subroutine */ int ctrsm_(char *, char *, char *, char *, 
00039             integer *, integer *, complex *, complex *, integer *, complex *, 
00040             integer *);
00041     logical upper, wantz, alleig, indeig, valeig;
00042     extern /* Subroutine */ int chegst_(integer *, char *, integer *, complex 
00043             *, integer *, complex *, integer *, integer *);
00044     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00045             integer *, integer *);
00046     extern /* Subroutine */ int xerbla_(char *, integer *), cheevx_(
00047             char *, char *, char *, integer *, complex *, integer *, real *, 
00048             real *, integer *, integer *, real *, integer *, real *, complex *
00049 , integer *, complex *, integer *, real *, integer *, integer *, 
00050             integer *), cpotrf_(char *, integer *, 
00051             complex *, integer *, integer *);
00052     integer lwkopt;
00053     logical lquery;
00054 
00055 
00056 /*  -- LAPACK driver routine (version 3.2) -- */
00057 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00058 /*     November 2006 */
00059 
00060 /*     .. Scalar Arguments .. */
00061 /*     .. */
00062 /*     .. Array Arguments .. */
00063 /*     .. */
00064 
00065 /*  Purpose */
00066 /*  ======= */
00067 
00068 /*  CHEGVX computes selected eigenvalues, and optionally, eigenvectors */
00069 /*  of a complex generalized Hermitian-definite eigenproblem, of the form */
00070 /*  A*x=(lambda)*B*x,  A*Bx=(lambda)*x,  or B*A*x=(lambda)*x.  Here A and */
00071 /*  B are assumed to be Hermitian and B is also positive definite. */
00072 /*  Eigenvalues and eigenvectors can be selected by specifying either a */
00073 /*  range of values or a range of indices for the desired eigenvalues. */
00074 
00075 /*  Arguments */
00076 /*  ========= */
00077 
00078 /*  ITYPE   (input) INTEGER */
00079 /*          Specifies the problem type to be solved: */
00080 /*          = 1:  A*x = (lambda)*B*x */
00081 /*          = 2:  A*B*x = (lambda)*x */
00082 /*          = 3:  B*A*x = (lambda)*x */
00083 
00084 /*  JOBZ    (input) CHARACTER*1 */
00085 /*          = 'N':  Compute eigenvalues only; */
00086 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00087 
00088 /*  RANGE   (input) CHARACTER*1 */
00089 /*          = 'A': all eigenvalues will be found. */
00090 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
00091 /*                 will be found. */
00092 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
00093 /* * */
00094 /*  UPLO    (input) CHARACTER*1 */
00095 /*          = 'U':  Upper triangles of A and B are stored; */
00096 /*          = 'L':  Lower triangles of A and B are stored. */
00097 
00098 /*  N       (input) INTEGER */
00099 /*          The order of the matrices A and B.  N >= 0. */
00100 
00101 /*  A       (input/output) COMPLEX array, dimension (LDA, N) */
00102 /*          On entry, the Hermitian matrix A.  If UPLO = 'U', the */
00103 /*          leading N-by-N upper triangular part of A contains the */
00104 /*          upper triangular part of the matrix A.  If UPLO = 'L', */
00105 /*          the leading N-by-N lower triangular part of A contains */
00106 /*          the lower triangular part of the matrix A. */
00107 
00108 /*          On exit,  the lower triangle (if UPLO='L') or the upper */
00109 /*          triangle (if UPLO='U') of A, including the diagonal, is */
00110 /*          destroyed. */
00111 
00112 /*  LDA     (input) INTEGER */
00113 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00114 
00115 /*  B       (input/output) COMPLEX array, dimension (LDB, N) */
00116 /*          On entry, the Hermitian matrix B.  If UPLO = 'U', the */
00117 /*          leading N-by-N upper triangular part of B contains the */
00118 /*          upper triangular part of the matrix B.  If UPLO = 'L', */
00119 /*          the leading N-by-N lower triangular part of B contains */
00120 /*          the lower triangular part of the matrix B. */
00121 
00122 /*          On exit, if INFO <= N, the part of B containing the matrix is */
00123 /*          overwritten by the triangular factor U or L from the Cholesky */
00124 /*          factorization B = U**H*U or B = L*L**H. */
00125 
00126 /*  LDB     (input) INTEGER */
00127 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00128 
00129 /*  VL      (input) REAL */
00130 /*  VU      (input) REAL */
00131 /*          If RANGE='V', the lower and upper bounds of the interval to */
00132 /*          be searched for eigenvalues. VL < VU. */
00133 /*          Not referenced if RANGE = 'A' or 'I'. */
00134 
00135 /*  IL      (input) INTEGER */
00136 /*  IU      (input) INTEGER */
00137 /*          If RANGE='I', the indices (in ascending order) of the */
00138 /*          smallest and largest eigenvalues to be returned. */
00139 /*          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
00140 /*          Not referenced if RANGE = 'A' or 'V'. */
00141 
00142 /*  ABSTOL  (input) REAL */
00143 /*          The absolute error tolerance for the eigenvalues. */
00144 /*          An approximate eigenvalue is accepted as converged */
00145 /*          when it is determined to lie in an interval [a,b] */
00146 /*          of width less than or equal to */
00147 
00148 /*                  ABSTOL + EPS *   max( |a|,|b| ) , */
00149 
00150 /*          where EPS is the machine precision.  If ABSTOL is less than */
00151 /*          or equal to zero, then  EPS*|T|  will be used in its place, */
00152 /*          where |T| is the 1-norm of the tridiagonal matrix obtained */
00153 /*          by reducing A to tridiagonal form. */
00154 
00155 /*          Eigenvalues will be computed most accurately when ABSTOL is */
00156 /*          set to twice the underflow threshold 2*SLAMCH('S'), not zero. */
00157 /*          If this routine returns with INFO>0, indicating that some */
00158 /*          eigenvectors did not converge, try setting ABSTOL to */
00159 /*          2*SLAMCH('S'). */
00160 
00161 /*  M       (output) INTEGER */
00162 /*          The total number of eigenvalues found.  0 <= M <= N. */
00163 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
00164 
00165 /*  W       (output) REAL array, dimension (N) */
00166 /*          The first M elements contain the selected */
00167 /*          eigenvalues in ascending order. */
00168 
00169 /*  Z       (output) COMPLEX array, dimension (LDZ, max(1,M)) */
00170 /*          If JOBZ = 'N', then Z is not referenced. */
00171 /*          If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
00172 /*          contain the orthonormal eigenvectors of the matrix A */
00173 /*          corresponding to the selected eigenvalues, with the i-th */
00174 /*          column of Z holding the eigenvector associated with W(i). */
00175 /*          The eigenvectors are normalized as follows: */
00176 /*          if ITYPE = 1 or 2, Z**T*B*Z = I; */
00177 /*          if ITYPE = 3, Z**T*inv(B)*Z = I. */
00178 
00179 /*          If an eigenvector fails to converge, then that column of Z */
00180 /*          contains the latest approximation to the eigenvector, and the */
00181 /*          index of the eigenvector is returned in IFAIL. */
00182 /*          Note: the user must ensure that at least max(1,M) columns are */
00183 /*          supplied in the array Z; if RANGE = 'V', the exact value of M */
00184 /*          is not known in advance and an upper bound must be used. */
00185 
00186 /*  LDZ     (input) INTEGER */
00187 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00188 /*          JOBZ = 'V', LDZ >= max(1,N). */
00189 
00190 /*  WORK    (workspace/output) COMPLEX array, dimension (MAX(1,LWORK)) */
00191 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00192 
00193 /*  LWORK   (input) INTEGER */
00194 /*          The length of the array WORK.  LWORK >= max(1,2*N). */
00195 /*          For optimal efficiency, LWORK >= (NB+1)*N, */
00196 /*          where NB is the blocksize for CHETRD returned by ILAENV. */
00197 
00198 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00199 /*          only calculates the optimal size of the WORK array, returns */
00200 /*          this value as the first entry of the WORK array, and no error */
00201 /*          message related to LWORK is issued by XERBLA. */
00202 
00203 /*  RWORK   (workspace) REAL array, dimension (7*N) */
00204 
00205 /*  IWORK   (workspace) INTEGER array, dimension (5*N) */
00206 
00207 /*  IFAIL   (output) INTEGER array, dimension (N) */
00208 /*          If JOBZ = 'V', then if INFO = 0, the first M elements of */
00209 /*          IFAIL are zero.  If INFO > 0, then IFAIL contains the */
00210 /*          indices of the eigenvectors that failed to converge. */
00211 /*          If JOBZ = 'N', then IFAIL is not referenced. */
00212 
00213 /*  INFO    (output) INTEGER */
00214 /*          = 0:  successful exit */
00215 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00216 /*          > 0:  CPOTRF or CHEEVX returned an error code: */
00217 /*             <= N:  if INFO = i, CHEEVX failed to converge; */
00218 /*                    i eigenvectors failed to converge.  Their indices */
00219 /*                    are stored in array IFAIL. */
00220 /*             > N:   if INFO = N + i, for 1 <= i <= N, then the leading */
00221 /*                    minor of order i of B is not positive definite. */
00222 /*                    The factorization of B could not be completed and */
00223 /*                    no eigenvalues or eigenvectors were computed. */
00224 
00225 /*  Further Details */
00226 /*  =============== */
00227 
00228 /*  Based on contributions by */
00229 /*     Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
00230 
00231 /*  ===================================================================== */
00232 
00233 /*     .. Parameters .. */
00234 /*     .. */
00235 /*     .. Local Scalars .. */
00236 /*     .. */
00237 /*     .. External Functions .. */
00238 /*     .. */
00239 /*     .. External Subroutines .. */
00240 /*     .. */
00241 /*     .. Intrinsic Functions .. */
00242 /*     .. */
00243 /*     .. Executable Statements .. */
00244 
00245 /*     Test the input parameters. */
00246 
00247     /* Parameter adjustments */
00248     a_dim1 = *lda;
00249     a_offset = 1 + a_dim1;
00250     a -= a_offset;
00251     b_dim1 = *ldb;
00252     b_offset = 1 + b_dim1;
00253     b -= b_offset;
00254     --w;
00255     z_dim1 = *ldz;
00256     z_offset = 1 + z_dim1;
00257     z__ -= z_offset;
00258     --work;
00259     --rwork;
00260     --iwork;
00261     --ifail;
00262 
00263     /* Function Body */
00264     wantz = lsame_(jobz, "V");
00265     upper = lsame_(uplo, "U");
00266     alleig = lsame_(range, "A");
00267     valeig = lsame_(range, "V");
00268     indeig = lsame_(range, "I");
00269     lquery = *lwork == -1;
00270 
00271     *info = 0;
00272     if (*itype < 1 || *itype > 3) {
00273         *info = -1;
00274     } else if (! (wantz || lsame_(jobz, "N"))) {
00275         *info = -2;
00276     } else if (! (alleig || valeig || indeig)) {
00277         *info = -3;
00278     } else if (! (upper || lsame_(uplo, "L"))) {
00279         *info = -4;
00280     } else if (*n < 0) {
00281         *info = -5;
00282     } else if (*lda < max(1,*n)) {
00283         *info = -7;
00284     } else if (*ldb < max(1,*n)) {
00285         *info = -9;
00286     } else {
00287         if (valeig) {
00288             if (*n > 0 && *vu <= *vl) {
00289                 *info = -11;
00290             }
00291         } else if (indeig) {
00292             if (*il < 1 || *il > max(1,*n)) {
00293                 *info = -12;
00294             } else if (*iu < min(*n,*il) || *iu > *n) {
00295                 *info = -13;
00296             }
00297         }
00298     }
00299     if (*info == 0) {
00300         if (*ldz < 1 || wantz && *ldz < *n) {
00301             *info = -18;
00302         }
00303     }
00304 
00305     if (*info == 0) {
00306         nb = ilaenv_(&c__1, "CHETRD", uplo, n, &c_n1, &c_n1, &c_n1);
00307 /* Computing MAX */
00308         i__1 = 1, i__2 = (nb + 1) * *n;
00309         lwkopt = max(i__1,i__2);
00310         work[1].r = (real) lwkopt, work[1].i = 0.f;
00311 
00312 /* Computing MAX */
00313         i__1 = 1, i__2 = *n << 1;
00314         if (*lwork < max(i__1,i__2) && ! lquery) {
00315             *info = -20;
00316         }
00317     }
00318 
00319     if (*info != 0) {
00320         i__1 = -(*info);
00321         xerbla_("CHEGVX", &i__1);
00322         return 0;
00323     } else if (lquery) {
00324         return 0;
00325     }
00326 
00327 /*     Quick return if possible */
00328 
00329     *m = 0;
00330     if (*n == 0) {
00331         return 0;
00332     }
00333 
00334 /*     Form a Cholesky factorization of B. */
00335 
00336     cpotrf_(uplo, n, &b[b_offset], ldb, info);
00337     if (*info != 0) {
00338         *info = *n + *info;
00339         return 0;
00340     }
00341 
00342 /*     Transform problem to standard eigenvalue problem and solve. */
00343 
00344     chegst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info);
00345     cheevx_(jobz, range, uplo, n, &a[a_offset], lda, vl, vu, il, iu, abstol, 
00346             m, &w[1], &z__[z_offset], ldz, &work[1], lwork, &rwork[1], &iwork[
00347             1], &ifail[1], info);
00348 
00349     if (wantz) {
00350 
00351 /*        Backtransform eigenvectors to the original problem. */
00352 
00353         if (*info > 0) {
00354             *m = *info - 1;
00355         }
00356         if (*itype == 1 || *itype == 2) {
00357 
00358 /*           For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
00359 /*           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
00360 
00361             if (upper) {
00362                 *(unsigned char *)trans = 'N';
00363             } else {
00364                 *(unsigned char *)trans = 'C';
00365             }
00366 
00367             ctrsm_("Left", uplo, trans, "Non-unit", n, m, &c_b1, &b[b_offset], 
00368                      ldb, &z__[z_offset], ldz);
00369 
00370         } else if (*itype == 3) {
00371 
00372 /*           For B*A*x=(lambda)*x; */
00373 /*           backtransform eigenvectors: x = L*y or U'*y */
00374 
00375             if (upper) {
00376                 *(unsigned char *)trans = 'C';
00377             } else {
00378                 *(unsigned char *)trans = 'N';
00379             }
00380 
00381             ctrmm_("Left", uplo, trans, "Non-unit", n, m, &c_b1, &b[b_offset], 
00382                      ldb, &z__[z_offset], ldz);
00383         }
00384     }
00385 
00386 /*     Set WORK(1) to optimal complex workspace size. */
00387 
00388     work[1].r = (real) lwkopt, work[1].i = 0.f;
00389 
00390     return 0;
00391 
00392 /*     End of CHEGVX */
00393 
00394 } /* chegvx_ */


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