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


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