dspevd.c
Go to the documentation of this file.
00001 /* dspevd.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 dspevd_(char *jobz, char *uplo, integer *n, doublereal *
00021         ap, doublereal *w, doublereal *z__, integer *ldz, doublereal *work, 
00022         integer *lwork, integer *iwork, integer *liwork, integer *info)
00023 {
00024     /* System generated locals */
00025     integer z_dim1, z_offset, i__1;
00026     doublereal d__1;
00027 
00028     /* Builtin functions */
00029     double sqrt(doublereal);
00030 
00031     /* Local variables */
00032     doublereal eps;
00033     integer inde;
00034     doublereal anrm, rmin, rmax;
00035     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00036             integer *);
00037     doublereal sigma;
00038     extern logical lsame_(char *, char *);
00039     integer iinfo, lwmin;
00040     logical wantz;
00041     extern doublereal dlamch_(char *);
00042     integer iscale;
00043     extern /* Subroutine */ int dstedc_(char *, integer *, doublereal *, 
00044             doublereal *, doublereal *, integer *, doublereal *, integer *, 
00045             integer *, integer *, integer *);
00046     doublereal safmin;
00047     extern /* Subroutine */ int xerbla_(char *, integer *);
00048     doublereal bignum;
00049     extern doublereal dlansp_(char *, char *, integer *, doublereal *, 
00050             doublereal *);
00051     integer indtau;
00052     extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *, 
00053              integer *);
00054     integer indwrk, liwmin;
00055     extern /* Subroutine */ int dsptrd_(char *, integer *, doublereal *, 
00056             doublereal *, doublereal *, doublereal *, integer *), 
00057             dopmtr_(char *, char *, char *, integer *, integer *, doublereal *
00058 , doublereal *, doublereal *, integer *, doublereal *, integer *);
00059     integer llwork;
00060     doublereal smlnum;
00061     logical lquery;
00062 
00063 
00064 /*  -- LAPACK driver routine (version 3.2) -- */
00065 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00066 /*     November 2006 */
00067 
00068 /*     .. Scalar Arguments .. */
00069 /*     .. */
00070 /*     .. Array Arguments .. */
00071 /*     .. */
00072 
00073 /*  Purpose */
00074 /*  ======= */
00075 
00076 /*  DSPEVD computes all the eigenvalues and, optionally, eigenvectors */
00077 /*  of a real symmetric matrix A in packed storage. If eigenvectors are */
00078 /*  desired, it uses a divide and conquer algorithm. */
00079 
00080 /*  The divide and conquer algorithm makes very mild assumptions about */
00081 /*  floating point arithmetic. It will work on machines with a guard */
00082 /*  digit in add/subtract, or on those binary machines without guard */
00083 /*  digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
00084 /*  Cray-2. It could conceivably fail on hexadecimal or decimal machines */
00085 /*  without guard digits, but we know of none. */
00086 
00087 /*  Arguments */
00088 /*  ========= */
00089 
00090 /*  JOBZ    (input) CHARACTER*1 */
00091 /*          = 'N':  Compute eigenvalues only; */
00092 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00093 
00094 /*  UPLO    (input) CHARACTER*1 */
00095 /*          = 'U':  Upper triangle of A is stored; */
00096 /*          = 'L':  Lower triangle of A is stored. */
00097 
00098 /*  N       (input) INTEGER */
00099 /*          The order of the matrix A.  N >= 0. */
00100 
00101 /*  AP      (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
00102 /*          On entry, the upper or lower triangle of the symmetric matrix */
00103 /*          A, packed columnwise in a linear array.  The j-th column of A */
00104 /*          is stored in the array AP as follows: */
00105 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00106 /*          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
00107 
00108 /*          On exit, AP is overwritten by values generated during the */
00109 /*          reduction to tridiagonal form.  If UPLO = 'U', the diagonal */
00110 /*          and first superdiagonal of the tridiagonal matrix T overwrite */
00111 /*          the corresponding elements of A, and if UPLO = 'L', the */
00112 /*          diagonal and first subdiagonal of T overwrite the */
00113 /*          corresponding elements of A. */
00114 
00115 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00116 /*          If INFO = 0, the eigenvalues in ascending order. */
00117 
00118 /*  Z       (output) DOUBLE PRECISION array, dimension (LDZ, N) */
00119 /*          If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */
00120 /*          eigenvectors of the matrix A, with the i-th column of Z */
00121 /*          holding the eigenvector associated with W(i). */
00122 /*          If JOBZ = 'N', then Z is not referenced. */
00123 
00124 /*  LDZ     (input) INTEGER */
00125 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00126 /*          JOBZ = 'V', LDZ >= max(1,N). */
00127 
00128 /*  WORK    (workspace/output) DOUBLE PRECISION array, */
00129 /*                                         dimension (LWORK) */
00130 /*          On exit, if INFO = 0, WORK(1) returns the required LWORK. */
00131 
00132 /*  LWORK   (input) INTEGER */
00133 /*          The dimension of the array WORK. */
00134 /*          If N <= 1,               LWORK must be at least 1. */
00135 /*          If JOBZ = 'N' and N > 1, LWORK must be at least 2*N. */
00136 /*          If JOBZ = 'V' and N > 1, LWORK must be at least */
00137 /*                                                 1 + 6*N + N**2. */
00138 
00139 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00140 /*          only calculates the required sizes of the WORK and IWORK */
00141 /*          arrays, returns these values as the first entries of the WORK */
00142 /*          and IWORK arrays, and no error message related to LWORK or */
00143 /*          LIWORK is issued by XERBLA. */
00144 
00145 /*  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
00146 /*          On exit, if INFO = 0, IWORK(1) returns the required LIWORK. */
00147 
00148 /*  LIWORK  (input) INTEGER */
00149 /*          The dimension of the array IWORK. */
00150 /*          If JOBZ  = 'N' or N <= 1, LIWORK must be at least 1. */
00151 /*          If JOBZ  = 'V' and N > 1, LIWORK must be at least 3 + 5*N. */
00152 
00153 /*          If LIWORK = -1, then a workspace query is assumed; the */
00154 /*          routine only calculates the required sizes of the WORK and */
00155 /*          IWORK arrays, returns these values as the first entries of */
00156 /*          the WORK and IWORK arrays, and no error message related to */
00157 /*          LWORK or LIWORK is issued by XERBLA. */
00158 
00159 /*  INFO    (output) INTEGER */
00160 /*          = 0:  successful exit */
00161 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00162 /*          > 0:  if INFO = i, the algorithm failed to converge; i */
00163 /*                off-diagonal elements of an intermediate tridiagonal */
00164 /*                form did not converge to zero. */
00165 
00166 /*  ===================================================================== */
00167 
00168 /*     .. Parameters .. */
00169 /*     .. */
00170 /*     .. Local Scalars .. */
00171 /*     .. */
00172 /*     .. External Functions .. */
00173 /*     .. */
00174 /*     .. External Subroutines .. */
00175 /*     .. */
00176 /*     .. Intrinsic Functions .. */
00177 /*     .. */
00178 /*     .. Executable Statements .. */
00179 
00180 /*     Test the input parameters. */
00181 
00182     /* Parameter adjustments */
00183     --ap;
00184     --w;
00185     z_dim1 = *ldz;
00186     z_offset = 1 + z_dim1;
00187     z__ -= z_offset;
00188     --work;
00189     --iwork;
00190 
00191     /* Function Body */
00192     wantz = lsame_(jobz, "V");
00193     lquery = *lwork == -1 || *liwork == -1;
00194 
00195     *info = 0;
00196     if (! (wantz || lsame_(jobz, "N"))) {
00197         *info = -1;
00198     } else if (! (lsame_(uplo, "U") || lsame_(uplo, 
00199             "L"))) {
00200         *info = -2;
00201     } else if (*n < 0) {
00202         *info = -3;
00203     } else if (*ldz < 1 || wantz && *ldz < *n) {
00204         *info = -7;
00205     }
00206 
00207     if (*info == 0) {
00208         if (*n <= 1) {
00209             liwmin = 1;
00210             lwmin = 1;
00211         } else {
00212             if (wantz) {
00213                 liwmin = *n * 5 + 3;
00214 /* Computing 2nd power */
00215                 i__1 = *n;
00216                 lwmin = *n * 6 + 1 + i__1 * i__1;
00217             } else {
00218                 liwmin = 1;
00219                 lwmin = *n << 1;
00220             }
00221         }
00222         iwork[1] = liwmin;
00223         work[1] = (doublereal) lwmin;
00224 
00225         if (*lwork < lwmin && ! lquery) {
00226             *info = -9;
00227         } else if (*liwork < liwmin && ! lquery) {
00228             *info = -11;
00229         }
00230     }
00231 
00232     if (*info != 0) {
00233         i__1 = -(*info);
00234         xerbla_("DSPEVD", &i__1);
00235         return 0;
00236     } else if (lquery) {
00237         return 0;
00238     }
00239 
00240 /*     Quick return if possible */
00241 
00242     if (*n == 0) {
00243         return 0;
00244     }
00245 
00246     if (*n == 1) {
00247         w[1] = ap[1];
00248         if (wantz) {
00249             z__[z_dim1 + 1] = 1.;
00250         }
00251         return 0;
00252     }
00253 
00254 /*     Get machine constants. */
00255 
00256     safmin = dlamch_("Safe minimum");
00257     eps = dlamch_("Precision");
00258     smlnum = safmin / eps;
00259     bignum = 1. / smlnum;
00260     rmin = sqrt(smlnum);
00261     rmax = sqrt(bignum);
00262 
00263 /*     Scale matrix to allowable range, if necessary. */
00264 
00265     anrm = dlansp_("M", uplo, n, &ap[1], &work[1]);
00266     iscale = 0;
00267     if (anrm > 0. && anrm < rmin) {
00268         iscale = 1;
00269         sigma = rmin / anrm;
00270     } else if (anrm > rmax) {
00271         iscale = 1;
00272         sigma = rmax / anrm;
00273     }
00274     if (iscale == 1) {
00275         i__1 = *n * (*n + 1) / 2;
00276         dscal_(&i__1, &sigma, &ap[1], &c__1);
00277     }
00278 
00279 /*     Call DSPTRD to reduce symmetric packed matrix to tridiagonal form. */
00280 
00281     inde = 1;
00282     indtau = inde + *n;
00283     dsptrd_(uplo, n, &ap[1], &w[1], &work[inde], &work[indtau], &iinfo);
00284 
00285 /*     For eigenvalues only, call DSTERF.  For eigenvectors, first call */
00286 /*     DSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the */
00287 /*     tridiagonal matrix, then call DOPMTR to multiply it by the */
00288 /*     Householder transformations represented in AP. */
00289 
00290     if (! wantz) {
00291         dsterf_(n, &w[1], &work[inde], info);
00292     } else {
00293         indwrk = indtau + *n;
00294         llwork = *lwork - indwrk + 1;
00295         dstedc_("I", n, &w[1], &work[inde], &z__[z_offset], ldz, &work[indwrk]
00296 , &llwork, &iwork[1], liwork, info);
00297         dopmtr_("L", uplo, "N", n, n, &ap[1], &work[indtau], &z__[z_offset], 
00298                 ldz, &work[indwrk], &iinfo);
00299     }
00300 
00301 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00302 
00303     if (iscale == 1) {
00304         d__1 = 1. / sigma;
00305         dscal_(n, &d__1, &w[1], &c__1);
00306     }
00307 
00308     work[1] = (doublereal) lwmin;
00309     iwork[1] = liwmin;
00310     return 0;
00311 
00312 /*     End of DSPEVD */
00313 
00314 } /* dspevd_ */


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