chbgvx.c
Go to the documentation of this file.
00001 /* chbgvx.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 = {0.f,0.f};
00019 static complex c_b2 = {1.f,0.f};
00020 static integer c__1 = 1;
00021 
00022 /* Subroutine */ int chbgvx_(char *jobz, char *range, char *uplo, integer *n, 
00023         integer *ka, integer *kb, complex *ab, integer *ldab, complex *bb, 
00024         integer *ldbb, complex *q, integer *ldq, real *vl, real *vu, integer *
00025         il, integer *iu, real *abstol, integer *m, real *w, complex *z__, 
00026         integer *ldz, complex *work, real *rwork, integer *iwork, integer *
00027         ifail, integer *info)
00028 {
00029     /* System generated locals */
00030     integer ab_dim1, ab_offset, bb_dim1, bb_offset, q_dim1, q_offset, z_dim1, 
00031             z_offset, i__1, i__2;
00032 
00033     /* Local variables */
00034     integer i__, j, jj;
00035     real tmp1;
00036     integer indd, inde;
00037     char vect[1];
00038     logical test;
00039     integer itmp1, indee;
00040     extern logical lsame_(char *, char *);
00041     extern /* Subroutine */ int cgemv_(char *, integer *, integer *, complex *
00042 , complex *, integer *, complex *, integer *, complex *, complex *
00043 , integer *);
00044     integer iinfo;
00045     char order[1];
00046     extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, 
00047             complex *, integer *), cswap_(integer *, complex *, integer *, 
00048             complex *, integer *);
00049     logical upper;
00050     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
00051             integer *);
00052     logical wantz, alleig, indeig;
00053     integer indibl;
00054     extern /* Subroutine */ int chbtrd_(char *, char *, integer *, integer *, 
00055             complex *, integer *, real *, real *, complex *, integer *, 
00056             complex *, integer *);
00057     logical valeig;
00058     extern /* Subroutine */ int chbgst_(char *, char *, integer *, integer *, 
00059             integer *, complex *, integer *, complex *, integer *, complex *, 
00060             integer *, complex *, real *, integer *), clacpy_(
00061             char *, integer *, integer *, complex *, integer *, complex *, 
00062             integer *), xerbla_(char *, integer *), cpbstf_(
00063             char *, integer *, integer *, complex *, integer *, integer *);
00064     integer indiwk, indisp;
00065     extern /* Subroutine */ int cstein_(integer *, real *, real *, integer *, 
00066             real *, integer *, integer *, complex *, integer *, real *, 
00067             integer *, integer *, integer *);
00068     integer indrwk, indwrk;
00069     extern /* Subroutine */ int csteqr_(char *, integer *, real *, real *, 
00070             complex *, integer *, real *, integer *), ssterf_(integer 
00071             *, real *, real *, integer *);
00072     integer nsplit;
00073     extern /* Subroutine */ int sstebz_(char *, char *, integer *, real *, 
00074             real *, integer *, integer *, real *, real *, real *, integer *, 
00075             integer *, real *, integer *, integer *, real *, integer *, 
00076             integer *);
00077 
00078 
00079 /*  -- LAPACK driver routine (version 3.2) -- */
00080 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00081 /*     November 2006 */
00082 
00083 /*     .. Scalar Arguments .. */
00084 /*     .. */
00085 /*     .. Array Arguments .. */
00086 /*     .. */
00087 
00088 /*  Purpose */
00089 /*  ======= */
00090 
00091 /*  CHBGVX computes all the eigenvalues, and optionally, the eigenvectors */
00092 /*  of a complex generalized Hermitian-definite banded eigenproblem, of */
00093 /*  the form A*x=(lambda)*B*x. Here A and B are assumed to be Hermitian */
00094 /*  and banded, and B is also positive definite.  Eigenvalues and */
00095 /*  eigenvectors can be selected by specifying either all eigenvalues, */
00096 /*  a range of values or a range of indices for the desired eigenvalues. */
00097 
00098 /*  Arguments */
00099 /*  ========= */
00100 
00101 /*  JOBZ    (input) CHARACTER*1 */
00102 /*          = 'N':  Compute eigenvalues only; */
00103 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00104 
00105 /*  RANGE   (input) CHARACTER*1 */
00106 /*          = 'A': all eigenvalues will be found; */
00107 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
00108 /*                 will be found; */
00109 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
00110 
00111 /*  UPLO    (input) CHARACTER*1 */
00112 /*          = 'U':  Upper triangles of A and B are stored; */
00113 /*          = 'L':  Lower triangles of A and B are stored. */
00114 
00115 /*  N       (input) INTEGER */
00116 /*          The order of the matrices A and B.  N >= 0. */
00117 
00118 /*  KA      (input) INTEGER */
00119 /*          The number of superdiagonals of the matrix A if UPLO = 'U', */
00120 /*          or the number of subdiagonals if UPLO = 'L'. KA >= 0. */
00121 
00122 /*  KB      (input) INTEGER */
00123 /*          The number of superdiagonals of the matrix B if UPLO = 'U', */
00124 /*          or the number of subdiagonals if UPLO = 'L'. KB >= 0. */
00125 
00126 /*  AB      (input/output) COMPLEX array, dimension (LDAB, N) */
00127 /*          On entry, the upper or lower triangle of the Hermitian band */
00128 /*          matrix A, stored in the first ka+1 rows of the array.  The */
00129 /*          j-th column of A is stored in the j-th column of the array AB */
00130 /*          as follows: */
00131 /*          if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for max(1,j-ka)<=i<=j; */
00132 /*          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+ka). */
00133 
00134 /*          On exit, the contents of AB are destroyed. */
00135 
00136 /*  LDAB    (input) INTEGER */
00137 /*          The leading dimension of the array AB.  LDAB >= KA+1. */
00138 
00139 /*  BB      (input/output) COMPLEX array, dimension (LDBB, N) */
00140 /*          On entry, the upper or lower triangle of the Hermitian band */
00141 /*          matrix B, stored in the first kb+1 rows of the array.  The */
00142 /*          j-th column of B is stored in the j-th column of the array BB */
00143 /*          as follows: */
00144 /*          if UPLO = 'U', BB(kb+1+i-j,j) = B(i,j) for max(1,j-kb)<=i<=j; */
00145 /*          if UPLO = 'L', BB(1+i-j,j)    = B(i,j) for j<=i<=min(n,j+kb). */
00146 
00147 /*          On exit, the factor S from the split Cholesky factorization */
00148 /*          B = S**H*S, as returned by CPBSTF. */
00149 
00150 /*  LDBB    (input) INTEGER */
00151 /*          The leading dimension of the array BB.  LDBB >= KB+1. */
00152 
00153 /*  Q       (output) COMPLEX array, dimension (LDQ, N) */
00154 /*          If JOBZ = 'V', the n-by-n matrix used in the reduction of */
00155 /*          A*x = (lambda)*B*x to standard form, i.e. C*x = (lambda)*x, */
00156 /*          and consequently C to tridiagonal form. */
00157 /*          If JOBZ = 'N', the array Q is not referenced. */
00158 
00159 /*  LDQ     (input) INTEGER */
00160 /*          The leading dimension of the array Q.  If JOBZ = 'N', */
00161 /*          LDQ >= 1. If JOBZ = 'V', LDQ >= max(1,N). */
00162 
00163 /*  VL      (input) REAL */
00164 /*  VU      (input) REAL */
00165 /*          If RANGE='V', the lower and upper bounds of the interval to */
00166 /*          be searched for eigenvalues. VL < VU. */
00167 /*          Not referenced if RANGE = 'A' or 'I'. */
00168 
00169 /*  IL      (input) INTEGER */
00170 /*  IU      (input) INTEGER */
00171 /*          If RANGE='I', the indices (in ascending order) of the */
00172 /*          smallest and largest eigenvalues to be returned. */
00173 /*          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
00174 /*          Not referenced if RANGE = 'A' or 'V'. */
00175 
00176 /*  ABSTOL  (input) REAL */
00177 /*          The absolute error tolerance for the eigenvalues. */
00178 /*          An approximate eigenvalue is accepted as converged */
00179 /*          when it is determined to lie in an interval [a,b] */
00180 /*          of width less than or equal to */
00181 
00182 /*                  ABSTOL + EPS *   max( |a|,|b| ) , */
00183 
00184 /*          where EPS is the machine precision.  If ABSTOL is less than */
00185 /*          or equal to zero, then  EPS*|T|  will be used in its place, */
00186 /*          where |T| is the 1-norm of the tridiagonal matrix obtained */
00187 /*          by reducing AP to tridiagonal form. */
00188 
00189 /*          Eigenvalues will be computed most accurately when ABSTOL is */
00190 /*          set to twice the underflow threshold 2*SLAMCH('S'), not zero. */
00191 /*          If this routine returns with INFO>0, indicating that some */
00192 /*          eigenvectors did not converge, try setting ABSTOL to */
00193 /*          2*SLAMCH('S'). */
00194 
00195 /*  M       (output) INTEGER */
00196 /*          The total number of eigenvalues found.  0 <= M <= N. */
00197 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
00198 
00199 /*  W       (output) REAL array, dimension (N) */
00200 /*          If INFO = 0, the eigenvalues in ascending order. */
00201 
00202 /*  Z       (output) COMPLEX array, dimension (LDZ, N) */
00203 /*          If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */
00204 /*          eigenvectors, with the i-th column of Z holding the */
00205 /*          eigenvector associated with W(i). The eigenvectors are */
00206 /*          normalized so that Z**H*B*Z = I. */
00207 /*          If JOBZ = 'N', then Z is not referenced. */
00208 
00209 /*  LDZ     (input) INTEGER */
00210 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00211 /*          JOBZ = 'V', LDZ >= N. */
00212 
00213 /*  WORK    (workspace) COMPLEX array, dimension (N) */
00214 
00215 /*  RWORK   (workspace) REAL array, dimension (7*N) */
00216 
00217 /*  IWORK   (workspace) INTEGER array, dimension (5*N) */
00218 
00219 /*  IFAIL   (output) INTEGER array, dimension (N) */
00220 /*          If JOBZ = 'V', then if INFO = 0, the first M elements of */
00221 /*          IFAIL are zero.  If INFO > 0, then IFAIL contains the */
00222 /*          indices of the eigenvectors that failed to converge. */
00223 /*          If JOBZ = 'N', then IFAIL is not referenced. */
00224 
00225 /*  INFO    (output) INTEGER */
00226 /*          = 0:  successful exit */
00227 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00228 /*          > 0:  if INFO = i, and i is: */
00229 /*             <= N:  then i eigenvectors failed to converge.  Their */
00230 /*                    indices are stored in array IFAIL. */
00231 /*             > N:   if INFO = N + i, for 1 <= i <= N, then CPBSTF */
00232 /*                    returned INFO = i: B is not positive definite. */
00233 /*                    The factorization of B could not be completed and */
00234 /*                    no eigenvalues or eigenvectors were computed. */
00235 
00236 /*  Further Details */
00237 /*  =============== */
00238 
00239 /*  Based on contributions by */
00240 /*     Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
00241 
00242 /*  ===================================================================== */
00243 
00244 /*     .. Parameters .. */
00245 /*     .. */
00246 /*     .. Local Scalars .. */
00247 /*     .. */
00248 /*     .. External Functions .. */
00249 /*     .. */
00250 /*     .. External Subroutines .. */
00251 /*     .. */
00252 /*     .. Intrinsic Functions .. */
00253 /*     .. */
00254 /*     .. Executable Statements .. */
00255 
00256 /*     Test the input parameters. */
00257 
00258     /* Parameter adjustments */
00259     ab_dim1 = *ldab;
00260     ab_offset = 1 + ab_dim1;
00261     ab -= ab_offset;
00262     bb_dim1 = *ldbb;
00263     bb_offset = 1 + bb_dim1;
00264     bb -= bb_offset;
00265     q_dim1 = *ldq;
00266     q_offset = 1 + q_dim1;
00267     q -= q_offset;
00268     --w;
00269     z_dim1 = *ldz;
00270     z_offset = 1 + z_dim1;
00271     z__ -= z_offset;
00272     --work;
00273     --rwork;
00274     --iwork;
00275     --ifail;
00276 
00277     /* Function Body */
00278     wantz = lsame_(jobz, "V");
00279     upper = lsame_(uplo, "U");
00280     alleig = lsame_(range, "A");
00281     valeig = lsame_(range, "V");
00282     indeig = lsame_(range, "I");
00283 
00284     *info = 0;
00285     if (! (wantz || lsame_(jobz, "N"))) {
00286         *info = -1;
00287     } else if (! (alleig || valeig || indeig)) {
00288         *info = -2;
00289     } else if (! (upper || lsame_(uplo, "L"))) {
00290         *info = -3;
00291     } else if (*n < 0) {
00292         *info = -4;
00293     } else if (*ka < 0) {
00294         *info = -5;
00295     } else if (*kb < 0 || *kb > *ka) {
00296         *info = -6;
00297     } else if (*ldab < *ka + 1) {
00298         *info = -8;
00299     } else if (*ldbb < *kb + 1) {
00300         *info = -10;
00301     } else if (*ldq < 1 || wantz && *ldq < *n) {
00302         *info = -12;
00303     } else {
00304         if (valeig) {
00305             if (*n > 0 && *vu <= *vl) {
00306                 *info = -14;
00307             }
00308         } else if (indeig) {
00309             if (*il < 1 || *il > max(1,*n)) {
00310                 *info = -15;
00311             } else if (*iu < min(*n,*il) || *iu > *n) {
00312                 *info = -16;
00313             }
00314         }
00315     }
00316     if (*info == 0) {
00317         if (*ldz < 1 || wantz && *ldz < *n) {
00318             *info = -21;
00319         }
00320     }
00321 
00322     if (*info != 0) {
00323         i__1 = -(*info);
00324         xerbla_("CHBGVX", &i__1);
00325         return 0;
00326     }
00327 
00328 /*     Quick return if possible */
00329 
00330     *m = 0;
00331     if (*n == 0) {
00332         return 0;
00333     }
00334 
00335 /*     Form a split Cholesky factorization of B. */
00336 
00337     cpbstf_(uplo, n, kb, &bb[bb_offset], ldbb, info);
00338     if (*info != 0) {
00339         *info = *n + *info;
00340         return 0;
00341     }
00342 
00343 /*     Transform problem to standard eigenvalue problem. */
00344 
00345     chbgst_(jobz, uplo, n, ka, kb, &ab[ab_offset], ldab, &bb[bb_offset], ldbb, 
00346              &q[q_offset], ldq, &work[1], &rwork[1], &iinfo);
00347 
00348 /*     Solve the standard eigenvalue problem. */
00349 /*     Reduce Hermitian band matrix to tridiagonal form. */
00350 
00351     indd = 1;
00352     inde = indd + *n;
00353     indrwk = inde + *n;
00354     indwrk = 1;
00355     if (wantz) {
00356         *(unsigned char *)vect = 'U';
00357     } else {
00358         *(unsigned char *)vect = 'N';
00359     }
00360     chbtrd_(vect, uplo, n, ka, &ab[ab_offset], ldab, &rwork[indd], &rwork[
00361             inde], &q[q_offset], ldq, &work[indwrk], &iinfo);
00362 
00363 /*     If all eigenvalues are desired and ABSTOL is less than or equal */
00364 /*     to zero, then call SSTERF or CSTEQR.  If this fails for some */
00365 /*     eigenvalue, then try SSTEBZ. */
00366 
00367     test = FALSE_;
00368     if (indeig) {
00369         if (*il == 1 && *iu == *n) {
00370             test = TRUE_;
00371         }
00372     }
00373     if ((alleig || test) && *abstol <= 0.f) {
00374         scopy_(n, &rwork[indd], &c__1, &w[1], &c__1);
00375         indee = indrwk + (*n << 1);
00376         i__1 = *n - 1;
00377         scopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
00378         if (! wantz) {
00379             ssterf_(n, &w[1], &rwork[indee], info);
00380         } else {
00381             clacpy_("A", n, n, &q[q_offset], ldq, &z__[z_offset], ldz);
00382             csteqr_(jobz, n, &w[1], &rwork[indee], &z__[z_offset], ldz, &
00383                     rwork[indrwk], info);
00384             if (*info == 0) {
00385                 i__1 = *n;
00386                 for (i__ = 1; i__ <= i__1; ++i__) {
00387                     ifail[i__] = 0;
00388 /* L10: */
00389                 }
00390             }
00391         }
00392         if (*info == 0) {
00393             *m = *n;
00394             goto L30;
00395         }
00396         *info = 0;
00397     }
00398 
00399 /*     Otherwise, call SSTEBZ and, if eigenvectors are desired, */
00400 /*     call CSTEIN. */
00401 
00402     if (wantz) {
00403         *(unsigned char *)order = 'B';
00404     } else {
00405         *(unsigned char *)order = 'E';
00406     }
00407     indibl = 1;
00408     indisp = indibl + *n;
00409     indiwk = indisp + *n;
00410     sstebz_(range, order, n, vl, vu, il, iu, abstol, &rwork[indd], &rwork[
00411             inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &rwork[
00412             indrwk], &iwork[indiwk], info);
00413 
00414     if (wantz) {
00415         cstein_(n, &rwork[indd], &rwork[inde], m, &w[1], &iwork[indibl], &
00416                 iwork[indisp], &z__[z_offset], ldz, &rwork[indrwk], &iwork[
00417                 indiwk], &ifail[1], info);
00418 
00419 /*        Apply unitary matrix used in reduction to tridiagonal */
00420 /*        form to eigenvectors returned by CSTEIN. */
00421 
00422         i__1 = *m;
00423         for (j = 1; j <= i__1; ++j) {
00424             ccopy_(n, &z__[j * z_dim1 + 1], &c__1, &work[1], &c__1);
00425             cgemv_("N", n, n, &c_b2, &q[q_offset], ldq, &work[1], &c__1, &
00426                     c_b1, &z__[j * z_dim1 + 1], &c__1);
00427 /* L20: */
00428         }
00429     }
00430 
00431 L30:
00432 
00433 /*     If eigenvalues are not in order, then sort them, along with */
00434 /*     eigenvectors. */
00435 
00436     if (wantz) {
00437         i__1 = *m - 1;
00438         for (j = 1; j <= i__1; ++j) {
00439             i__ = 0;
00440             tmp1 = w[j];
00441             i__2 = *m;
00442             for (jj = j + 1; jj <= i__2; ++jj) {
00443                 if (w[jj] < tmp1) {
00444                     i__ = jj;
00445                     tmp1 = w[jj];
00446                 }
00447 /* L40: */
00448             }
00449 
00450             if (i__ != 0) {
00451                 itmp1 = iwork[indibl + i__ - 1];
00452                 w[i__] = w[j];
00453                 iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
00454                 w[j] = tmp1;
00455                 iwork[indibl + j - 1] = itmp1;
00456                 cswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], 
00457                          &c__1);
00458                 if (*info != 0) {
00459                     itmp1 = ifail[i__];
00460                     ifail[i__] = ifail[j];
00461                     ifail[j] = itmp1;
00462                 }
00463             }
00464 /* L50: */
00465         }
00466     }
00467 
00468     return 0;
00469 
00470 /*     End of CHBGVX */
00471 
00472 } /* chbgvx_ */


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