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


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