zhpgvd.c
Go to the documentation of this file.
00001 /* zhpgvd.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 zhpgvd_(integer *itype, char *jobz, char *uplo, integer *
00021         n, doublecomplex *ap, doublecomplex *bp, doublereal *w, doublecomplex 
00022         *z__, integer *ldz, doublecomplex *work, integer *lwork, doublereal *
00023         rwork, integer *lrwork, integer *iwork, integer *liwork, integer *
00024         info)
00025 {
00026     /* System generated locals */
00027     integer z_dim1, z_offset, i__1;
00028     doublereal d__1, d__2;
00029 
00030     /* Local variables */
00031     integer j, neig;
00032     extern logical lsame_(char *, char *);
00033     integer lwmin;
00034     char trans[1];
00035     logical upper, wantz;
00036     extern /* Subroutine */ int ztpmv_(char *, char *, char *, integer *, 
00037             doublecomplex *, doublecomplex *, integer *), ztpsv_(char *, char *, char *, integer *, doublecomplex *
00038 , doublecomplex *, integer *), xerbla_(
00039             char *, integer *);
00040     integer liwmin;
00041     extern /* Subroutine */ int zhpevd_(char *, char *, integer *, 
00042             doublecomplex *, doublereal *, doublecomplex *, integer *, 
00043             doublecomplex *, integer *, doublereal *, integer *, integer *, 
00044             integer *, integer *);
00045     integer lrwmin;
00046     extern /* Subroutine */ int zhpgst_(integer *, char *, integer *, 
00047             doublecomplex *, doublecomplex *, integer *);
00048     logical lquery;
00049     extern /* Subroutine */ int zpptrf_(char *, integer *, doublecomplex *, 
00050             integer *);
00051 
00052 
00053 /*  -- LAPACK driver routine (version 3.2) -- */
00054 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00055 /*     November 2006 */
00056 
00057 /*     .. Scalar Arguments .. */
00058 /*     .. */
00059 /*     .. Array Arguments .. */
00060 /*     .. */
00061 
00062 /*  Purpose */
00063 /*  ======= */
00064 
00065 /*  ZHPGVD computes all the eigenvalues and, optionally, the eigenvectors */
00066 /*  of a complex generalized Hermitian-definite eigenproblem, of the form */
00067 /*  A*x=(lambda)*B*x,  A*Bx=(lambda)*x,  or B*A*x=(lambda)*x.  Here A and */
00068 /*  B are assumed to be Hermitian, stored in packed format, and B is also */
00069 /*  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 /*  AP      (input/output) COMPLEX*16 array, dimension (N*(N+1)/2) */
00100 /*          On entry, the upper or lower triangle of the Hermitian matrix */
00101 /*          A, packed columnwise in a linear array.  The j-th column of A */
00102 /*          is stored in the array AP as follows: */
00103 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00104 /*          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
00105 
00106 /*          On exit, the contents of AP are destroyed. */
00107 
00108 /*  BP      (input/output) COMPLEX*16 array, dimension (N*(N+1)/2) */
00109 /*          On entry, the upper or lower triangle of the Hermitian matrix */
00110 /*          B, packed columnwise in a linear array.  The j-th column of B */
00111 /*          is stored in the array BP as follows: */
00112 /*          if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j; */
00113 /*          if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n. */
00114 
00115 /*          On exit, the triangular factor U or L from the Cholesky */
00116 /*          factorization B = U**H*U or B = L*L**H, in the same storage */
00117 /*          format as B. */
00118 
00119 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00120 /*          If INFO = 0, the eigenvalues in ascending order. */
00121 
00122 /*  Z       (output) COMPLEX*16 array, dimension (LDZ, N) */
00123 /*          If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */
00124 /*          eigenvectors.  The eigenvectors are normalized as follows: */
00125 /*          if ITYPE = 1 or 2, Z**H*B*Z = I; */
00126 /*          if ITYPE = 3, Z**H*inv(B)*Z = I. */
00127 /*          If JOBZ = 'N', then Z is not referenced. */
00128 
00129 /*  LDZ     (input) INTEGER */
00130 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00131 /*          JOBZ = 'V', LDZ >= max(1,N). */
00132 
00133 /*  WORK    (workspace) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00134 /*          On exit, if INFO = 0, WORK(1) returns the required LWORK. */
00135 
00136 /*  LWORK   (input) INTEGER */
00137 /*          The dimension of array WORK. */
00138 /*          If N <= 1,               LWORK >= 1. */
00139 /*          If JOBZ = 'N' and N > 1, LWORK >= N. */
00140 /*          If JOBZ = 'V' and N > 1, LWORK >= 2*N. */
00141 
00142 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00143 /*          only calculates the required sizes of the WORK, RWORK and */
00144 /*          IWORK arrays, returns these values as the first entries of */
00145 /*          the WORK, RWORK and IWORK arrays, and no error message */
00146 /*          related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
00147 
00148 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (MAX(1,LRWORK)) */
00149 /*          On exit, if INFO = 0, RWORK(1) returns the required LRWORK. */
00150 
00151 /*  LRWORK  (input) INTEGER */
00152 /*          The dimension of array RWORK. */
00153 /*          If N <= 1,               LRWORK >= 1. */
00154 /*          If JOBZ = 'N' and N > 1, LRWORK >= N. */
00155 /*          If JOBZ = 'V' and N > 1, LRWORK >= 1 + 5*N + 2*N**2. */
00156 
00157 /*          If LRWORK = -1, then a workspace query is assumed; the */
00158 /*          routine only calculates the required sizes of the WORK, RWORK */
00159 /*          and IWORK arrays, returns these values as the first entries */
00160 /*          of the WORK, RWORK and IWORK arrays, and no error message */
00161 /*          related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
00162 
00163 /*  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
00164 /*          On exit, if INFO = 0, IWORK(1) returns the required LIWORK. */
00165 
00166 /*  LIWORK  (input) INTEGER */
00167 /*          The dimension of array IWORK. */
00168 /*          If JOBZ  = 'N' or N <= 1, LIWORK >= 1. */
00169 /*          If JOBZ  = 'V' and N > 1, LIWORK >= 3 + 5*N. */
00170 
00171 /*          If LIWORK = -1, then a workspace query is assumed; the */
00172 /*          routine only calculates the required sizes of the WORK, RWORK */
00173 /*          and IWORK arrays, returns these values as the first entries */
00174 /*          of the WORK, RWORK and IWORK arrays, and no error message */
00175 /*          related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
00176 
00177 /*  INFO    (output) INTEGER */
00178 /*          = 0:  successful exit */
00179 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00180 /*          > 0:  ZPPTRF or ZHPEVD returned an error code: */
00181 /*             <= N:  if INFO = i, ZHPEVD failed to converge; */
00182 /*                    i off-diagonal elements of an intermediate */
00183 /*                    tridiagonal form did not convergeto zero; */
00184 /*             > N:   if INFO = N + i, for 1 <= i <= n, then the leading */
00185 /*                    minor of order i of B is not positive definite. */
00186 /*                    The factorization of B could not be completed and */
00187 /*                    no eigenvalues or eigenvectors were computed. */
00188 
00189 /*  Further Details */
00190 /*  =============== */
00191 
00192 /*  Based on contributions by */
00193 /*     Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
00194 
00195 /*  ===================================================================== */
00196 
00197 /*     .. Local Scalars .. */
00198 /*     .. */
00199 /*     .. External Functions .. */
00200 /*     .. */
00201 /*     .. External Subroutines .. */
00202 /*     .. */
00203 /*     .. Intrinsic Functions .. */
00204 /*     .. */
00205 /*     .. Executable Statements .. */
00206 
00207 /*     Test the input parameters. */
00208 
00209     /* Parameter adjustments */
00210     --ap;
00211     --bp;
00212     --w;
00213     z_dim1 = *ldz;
00214     z_offset = 1 + z_dim1;
00215     z__ -= z_offset;
00216     --work;
00217     --rwork;
00218     --iwork;
00219 
00220     /* Function Body */
00221     wantz = lsame_(jobz, "V");
00222     upper = lsame_(uplo, "U");
00223     lquery = *lwork == -1 || *lrwork == -1 || *liwork == -1;
00224 
00225     *info = 0;
00226     if (*itype < 1 || *itype > 3) {
00227         *info = -1;
00228     } else if (! (wantz || lsame_(jobz, "N"))) {
00229         *info = -2;
00230     } else if (! (upper || lsame_(uplo, "L"))) {
00231         *info = -3;
00232     } else if (*n < 0) {
00233         *info = -4;
00234     } else if (*ldz < 1 || wantz && *ldz < *n) {
00235         *info = -9;
00236     }
00237 
00238     if (*info == 0) {
00239         if (*n <= 1) {
00240             lwmin = 1;
00241             liwmin = 1;
00242             lrwmin = 1;
00243         } else {
00244             if (wantz) {
00245                 lwmin = *n << 1;
00246 /* Computing 2nd power */
00247                 i__1 = *n;
00248                 lrwmin = *n * 5 + 1 + (i__1 * i__1 << 1);
00249                 liwmin = *n * 5 + 3;
00250             } else {
00251                 lwmin = *n;
00252                 lrwmin = *n;
00253                 liwmin = 1;
00254             }
00255         }
00256 
00257         work[1].r = (doublereal) lwmin, work[1].i = 0.;
00258         rwork[1] = (doublereal) lrwmin;
00259         iwork[1] = liwmin;
00260         if (*lwork < lwmin && ! lquery) {
00261             *info = -11;
00262         } else if (*lrwork < lrwmin && ! lquery) {
00263             *info = -13;
00264         } else if (*liwork < liwmin && ! lquery) {
00265             *info = -15;
00266         }
00267     }
00268 
00269     if (*info != 0) {
00270         i__1 = -(*info);
00271         xerbla_("ZHPGVD", &i__1);
00272         return 0;
00273     } else if (lquery) {
00274         return 0;
00275     }
00276 
00277 /*     Quick return if possible */
00278 
00279     if (*n == 0) {
00280         return 0;
00281     }
00282 
00283 /*     Form a Cholesky factorization of B. */
00284 
00285     zpptrf_(uplo, n, &bp[1], info);
00286     if (*info != 0) {
00287         *info = *n + *info;
00288         return 0;
00289     }
00290 
00291 /*     Transform problem to standard eigenvalue problem and solve. */
00292 
00293     zhpgst_(itype, uplo, n, &ap[1], &bp[1], info);
00294     zhpevd_(jobz, uplo, n, &ap[1], &w[1], &z__[z_offset], ldz, &work[1], 
00295             lwork, &rwork[1], lrwork, &iwork[1], liwork, info);
00296 /* Computing MAX */
00297     d__1 = (doublereal) lwmin, d__2 = work[1].r;
00298     lwmin = (integer) max(d__1,d__2);
00299 /* Computing MAX */
00300     d__1 = (doublereal) lrwmin;
00301     lrwmin = (integer) max(d__1,rwork[1]);
00302 /* Computing MAX */
00303     d__1 = (doublereal) liwmin, d__2 = (doublereal) iwork[1];
00304     liwmin = (integer) max(d__1,d__2);
00305 
00306     if (wantz) {
00307 
00308 /*        Backtransform eigenvectors to the original problem. */
00309 
00310         neig = *n;
00311         if (*info > 0) {
00312             neig = *info - 1;
00313         }
00314         if (*itype == 1 || *itype == 2) {
00315 
00316 /*           For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
00317 /*           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
00318 
00319             if (upper) {
00320                 *(unsigned char *)trans = 'N';
00321             } else {
00322                 *(unsigned char *)trans = 'C';
00323             }
00324 
00325             i__1 = neig;
00326             for (j = 1; j <= i__1; ++j) {
00327                 ztpsv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 + 
00328                         1], &c__1);
00329 /* L10: */
00330             }
00331 
00332         } else if (*itype == 3) {
00333 
00334 /*           For B*A*x=(lambda)*x; */
00335 /*           backtransform eigenvectors: x = L*y or U'*y */
00336 
00337             if (upper) {
00338                 *(unsigned char *)trans = 'C';
00339             } else {
00340                 *(unsigned char *)trans = 'N';
00341             }
00342 
00343             i__1 = neig;
00344             for (j = 1; j <= i__1; ++j) {
00345                 ztpmv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 + 
00346                         1], &c__1);
00347 /* L20: */
00348             }
00349         }
00350     }
00351 
00352     work[1].r = (doublereal) lwmin, work[1].i = 0.;
00353     rwork[1] = (doublereal) lrwmin;
00354     iwork[1] = liwmin;
00355     return 0;
00356 
00357 /*     End of ZHPGVD */
00358 
00359 } /* zhpgvd_ */


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