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


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