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


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