ssygv.c
Go to the documentation of this file.
00001 /* ssygv.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_b16 = 1.f;
00021 
00022 /* Subroutine */ int ssygv_(integer *itype, char *jobz, char *uplo, integer *
00023         n, real *a, integer *lda, real *b, integer *ldb, real *w, real *work, 
00024         integer *lwork, integer *info)
00025 {
00026     /* System generated locals */
00027     integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2;
00028 
00029     /* Local variables */
00030     integer nb, neig;
00031     extern logical lsame_(char *, char *);
00032     char trans[1];
00033     logical upper;
00034     extern /* Subroutine */ int strmm_(char *, char *, char *, char *, 
00035             integer *, integer *, real *, real *, integer *, real *, integer *
00036 );
00037     logical wantz;
00038     extern /* Subroutine */ int strsm_(char *, char *, char *, char *, 
00039             integer *, integer *, real *, real *, integer *, real *, integer *
00040 ), ssyev_(char *, char *, integer 
00041             *, real *, integer *, real *, real *, integer *, integer *), xerbla_(char *, integer *);
00042     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00043             integer *, integer *);
00044     integer lwkmin;
00045     extern /* Subroutine */ int spotrf_(char *, integer *, real *, integer *, 
00046             integer *);
00047     integer lwkopt;
00048     logical lquery;
00049     extern /* Subroutine */ int ssygst_(integer *, char *, integer *, real *, 
00050             integer *, real *, integer *, integer *);
00051 
00052 
00053 /*  -- LAPACK driver routine (version 3.2) -- */
00054 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00055 /*     November 2006 */
00056 
00057 /*     .. Scalar Arguments .. */
00058 /*     .. */
00059 /*     .. Array Arguments .. */
00060 /*     .. */
00061 
00062 /*  Purpose */
00063 /*  ======= */
00064 
00065 /*  SSYGV computes all the eigenvalues, and optionally, the eigenvectors */
00066 /*  of a real generalized symmetric-definite eigenproblem, of the form */
00067 /*  A*x=(lambda)*B*x,  A*Bx=(lambda)*x,  or B*A*x=(lambda)*x. */
00068 /*  Here A and B are assumed to be symmetric and B is also */
00069 /*  positive definite. */
00070 
00071 /*  Arguments */
00072 /*  ========= */
00073 
00074 /*  ITYPE   (input) INTEGER */
00075 /*          Specifies the problem type to be solved: */
00076 /*          = 1:  A*x = (lambda)*B*x */
00077 /*          = 2:  A*B*x = (lambda)*x */
00078 /*          = 3:  B*A*x = (lambda)*x */
00079 
00080 /*  JOBZ    (input) CHARACTER*1 */
00081 /*          = 'N':  Compute eigenvalues only; */
00082 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00083 
00084 /*  UPLO    (input) CHARACTER*1 */
00085 /*          = 'U':  Upper triangles of A and B are stored; */
00086 /*          = 'L':  Lower triangles of A and B are stored. */
00087 
00088 /*  N       (input) INTEGER */
00089 /*          The order of the matrices A and B.  N >= 0. */
00090 
00091 /*  A       (input/output) REAL array, dimension (LDA, N) */
00092 /*          On entry, the symmetric matrix A.  If UPLO = 'U', the */
00093 /*          leading N-by-N upper triangular part of A contains the */
00094 /*          upper triangular part of the matrix A.  If UPLO = 'L', */
00095 /*          the leading N-by-N lower triangular part of A contains */
00096 /*          the lower triangular part of the matrix A. */
00097 
00098 /*          On exit, if JOBZ = 'V', then if INFO = 0, A contains the */
00099 /*          matrix Z of eigenvectors.  The eigenvectors are normalized */
00100 /*          as follows: */
00101 /*          if ITYPE = 1 or 2, Z**T*B*Z = I; */
00102 /*          if ITYPE = 3, Z**T*inv(B)*Z = I. */
00103 /*          If JOBZ = 'N', then on exit the upper triangle (if UPLO='U') */
00104 /*          or the lower triangle (if UPLO='L') of A, including the */
00105 /*          diagonal, is destroyed. */
00106 
00107 /*  LDA     (input) INTEGER */
00108 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00109 
00110 /*  B       (input/output) REAL array, dimension (LDB, N) */
00111 /*          On entry, the symmetric positive definite matrix B. */
00112 /*          If UPLO = 'U', the leading N-by-N upper triangular part of B */
00113 /*          contains the upper triangular part of the matrix B. */
00114 /*          If UPLO = 'L', the leading N-by-N lower triangular part of B */
00115 /*          contains the lower triangular part of the matrix B. */
00116 
00117 /*          On exit, if INFO <= N, the part of B containing the matrix is */
00118 /*          overwritten by the triangular factor U or L from the Cholesky */
00119 /*          factorization B = U**T*U or B = L*L**T. */
00120 
00121 /*  LDB     (input) INTEGER */
00122 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00123 
00124 /*  W       (output) REAL array, dimension (N) */
00125 /*          If INFO = 0, the eigenvalues in ascending order. */
00126 
00127 /*  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK)) */
00128 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00129 
00130 /*  LWORK   (input) INTEGER */
00131 /*          The length of the array WORK.  LWORK >= max(1,3*N-1). */
00132 /*          For optimal efficiency, LWORK >= (NB+2)*N, */
00133 /*          where NB is the blocksize for SSYTRD returned by ILAENV. */
00134 
00135 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00136 /*          only calculates the optimal size of the WORK array, returns */
00137 /*          this value as the first entry of the WORK array, and no error */
00138 /*          message related to LWORK is issued by XERBLA. */
00139 
00140 /*  INFO    (output) INTEGER */
00141 /*          = 0:  successful exit */
00142 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00143 /*          > 0:  SPOTRF or SSYEV returned an error code: */
00144 /*             <= N:  if INFO = i, SSYEV failed to converge; */
00145 /*                    i off-diagonal elements of an intermediate */
00146 /*                    tridiagonal form did not converge to zero; */
00147 /*             > N:   if INFO = N + i, for 1 <= i <= N, then the leading */
00148 /*                    minor of order i of B is not positive definite. */
00149 /*                    The factorization of B could not be completed and */
00150 /*                    no eigenvalues or eigenvectors were computed. */
00151 
00152 /*  ===================================================================== */
00153 
00154 /*     .. Parameters .. */
00155 /*     .. */
00156 /*     .. Local Scalars .. */
00157 /*     .. */
00158 /*     .. External Functions .. */
00159 /*     .. */
00160 /*     .. External Subroutines .. */
00161 /*     .. */
00162 /*     .. Intrinsic Functions .. */
00163 /*     .. */
00164 /*     .. Executable Statements .. */
00165 
00166 /*     Test the input parameters. */
00167 
00168     /* Parameter adjustments */
00169     a_dim1 = *lda;
00170     a_offset = 1 + a_dim1;
00171     a -= a_offset;
00172     b_dim1 = *ldb;
00173     b_offset = 1 + b_dim1;
00174     b -= b_offset;
00175     --w;
00176     --work;
00177 
00178     /* Function Body */
00179     wantz = lsame_(jobz, "V");
00180     upper = lsame_(uplo, "U");
00181     lquery = *lwork == -1;
00182 
00183     *info = 0;
00184     if (*itype < 1 || *itype > 3) {
00185         *info = -1;
00186     } else if (! (wantz || lsame_(jobz, "N"))) {
00187         *info = -2;
00188     } else if (! (upper || lsame_(uplo, "L"))) {
00189         *info = -3;
00190     } else if (*n < 0) {
00191         *info = -4;
00192     } else if (*lda < max(1,*n)) {
00193         *info = -6;
00194     } else if (*ldb < max(1,*n)) {
00195         *info = -8;
00196     }
00197 
00198     if (*info == 0) {
00199 /* Computing MAX */
00200         i__1 = 1, i__2 = *n * 3 - 1;
00201         lwkmin = max(i__1,i__2);
00202         nb = ilaenv_(&c__1, "SSYTRD", uplo, n, &c_n1, &c_n1, &c_n1);
00203 /* Computing MAX */
00204         i__1 = lwkmin, i__2 = (nb + 2) * *n;
00205         lwkopt = max(i__1,i__2);
00206         work[1] = (real) lwkopt;
00207 
00208         if (*lwork < lwkmin && ! lquery) {
00209             *info = -11;
00210         }
00211     }
00212 
00213     if (*info != 0) {
00214         i__1 = -(*info);
00215         xerbla_("SSYGV ", &i__1);
00216         return 0;
00217     } else if (lquery) {
00218         return 0;
00219     }
00220 
00221 /*     Quick return if possible */
00222 
00223     if (*n == 0) {
00224         return 0;
00225     }
00226 
00227 /*     Form a Cholesky factorization of B. */
00228 
00229     spotrf_(uplo, n, &b[b_offset], ldb, info);
00230     if (*info != 0) {
00231         *info = *n + *info;
00232         return 0;
00233     }
00234 
00235 /*     Transform problem to standard eigenvalue problem and solve. */
00236 
00237     ssygst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info);
00238     ssyev_(jobz, uplo, n, &a[a_offset], lda, &w[1], &work[1], lwork, info);
00239 
00240     if (wantz) {
00241 
00242 /*        Backtransform eigenvectors to the original problem. */
00243 
00244         neig = *n;
00245         if (*info > 0) {
00246             neig = *info - 1;
00247         }
00248         if (*itype == 1 || *itype == 2) {
00249 
00250 /*           For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
00251 /*           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
00252 
00253             if (upper) {
00254                 *(unsigned char *)trans = 'N';
00255             } else {
00256                 *(unsigned char *)trans = 'T';
00257             }
00258 
00259             strsm_("Left", uplo, trans, "Non-unit", n, &neig, &c_b16, &b[
00260                     b_offset], ldb, &a[a_offset], lda);
00261 
00262         } else if (*itype == 3) {
00263 
00264 /*           For B*A*x=(lambda)*x; */
00265 /*           backtransform eigenvectors: x = L*y or U'*y */
00266 
00267             if (upper) {
00268                 *(unsigned char *)trans = 'T';
00269             } else {
00270                 *(unsigned char *)trans = 'N';
00271             }
00272 
00273             strmm_("Left", uplo, trans, "Non-unit", n, &neig, &c_b16, &b[
00274                     b_offset], ldb, &a[a_offset], lda);
00275         }
00276     }
00277 
00278     work[1] = (real) lwkopt;
00279     return 0;
00280 
00281 /*     End of SSYGV */
00282 
00283 } /* ssygv_ */


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