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


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