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


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