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


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