sspgvd.c
Go to the documentation of this file.
00001 /* sspgvd.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 sspgvd_(integer *itype, char *jobz, char *uplo, integer *
00021         n, real *ap, real *bp, real *w, real *z__, integer *ldz, real *work, 
00022         integer *lwork, integer *iwork, integer *liwork, integer *info)
00023 {
00024     /* System generated locals */
00025     integer z_dim1, z_offset, i__1;
00026     real r__1, r__2;
00027 
00028     /* Local variables */
00029     integer j, neig;
00030     extern logical lsame_(char *, char *);
00031     integer lwmin;
00032     char trans[1];
00033     logical upper, wantz;
00034     extern /* Subroutine */ int stpmv_(char *, char *, char *, integer *, 
00035             real *, real *, integer *), stpsv_(char *, 
00036              char *, char *, integer *, real *, real *, integer *), xerbla_(char *, integer *);
00037     integer liwmin;
00038     extern /* Subroutine */ int sspevd_(char *, char *, integer *, real *, 
00039             real *, real *, integer *, real *, integer *, integer *, integer *
00040 , integer *), spptrf_(char *, integer *, real *, 
00041             integer *);
00042     logical lquery;
00043     extern /* Subroutine */ int sspgst_(integer *, char *, integer *, real *, 
00044             real *, integer *);
00045 
00046 
00047 /*  -- LAPACK driver routine (version 3.2) -- */
00048 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00049 /*     November 2006 */
00050 
00051 /*     .. Scalar Arguments .. */
00052 /*     .. */
00053 /*     .. Array Arguments .. */
00054 /*     .. */
00055 
00056 /*  Purpose */
00057 /*  ======= */
00058 
00059 /*  SSPGVD computes all the eigenvalues, and optionally, the eigenvectors */
00060 /*  of a real generalized symmetric-definite eigenproblem, of the form */
00061 /*  A*x=(lambda)*B*x,  A*Bx=(lambda)*x,  or B*A*x=(lambda)*x.  Here A and */
00062 /*  B are assumed to be symmetric, stored in packed format, and B is also */
00063 /*  positive definite. */
00064 /*  If eigenvectors are desired, it uses a divide and conquer algorithm. */
00065 
00066 /*  The divide and conquer algorithm makes very mild assumptions about */
00067 /*  floating point arithmetic. It will work on machines with a guard */
00068 /*  digit in add/subtract, or on those binary machines without guard */
00069 /*  digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
00070 /*  Cray-2. It could conceivably fail on hexadecimal or decimal machines */
00071 /*  without guard digits, but we know of none. */
00072 
00073 /*  Arguments */
00074 /*  ========= */
00075 
00076 /*  ITYPE   (input) INTEGER */
00077 /*          Specifies the problem type to be solved: */
00078 /*          = 1:  A*x = (lambda)*B*x */
00079 /*          = 2:  A*B*x = (lambda)*x */
00080 /*          = 3:  B*A*x = (lambda)*x */
00081 
00082 /*  JOBZ    (input) CHARACTER*1 */
00083 /*          = 'N':  Compute eigenvalues only; */
00084 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00085 
00086 /*  UPLO    (input) CHARACTER*1 */
00087 /*          = 'U':  Upper triangles of A and B are stored; */
00088 /*          = 'L':  Lower triangles of A and B are stored. */
00089 
00090 /*  N       (input) INTEGER */
00091 /*          The order of the matrices A and B.  N >= 0. */
00092 
00093 /*  AP      (input/output) REAL array, dimension (N*(N+1)/2) */
00094 /*          On entry, the upper or lower triangle of the symmetric matrix */
00095 /*          A, packed columnwise in a linear array.  The j-th column of A */
00096 /*          is stored in the array AP as follows: */
00097 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00098 /*          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
00099 
00100 /*          On exit, the contents of AP are destroyed. */
00101 
00102 /*  BP      (input/output) REAL array, dimension (N*(N+1)/2) */
00103 /*          On entry, the upper or lower triangle of the symmetric matrix */
00104 /*          B, packed columnwise in a linear array.  The j-th column of B */
00105 /*          is stored in the array BP as follows: */
00106 /*          if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j; */
00107 /*          if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n. */
00108 
00109 /*          On exit, the triangular factor U or L from the Cholesky */
00110 /*          factorization B = U**T*U or B = L*L**T, in the same storage */
00111 /*          format as B. */
00112 
00113 /*  W       (output) REAL array, dimension (N) */
00114 /*          If INFO = 0, the eigenvalues in ascending order. */
00115 
00116 /*  Z       (output) REAL array, dimension (LDZ, N) */
00117 /*          If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */
00118 /*          eigenvectors.  The eigenvectors are normalized as follows: */
00119 /*          if ITYPE = 1 or 2, Z**T*B*Z = I; */
00120 /*          if ITYPE = 3, Z**T*inv(B)*Z = I. */
00121 /*          If JOBZ = 'N', then Z is not referenced. */
00122 
00123 /*  LDZ     (input) INTEGER */
00124 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00125 /*          JOBZ = 'V', LDZ >= max(1,N). */
00126 
00127 /*  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK)) */
00128 /*          On exit, if INFO = 0, WORK(1) returns the required LWORK. */
00129 
00130 /*  LWORK   (input) INTEGER */
00131 /*          The dimension of the array WORK. */
00132 /*          If N <= 1,               LWORK >= 1. */
00133 /*          If JOBZ = 'N' and N > 1, LWORK >= 2*N. */
00134 /*          If JOBZ = 'V' and N > 1, LWORK >= 1 + 6*N + 2*N**2. */
00135 
00136 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00137 /*          only calculates the required sizes of the WORK and IWORK */
00138 /*          arrays, returns these values as the first entries of the WORK */
00139 /*          and IWORK arrays, and no error message related to LWORK or */
00140 /*          LIWORK is issued by XERBLA. */
00141 
00142 /*  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
00143 /*          On exit, if INFO = 0, IWORK(1) returns the required LIWORK. */
00144 
00145 /*  LIWORK  (input) INTEGER */
00146 /*          The dimension of the array IWORK. */
00147 /*          If JOBZ  = 'N' or N <= 1, LIWORK >= 1. */
00148 /*          If JOBZ  = 'V' and N > 1, LIWORK >= 3 + 5*N. */
00149 
00150 /*          If LIWORK = -1, then a workspace query is assumed; the */
00151 /*          routine only calculates the required sizes of the WORK and */
00152 /*          IWORK arrays, returns these values as the first entries of */
00153 /*          the WORK and IWORK arrays, and no error message related to */
00154 /*          LWORK or LIWORK is issued by XERBLA. */
00155 
00156 /*  INFO    (output) INTEGER */
00157 /*          = 0:  successful exit */
00158 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00159 /*          > 0:  SPPTRF or SSPEVD returned an error code: */
00160 /*             <= N:  if INFO = i, SSPEVD failed to converge; */
00161 /*                    i off-diagonal elements of an intermediate */
00162 /*                    tridiagonal form did not converge to zero; */
00163 /*             > N:   if INFO = N + i, for 1 <= i <= N, then the leading */
00164 /*                    minor of order i of B is not positive definite. */
00165 /*                    The factorization of B could not be completed and */
00166 /*                    no eigenvalues or eigenvectors were computed. */
00167 
00168 /*  Further Details */
00169 /*  =============== */
00170 
00171 /*  Based on contributions by */
00172 /*     Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
00173 
00174 /*  ===================================================================== */
00175 
00176 /*     .. Parameters .. */
00177 /*     .. */
00178 /*     .. Local Scalars .. */
00179 /*     .. */
00180 /*     .. External Functions .. */
00181 /*     .. */
00182 /*     .. External Subroutines .. */
00183 /*     .. */
00184 /*     .. Intrinsic Functions .. */
00185 /*     .. */
00186 /*     .. Executable Statements .. */
00187 
00188 /*     Test the input parameters. */
00189 
00190     /* Parameter adjustments */
00191     --ap;
00192     --bp;
00193     --w;
00194     z_dim1 = *ldz;
00195     z_offset = 1 + z_dim1;
00196     z__ -= z_offset;
00197     --work;
00198     --iwork;
00199 
00200     /* Function Body */
00201     wantz = lsame_(jobz, "V");
00202     upper = lsame_(uplo, "U");
00203     lquery = *lwork == -1 || *liwork == -1;
00204 
00205     *info = 0;
00206     if (*itype < 1 || *itype > 3) {
00207         *info = -1;
00208     } else if (! (wantz || lsame_(jobz, "N"))) {
00209         *info = -2;
00210     } else if (! (upper || lsame_(uplo, "L"))) {
00211         *info = -3;
00212     } else if (*n < 0) {
00213         *info = -4;
00214     } else if (*ldz < 1 || wantz && *ldz < *n) {
00215         *info = -9;
00216     }
00217 
00218     if (*info == 0) {
00219         if (*n <= 1) {
00220             liwmin = 1;
00221             lwmin = 1;
00222         } else {
00223             if (wantz) {
00224                 liwmin = *n * 5 + 3;
00225 /* Computing 2nd power */
00226                 i__1 = *n;
00227                 lwmin = *n * 6 + 1 + (i__1 * i__1 << 1);
00228             } else {
00229                 liwmin = 1;
00230                 lwmin = *n << 1;
00231             }
00232         }
00233         work[1] = (real) lwmin;
00234         iwork[1] = liwmin;
00235 
00236         if (*lwork < lwmin && ! lquery) {
00237             *info = -11;
00238         } else if (*liwork < liwmin && ! lquery) {
00239             *info = -13;
00240         }
00241     }
00242 
00243     if (*info != 0) {
00244         i__1 = -(*info);
00245         xerbla_("SSPGVD", &i__1);
00246         return 0;
00247     } else if (lquery) {
00248         return 0;
00249     }
00250 
00251 /*     Quick return if possible */
00252 
00253     if (*n == 0) {
00254         return 0;
00255     }
00256 
00257 /*     Form a Cholesky factorization of BP. */
00258 
00259     spptrf_(uplo, n, &bp[1], info);
00260     if (*info != 0) {
00261         *info = *n + *info;
00262         return 0;
00263     }
00264 
00265 /*     Transform problem to standard eigenvalue problem and solve. */
00266 
00267     sspgst_(itype, uplo, n, &ap[1], &bp[1], info);
00268     sspevd_(jobz, uplo, n, &ap[1], &w[1], &z__[z_offset], ldz, &work[1], 
00269             lwork, &iwork[1], liwork, info);
00270 /* Computing MAX */
00271     r__1 = (real) lwmin;
00272     lwmin = dmax(r__1,work[1]);
00273 /* Computing MAX */
00274     r__1 = (real) liwmin, r__2 = (real) iwork[1];
00275     liwmin = dmax(r__1,r__2);
00276 
00277     if (wantz) {
00278 
00279 /*        Backtransform eigenvectors to the original problem. */
00280 
00281         neig = *n;
00282         if (*info > 0) {
00283             neig = *info - 1;
00284         }
00285         if (*itype == 1 || *itype == 2) {
00286 
00287 /*           For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
00288 /*           backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
00289 
00290             if (upper) {
00291                 *(unsigned char *)trans = 'N';
00292             } else {
00293                 *(unsigned char *)trans = 'T';
00294             }
00295 
00296             i__1 = neig;
00297             for (j = 1; j <= i__1; ++j) {
00298                 stpsv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 + 
00299                         1], &c__1);
00300 /* L10: */
00301             }
00302 
00303         } else if (*itype == 3) {
00304 
00305 /*           For B*A*x=(lambda)*x; */
00306 /*           backtransform eigenvectors: x = L*y or U'*y */
00307 
00308             if (upper) {
00309                 *(unsigned char *)trans = 'T';
00310             } else {
00311                 *(unsigned char *)trans = 'N';
00312             }
00313 
00314             i__1 = neig;
00315             for (j = 1; j <= i__1; ++j) {
00316                 stpmv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 + 
00317                         1], &c__1);
00318 /* L20: */
00319             }
00320         }
00321     }
00322 
00323     work[1] = (real) lwmin;
00324     iwork[1] = liwmin;
00325 
00326     return 0;
00327 
00328 /*     End of SSPGVD */
00329 
00330 } /* sspgvd_ */


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