/* Subroutine */ int ssyevr_(char *jobz, char *range, char *uplo, integer *n, real *a, integer *lda, real *vl, real *vu, integer *il, integer *iu, real *abstol, integer *m, real *w, real *z__, integer *ldz, integer * isuppz, real *work, integer *lwork, integer *iwork, integer *liwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2; real r__1, r__2; /* Builtin functions */ double sqrt(doublereal); /* Local variables */ integer i__, j, nb, jj; real eps, vll, vuu, tmp1; integer indd, inde; real anrm; integer imax; real rmin, rmax; logical test; integer inddd, indee; real sigma; extern logical lsame_(char *, char *); integer iinfo; extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *); char order[1]; integer indwk, lwmin; logical lower; extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, integer *), sswap_(integer *, real *, integer *, real *, integer * ); logical wantz, alleig, indeig; integer iscale, ieeeok, indibl, indifl; logical valeig; extern doublereal slamch_(char *); real safmin; extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *); extern /* Subroutine */ int xerbla_(char *, integer *); real abstll, bignum; integer indtau, indisp, indiwo, indwkn, liwmin; logical tryrac; extern /* Subroutine */ int sstein_(integer *, real *, real *, integer *, real *, integer *, integer *, real *, integer *, real *, integer * , integer *, integer *), ssterf_(integer *, real *, real *, integer *); integer llwrkn, llwork, nsplit; real smlnum; extern doublereal slansy_(char *, char *, integer *, real *, integer *, real *); extern /* Subroutine */ int sstebz_(char *, char *, integer *, real *, real *, integer *, integer *, real *, real *, real *, integer *, integer *, real *, integer *, integer *, real *, integer *, integer *), sstemr_(char *, char *, integer *, real *, real *, real *, real *, integer *, integer *, integer *, real *, real *, integer *, integer *, integer *, logical *, real * , integer *, integer *, integer *, integer *); integer lwkopt; logical lquery; extern /* Subroutine */ int sormtr_(char *, char *, char *, integer *, integer *, real *, integer *, real *, real *, integer *, real *, integer *, integer *), ssytrd_(char *, integer *, real *, integer *, real *, real *, real *, real *, integer *, integer *); /* -- LAPACK driver routine (version 3.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* SSYEVR computes selected eigenvalues and, optionally, eigenvectors */ /* of a real symmetric matrix A. Eigenvalues and eigenvectors can be */ /* selected by specifying either a range of values or a range of */ /* indices for the desired eigenvalues. */ /* SSYEVR first reduces the matrix A to tridiagonal form T with a call */ /* to SSYTRD. Then, whenever possible, SSYEVR calls SSTEMR to compute */ /* the eigenspectrum using Relatively Robust Representations. SSTEMR */ /* computes eigenvalues by the dqds algorithm, while orthogonal */ /* eigenvectors are computed from various "good" L D L^T representations */ /* (also known as Relatively Robust Representations). Gram-Schmidt */ /* orthogonalization is avoided as far as possible. More specifically, */ /* the various steps of the algorithm are as follows. */ /* For each unreduced block (submatrix) of T, */ /* (a) Compute T - sigma I = L D L^T, so that L and D */ /* define all the wanted eigenvalues to high relative accuracy. */ /* This means that small relative changes in the entries of D and L */ /* cause only small relative changes in the eigenvalues and */ /* eigenvectors. The standard (unfactored) representation of the */ /* tridiagonal matrix T does not have this property in general. */ /* (b) Compute the eigenvalues to suitable accuracy. */ /* If the eigenvectors are desired, the algorithm attains full */ /* accuracy of the computed eigenvalues only right before */ /* the corresponding vectors have to be computed, see steps c) and d). */ /* (c) For each cluster of close eigenvalues, select a new */ /* shift close to the cluster, find a new factorization, and refine */ /* the shifted eigenvalues to suitable accuracy. */ /* (d) For each eigenvalue with a large enough relative separation compute */ /* the corresponding eigenvector by forming a rank revealing twisted */ /* factorization. Go back to (c) for any clusters that remain. */ /* The desired accuracy of the output can be specified by the input */ /* parameter ABSTOL. */ /* For more details, see SSTEMR's documentation and: */ /* - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */ /* to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */ /* Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */ /* - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */ /* Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */ /* 2004. Also LAPACK Working Note 154. */ /* - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */ /* tridiagonal eigenvalue/eigenvector problem", */ /* Computer Science Division Technical Report No. UCB/CSD-97-971, */ /* UC Berkeley, May 1997. */ /* Note 1 : SSYEVR calls SSTEMR when the full spectrum is requested */ /* on machines which conform to the ieee-754 floating point standard. */ /* SSYEVR calls SSTEBZ and SSTEIN on non-ieee machines and */ /* when partial spectrum requests are made. */ /* Normal execution of SSTEMR may create NaNs and infinities and */ /* hence may abort due to a floating point exception in environments */ /* which do not handle NaNs and infinities in the ieee standard default */ /* manner. */ /* Arguments */ /* ========= */ /* JOBZ (input) CHARACTER*1 */ /* = 'N': Compute eigenvalues only; */ /* = 'V': Compute eigenvalues and eigenvectors. */ /* RANGE (input) CHARACTER*1 */ /* = 'A': all eigenvalues will be found. */ /* = 'V': all eigenvalues in the half-open interval (VL,VU] */ /* will be found. */ /* = 'I': the IL-th through IU-th eigenvalues will be found. */ /* ********* For RANGE = 'V' or 'I' and IU - IL < N - 1, SSTEBZ and */ /* ********* SSTEIN are called */ /* UPLO (input) CHARACTER*1 */ /* = 'U': Upper triangle of A is stored; */ /* = 'L': Lower triangle of A is stored. */ /* N (input) INTEGER */ /* The order of the matrix A. N >= 0. */ /* A (input/output) REAL array, dimension (LDA, N) */ /* On entry, the symmetric matrix A. If UPLO = 'U', the */ /* leading N-by-N upper triangular part of A contains the */ /* upper triangular part of the matrix A. If UPLO = 'L', */ /* the leading N-by-N lower triangular part of A contains */ /* the lower triangular part of the matrix A. */ /* On exit, the lower triangle (if UPLO='L') or the upper */ /* triangle (if UPLO='U') of A, including the diagonal, is */ /* destroyed. */ /* LDA (input) INTEGER */ /* The leading dimension of the array A. LDA >= max(1,N). */ /* VL (input) REAL */ /* VU (input) REAL */ /* If RANGE='V', the lower and upper bounds of the interval to */ /* be searched for eigenvalues. VL < VU. */ /* Not referenced if RANGE = 'A' or 'I'. */ /* IL (input) INTEGER */ /* IU (input) INTEGER */ /* If RANGE='I', the indices (in ascending order) of the */ /* smallest and largest eigenvalues to be returned. */ /* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */ /* Not referenced if RANGE = 'A' or 'V'. */ /* ABSTOL (input) REAL */ /* The absolute error tolerance for the eigenvalues. */ /* An approximate eigenvalue is accepted as converged */ /* when it is determined to lie in an interval [a,b] */ /* of width less than or equal to */ /* ABSTOL + EPS * max( |a|,|b| ) , */ /* where EPS is the machine precision. If ABSTOL is less than */ /* or equal to zero, then EPS*|T| will be used in its place, */ /* where |T| is the 1-norm of the tridiagonal matrix obtained */ /* by reducing A to tridiagonal form. */ /* See "Computing Small Singular Values of Bidiagonal Matrices */ /* with Guaranteed High Relative Accuracy," by Demmel and */ /* Kahan, LAPACK Working Note #3. */ /* If high relative accuracy is important, set ABSTOL to */ /* SLAMCH( 'Safe minimum' ). Doing so will guarantee that */ /* eigenvalues are computed to high relative accuracy when */ /* possible in future releases. The current code does not */ /* make any guarantees about high relative accuracy, but */ /* future releases will. See J. Barlow and J. Demmel, */ /* "Computing Accurate Eigensystems of Scaled Diagonally */ /* Dominant Matrices", LAPACK Working Note #7, for a discussion */ /* of which matrices define their eigenvalues to high relative */ /* accuracy. */ /* M (output) INTEGER */ /* The total number of eigenvalues found. 0 <= M <= N. */ /* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ /* W (output) REAL array, dimension (N) */ /* The first M elements contain the selected eigenvalues in */ /* ascending order. */ /* Z (output) REAL array, dimension (LDZ, max(1,M)) */ /* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */ /* contain the orthonormal eigenvectors of the matrix A */ /* corresponding to the selected eigenvalues, with the i-th */ /* column of Z holding the eigenvector associated with W(i). */ /* If JOBZ = 'N', then Z is not referenced. */ /* Note: the user must ensure that at least max(1,M) columns are */ /* supplied in the array Z; if RANGE = 'V', the exact value of M */ /* is not known in advance and an upper bound must be used. */ /* Supplying N columns is always safe. */ /* LDZ (input) INTEGER */ /* The leading dimension of the array Z. LDZ >= 1, and if */ /* JOBZ = 'V', LDZ >= max(1,N). */ /* ISUPPZ (output) INTEGER array, dimension ( 2*max(1,M) ) */ /* The support of the eigenvectors in Z, i.e., the indices */ /* indicating the nonzero elements in Z. The i-th eigenvector */ /* is nonzero only in elements ISUPPZ( 2*i-1 ) through */ /* ISUPPZ( 2*i ). */ /* ********* Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 */ /* WORK (workspace/output) REAL array, dimension (MAX(1,LWORK)) */ /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ /* LWORK (input) INTEGER */ /* The dimension of the array WORK. LWORK >= max(1,26*N). */ /* For optimal efficiency, LWORK >= (NB+6)*N, */ /* where NB is the max of the blocksize for SSYTRD and SORMTR */ /* returned by ILAENV. */ /* If LWORK = -1, then a workspace query is assumed; the routine */ /* only calculates the optimal sizes of the WORK and IWORK */ /* arrays, returns these values as the first entries of the WORK */ /* and IWORK arrays, and no error message related to LWORK or */ /* LIWORK is issued by XERBLA. */ /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ /* On exit, if INFO = 0, IWORK(1) returns the optimal LWORK. */ /* LIWORK (input) INTEGER */ /* The dimension of the array IWORK. LIWORK >= max(1,10*N). */ /* If LIWORK = -1, then a workspace query is assumed; the */ /* routine only calculates the optimal sizes of the WORK and */ /* IWORK arrays, returns these values as the first entries of */ /* the WORK and IWORK arrays, and no error message related to */ /* LWORK or LIWORK is issued by XERBLA. */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value */ /* > 0: Internal error */ /* Further Details */ /* =============== */ /* Based on contributions by */ /* Inderjit Dhillon, IBM Almaden, USA */ /* Osni Marques, LBNL/NERSC, USA */ /* Ken Stanley, Computer Science Division, University of */ /* California at Berkeley, USA */ /* Jason Riedy, Computer Science Division, University of */ /* California at Berkeley, USA */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input parameters. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; --w; z_dim1 = *ldz; z_offset = 1 + z_dim1; z__ -= z_offset; --isuppz; --work; --iwork; /* Function Body */ ieeeok = ilaenv_(&c__10, "SSYEVR", "N", &c__1, &c__2, &c__3, &c__4); lower = lsame_(uplo, "L"); wantz = lsame_(jobz, "V"); alleig = lsame_(range, "A"); valeig = lsame_(range, "V"); indeig = lsame_(range, "I"); lquery = *lwork == -1 || *liwork == -1; /* Computing MAX */ i__1 = 1, i__2 = *n * 26; lwmin = max(i__1,i__2); /* Computing MAX */ i__1 = 1, i__2 = *n * 10; liwmin = max(i__1,i__2); *info = 0; if (! (wantz || lsame_(jobz, "N"))) { *info = -1; } else if (! (alleig || valeig || indeig)) { *info = -2; } else if (! (lower || lsame_(uplo, "U"))) { *info = -3; } else if (*n < 0) { *info = -4; } else if (*lda < max(1,*n)) { *info = -6; } else { if (valeig) { if (*n > 0 && *vu <= *vl) { *info = -8; } } else if (indeig) { if (*il < 1 || *il > max(1,*n)) { *info = -9; } else if (*iu < min(*n,*il) || *iu > *n) { *info = -10; } } } if (*info == 0) { if (*ldz < 1 || wantz && *ldz < *n) { *info = -15; } } if (*info == 0) { nb = ilaenv_(&c__1, "SSYTRD", uplo, n, &c_n1, &c_n1, &c_n1); /* Computing MAX */ i__1 = nb, i__2 = ilaenv_(&c__1, "SORMTR", uplo, n, &c_n1, &c_n1, & c_n1); nb = max(i__1,i__2); /* Computing MAX */ i__1 = (nb + 1) * *n; lwkopt = max(i__1,lwmin); work[1] = (real) lwkopt; iwork[1] = liwmin; if (*lwork < lwmin && ! lquery) { *info = -18; } else if (*liwork < liwmin && ! lquery) { *info = -20; } } if (*info != 0) { i__1 = -(*info); xerbla_("SSYEVR", &i__1); return 0; } else if (lquery) { return 0; } /* Quick return if possible */ *m = 0; if (*n == 0) { work[1] = 1.f; return 0; } if (*n == 1) { work[1] = 26.f; if (alleig || indeig) { *m = 1; w[1] = a[a_dim1 + 1]; } else { if (*vl < a[a_dim1 + 1] && *vu >= a[a_dim1 + 1]) { *m = 1; w[1] = a[a_dim1 + 1]; } } if (wantz) { z__[z_dim1 + 1] = 1.f; } return 0; } /* Get machine constants. */ safmin = slamch_("Safe minimum"); eps = slamch_("Precision"); smlnum = safmin / eps; bignum = 1.f / smlnum; rmin = sqrt(smlnum); /* Computing MIN */ r__1 = sqrt(bignum), r__2 = 1.f / sqrt(sqrt(safmin)); rmax = dmin(r__1,r__2); /* Scale matrix to allowable range, if necessary. */ iscale = 0; abstll = *abstol; if (valeig) { vll = *vl; vuu = *vu; } anrm = slansy_("M", uplo, n, &a[a_offset], lda, &work[1]); if (anrm > 0.f && anrm < rmin) { iscale = 1; sigma = rmin / anrm; } else if (anrm > rmax) { iscale = 1; sigma = rmax / anrm; } if (iscale == 1) { if (lower) { i__1 = *n; for (j = 1; j <= i__1; ++j) { i__2 = *n - j + 1; sscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1); /* L10: */ } } else { i__1 = *n; for (j = 1; j <= i__1; ++j) { sscal_(&j, &sigma, &a[j * a_dim1 + 1], &c__1); /* L20: */ } } if (*abstol > 0.f) { abstll = *abstol * sigma; } if (valeig) { vll = *vl * sigma; vuu = *vu * sigma; } } /* Initialize indices into workspaces. Note: The IWORK indices are */ /* used only if SSTERF or SSTEMR fail. */ /* WORK(INDTAU:INDTAU+N-1) stores the scalar factors of the */ /* elementary reflectors used in SSYTRD. */ indtau = 1; /* WORK(INDD:INDD+N-1) stores the tridiagonal's diagonal entries. */ indd = indtau + *n; /* WORK(INDE:INDE+N-1) stores the off-diagonal entries of the */ /* tridiagonal matrix from SSYTRD. */ inde = indd + *n; /* WORK(INDDD:INDDD+N-1) is a copy of the diagonal entries over */ /* -written by SSTEMR (the SSTERF path copies the diagonal to W). */ inddd = inde + *n; /* WORK(INDEE:INDEE+N-1) is a copy of the off-diagonal entries over */ /* -written while computing the eigenvalues in SSTERF and SSTEMR. */ indee = inddd + *n; /* INDWK is the starting offset of the left-over workspace, and */ /* LLWORK is the remaining workspace size. */ indwk = indee + *n; llwork = *lwork - indwk + 1; /* IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in SSTEBZ and */ /* stores the block indices of each of the M<=N eigenvalues. */ indibl = 1; /* IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in SSTEBZ and */ /* stores the starting and finishing indices of each block. */ indisp = indibl + *n; /* IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors */ /* that corresponding to eigenvectors that fail to converge in */ /* SSTEIN. This information is discarded; if any fail, the driver */ /* returns INFO > 0. */ indifl = indisp + *n; /* INDIWO is the offset of the remaining integer workspace. */ indiwo = indisp + *n; /* Call SSYTRD to reduce symmetric matrix to tridiagonal form. */ ssytrd_(uplo, n, &a[a_offset], lda, &work[indd], &work[inde], &work[ indtau], &work[indwk], &llwork, &iinfo); /* If all eigenvalues are desired */ /* then call SSTERF or SSTEMR and SORMTR. */ test = FALSE_; if (indeig) { if (*il == 1 && *iu == *n) { test = TRUE_; } } if ((alleig || test) && ieeeok == 1) { if (! wantz) { scopy_(n, &work[indd], &c__1, &w[1], &c__1); i__1 = *n - 1; scopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1); ssterf_(n, &w[1], &work[indee], info); } else { i__1 = *n - 1; scopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1); scopy_(n, &work[indd], &c__1, &work[inddd], &c__1); if (*abstol <= *n * 2.f * eps) { tryrac = TRUE_; } else { tryrac = FALSE_; } sstemr_(jobz, "A", n, &work[inddd], &work[indee], vl, vu, il, iu, m, &w[1], &z__[z_offset], ldz, n, &isuppz[1], &tryrac, & work[indwk], lwork, &iwork[1], liwork, info); /* Apply orthogonal matrix used in reduction to tridiagonal */ /* form to eigenvectors returned by SSTEIN. */ if (wantz && *info == 0) { indwkn = inde; llwrkn = *lwork - indwkn + 1; sormtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau] , &z__[z_offset], ldz, &work[indwkn], &llwrkn, &iinfo); } } if (*info == 0) { /* Everything worked. Skip SSTEBZ/SSTEIN. IWORK(:) are */ /* undefined. */ *m = *n; goto L30; } *info = 0; } /* Otherwise, call SSTEBZ and, if eigenvectors are desired, SSTEIN. */ /* Also call SSTEBZ and SSTEIN if SSTEMR fails. */ if (wantz) { *(unsigned char *)order = 'B'; } else { *(unsigned char *)order = 'E'; } sstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &work[indd], &work[ inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[ indwk], &iwork[indiwo], info); if (wantz) { sstein_(n, &work[indd], &work[inde], m, &w[1], &iwork[indibl], &iwork[ indisp], &z__[z_offset], ldz, &work[indwk], &iwork[indiwo], & iwork[indifl], info); /* Apply orthogonal matrix used in reduction to tridiagonal */ /* form to eigenvectors returned by SSTEIN. */ indwkn = inde; llwrkn = *lwork - indwkn + 1; sormtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[ z_offset], ldz, &work[indwkn], &llwrkn, &iinfo); } /* If matrix was scaled, then rescale eigenvalues appropriately. */ /* Jump here if SSTEMR/SSTEIN succeeded. */ L30: if (iscale == 1) { if (*info == 0) { imax = *m; } else { imax = *info - 1; } r__1 = 1.f / sigma; sscal_(&imax, &r__1, &w[1], &c__1); } /* If eigenvalues are not in order, then sort them, along with */ /* eigenvectors. Note: We do not sort the IFAIL portion of IWORK. */ /* It may not be initialized (if SSTEMR/SSTEIN succeeded), and we do */ /* not return this detailed information to the user. */ if (wantz) { i__1 = *m - 1; for (j = 1; j <= i__1; ++j) { i__ = 0; tmp1 = w[j]; i__2 = *m; for (jj = j + 1; jj <= i__2; ++jj) { if (w[jj] < tmp1) { i__ = jj; tmp1 = w[jj]; } /* L40: */ } if (i__ != 0) { w[i__] = w[j]; w[j] = tmp1; sswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], &c__1); } /* L50: */ } } /* Set WORK(1) to optimal workspace size. */ work[1] = (real) lwkopt; iwork[1] = liwmin; return 0; /* End of SSYEVR */ } /* ssyevr_ */
/* Subroutine */ int ssbevx_(char *jobz, char *range, char *uplo, integer *n, integer *kd, real *ab, integer *ldab, real *q, integer *ldq, real *vl, real *vu, integer *il, integer *iu, real *abstol, integer *m, real * w, real *z, integer *ldz, real *work, integer *iwork, integer *ifail, integer *info) { /* -- LAPACK driver routine (version 2.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University September 30, 1994 Purpose ======= SSBEVX computes selected eigenvalues and, optionally, eigenvectors of a real symmetric band matrix A. Eigenvalues and eigenvectors can be selected by specifying either a range of values or a range of indices for the desired eigenvalues. Arguments ========= JOBZ (input) CHARACTER*1 = 'N': Compute eigenvalues only; = 'V': Compute eigenvalues and eigenvectors. RANGE (input) CHARACTER*1 = 'A': all eigenvalues will be found; = 'V': all eigenvalues in the half-open interval (VL,VU] will be found; = 'I': the IL-th through IU-th eigenvalues will be found. UPLO (input) CHARACTER*1 = 'U': Upper triangle of A is stored; = 'L': Lower triangle of A is stored. N (input) INTEGER The order of the matrix A. N >= 0. KD (input) INTEGER The number of superdiagonals of the matrix A if UPLO = 'U', or the number of subdiagonals if UPLO = 'L'. KD >= 0. AB (input/output) REAL array, dimension (LDAB, N) On entry, the upper or lower triangle of the symmetric band matrix A, stored in the first KD+1 rows of the array. The j-th column of A is stored in the j-th column of the array AB as follows: if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). On exit, AB is overwritten by values generated during the reduction to tridiagonal form. If UPLO = 'U', the first superdiagonal and the diagonal of the tridiagonal matrix T are returned in rows KD and KD+1 of AB, and if UPLO = 'L', the diagonal and first subdiagonal of T are returned in the first two rows of AB. LDAB (input) INTEGER The leading dimension of the array AB. LDAB >= KD + 1. Q (output) REAL array, dimension (LDQ, N) If JOBZ = 'V', the N-by-N orthogonal matrix used in the reduction to tridiagonal form. If JOBZ = 'N', the array Q is not referenced. LDQ (input) INTEGER The leading dimension of the array Q. If JOBZ = 'V', then LDQ >= max(1,N). VL (input) REAL VU (input) REAL If RANGE='V', the lower and upper bounds of the interval to be searched for eigenvalues. VL < VU. Not referenced if RANGE = 'A' or 'I'. IL (input) INTEGER IU (input) INTEGER If RANGE='I', the indices (in ascending order) of the smallest and largest eigenvalues to be returned. 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. Not referenced if RANGE = 'A' or 'V'. ABSTOL (input) REAL The absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to ABSTOL + EPS * max( |a|,|b| ) , where EPS is the machine precision. If ABSTOL is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix obtained by reducing AB to tridiagonal form. Eigenvalues will be computed most accurately when ABSTOL is set to twice the underflow threshold 2*SLAMCH('S'), not zero. If this routine returns with INFO>0, indicating that some eigenvectors did not converge, try setting ABSTOL to 2*SLAMCH('S'). See "Computing Small Singular Values of Bidiagonal Matrices with Guaranteed High Relative Accuracy," by Demmel and Kahan, LAPACK Working Note #3. M (output) INTEGER The total number of eigenvalues found. 0 <= M <= N. If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. W (output) REAL array, dimension (N) The first M elements contain the selected eigenvalues in ascending order. Z (output) REAL array, dimension (LDZ, max(1,M)) If JOBZ = 'V', then if INFO = 0, the first M columns of Z contain the orthonormal eigenvectors of the matrix A corresponding to the selected eigenvalues, with the i-th column of Z holding the eigenvector associated with W(i). If an eigenvector fails to converge, then that column of Z contains the latest approximation to the eigenvector, and the index of the eigenvector is returned in IFAIL. If JOBZ = 'N', then Z is not referenced. Note: the user must ensure that at least max(1,M) columns are supplied in the array Z; if RANGE = 'V', the exact value of M is not known in advance and an upper bound must be used. LDZ (input) INTEGER The leading dimension of the array Z. LDZ >= 1, and if JOBZ = 'V', LDZ >= max(1,N). WORK (workspace) REAL array, dimension (7*N) IWORK (workspace) INTEGER array, dimension (5*N) IFAIL (output) INTEGER array, dimension (N) If JOBZ = 'V', then if INFO = 0, the first M elements of IFAIL are zero. If INFO > 0, then IFAIL contains the indices of the eigenvectors that failed to converge. If JOBZ = 'N', then IFAIL is not referenced. INFO (output) INTEGER = 0: successful exit. < 0: if INFO = -i, the i-th argument had an illegal value. > 0: if INFO = i, then i eigenvectors failed to converge. Their indices are stored in array IFAIL. ===================================================================== Test the input parameters. Parameter adjustments Function Body */ /* Table of constant values */ static real c_b14 = 1.f; static integer c__1 = 1; static real c_b34 = 0.f; /* System generated locals */ integer ab_dim1, ab_offset, q_dim1, q_offset, z_dim1, z_offset, i__1, i__2; real r__1, r__2; /* Builtin functions */ double sqrt(doublereal); /* Local variables */ static integer indd, inde; static real anrm; static integer imax; static real rmin, rmax; static integer itmp1, i, j, indee; static real sigma; extern logical lsame_(char *, char *); static integer iinfo; extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *); static char order[1]; extern /* Subroutine */ int sgemv_(char *, integer *, integer *, real *, real *, integer *, real *, integer *, real *, real *, integer *); static logical lower; extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, integer *), sswap_(integer *, real *, integer *, real *, integer * ); static logical wantz; static integer jj; static logical alleig, indeig; static integer iscale, indibl; static logical valeig; extern doublereal slamch_(char *); static real safmin; extern /* Subroutine */ int xerbla_(char *, integer *); static real abstll, bignum; extern doublereal slansb_(char *, char *, integer *, integer *, real *, integer *, real *); extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *, real *, integer *, integer *, real *, integer *, integer *); static integer indisp, indiwo; extern /* Subroutine */ int slacpy_(char *, integer *, integer *, real *, integer *, real *, integer *); static integer indwrk; extern /* Subroutine */ int ssbtrd_(char *, char *, integer *, integer *, real *, integer *, real *, real *, real *, integer *, real *, integer *), sstein_(integer *, real *, real *, integer *, real *, integer *, integer *, real *, integer *, real * , integer *, integer *, integer *), ssterf_(integer *, real *, real *, integer *); static integer nsplit; static real smlnum; extern /* Subroutine */ int sstebz_(char *, char *, integer *, real *, real *, integer *, integer *, real *, real *, real *, integer *, integer *, real *, integer *, integer *, real *, integer *, integer *), ssteqr_(char *, integer *, real *, real *, real *, integer *, real *, integer *); static real eps, vll, vuu, tmp1; #define W(I) w[(I)-1] #define WORK(I) work[(I)-1] #define IWORK(I) iwork[(I)-1] #define IFAIL(I) ifail[(I)-1] #define AB(I,J) ab[(I)-1 + ((J)-1)* ( *ldab)] #define Q(I,J) q[(I)-1 + ((J)-1)* ( *ldq)] #define Z(I,J) z[(I)-1 + ((J)-1)* ( *ldz)] wantz = lsame_(jobz, "V"); alleig = lsame_(range, "A"); valeig = lsame_(range, "V"); indeig = lsame_(range, "I"); lower = lsame_(uplo, "L"); *info = 0; if (! (wantz || lsame_(jobz, "N"))) { *info = -1; } else if (! (alleig || valeig || indeig)) { *info = -2; } else if (! (lower || lsame_(uplo, "U"))) { *info = -3; } else if (*n < 0) { *info = -4; } else if (*kd < 0) { *info = -5; } else if (*ldab < *kd + 1) { *info = -7; } else if (*ldq < *n) { *info = -9; } else if (valeig && *n > 0 && *vu <= *vl) { *info = -11; } else if (indeig && *il < 1) { *info = -12; } else if (indeig && (*iu < min(*n,*il) || *iu > *n)) { *info = -13; } else if (*ldz < 1 || wantz && *ldz < *n) { *info = -18; } if (*info != 0) { i__1 = -(*info); xerbla_("SSBEVX", &i__1); return 0; } /* Quick return if possible */ *m = 0; if (*n == 0) { return 0; } if (*n == 1) { if (alleig || indeig) { *m = 1; W(1) = AB(1,1); } else { if (*vl < AB(1,1) && *vu >= AB(1,1)) { *m = 1; W(1) = AB(1,1); } } if (wantz) { Z(1,1) = 1.f; } return 0; } /* Get machine constants. */ safmin = slamch_("Safe minimum"); eps = slamch_("Precision"); smlnum = safmin / eps; bignum = 1.f / smlnum; rmin = sqrt(smlnum); /* Computing MIN */ r__1 = sqrt(bignum), r__2 = 1.f / sqrt(sqrt(safmin)); rmax = dmin(r__1,r__2); /* Scale matrix to allowable range, if necessary. */ iscale = 0; abstll = *abstol; if (valeig) { vll = *vl; vuu = *vu; } anrm = slansb_("M", uplo, n, kd, &AB(1,1), ldab, &WORK(1)); if (anrm > 0.f && anrm < rmin) { iscale = 1; sigma = rmin / anrm; } else if (anrm > rmax) { iscale = 1; sigma = rmax / anrm; } if (iscale == 1) { if (lower) { slascl_("B", kd, kd, &c_b14, &sigma, n, n, &AB(1,1), ldab, info); } else { slascl_("Q", kd, kd, &c_b14, &sigma, n, n, &AB(1,1), ldab, info); } if (*abstol > 0.f) { abstll = *abstol * sigma; } if (valeig) { vll = *vl * sigma; vuu = *vu * sigma; } } /* Call SSBTRD to reduce symmetric band matrix to tridiagonal form. */ indd = 1; inde = indd + *n; indwrk = inde + *n; ssbtrd_(jobz, uplo, n, kd, &AB(1,1), ldab, &WORK(indd), &WORK(inde), &Q(1,1), ldq, &WORK(indwrk), &iinfo); /* If all eigenvalues are desired and ABSTOL is less than or equal to zero, then call SSTERF or SSTEQR. If this fails for some eigenvalue, then try SSTEBZ. */ if ((alleig || indeig && *il == 1 && *iu == *n) && *abstol <= 0.f) { scopy_(n, &WORK(indd), &c__1, &W(1), &c__1); indee = indwrk + (*n << 1); if (! wantz) { i__1 = *n - 1; scopy_(&i__1, &WORK(inde), &c__1, &WORK(indee), &c__1); ssterf_(n, &W(1), &WORK(indee), info); } else { slacpy_("A", n, n, &Q(1,1), ldq, &Z(1,1), ldz); i__1 = *n - 1; scopy_(&i__1, &WORK(inde), &c__1, &WORK(indee), &c__1); ssteqr_(jobz, n, &W(1), &WORK(indee), &Z(1,1), ldz, &WORK( indwrk), info); if (*info == 0) { i__1 = *n; for (i = 1; i <= *n; ++i) { IFAIL(i) = 0; /* L10: */ } } } if (*info == 0) { *m = *n; goto L30; } *info = 0; } /* Otherwise, call SSTEBZ and, if eigenvectors are desired, SSTEIN. */ if (wantz) { *(unsigned char *)order = 'B'; } else { *(unsigned char *)order = 'E'; } indibl = 1; indisp = indibl + *n; indiwo = indisp + *n; sstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &WORK(indd), &WORK( inde), m, &nsplit, &W(1), &IWORK(indibl), &IWORK(indisp), &WORK( indwrk), &IWORK(indiwo), info); if (wantz) { sstein_(n, &WORK(indd), &WORK(inde), m, &W(1), &IWORK(indibl), &IWORK( indisp), &Z(1,1), ldz, &WORK(indwrk), &IWORK(indiwo), & IFAIL(1), info); /* Apply orthogonal matrix used in reduction to tridiagonal form to eigenvectors returned by SSTEIN. */ i__1 = *m; for (j = 1; j <= *m; ++j) { scopy_(n, &Z(1,j), &c__1, &WORK(1), &c__1); sgemv_("N", n, n, &c_b14, &Q(1,1), ldq, &WORK(1), &c__1, & c_b34, &Z(1,j), &c__1); /* L20: */ } } /* If matrix was scaled, then rescale eigenvalues appropriately. */ L30: if (iscale == 1) { if (*info == 0) { imax = *m; } else { imax = *info - 1; } r__1 = 1.f / sigma; sscal_(&imax, &r__1, &W(1), &c__1); } /* If eigenvalues are not in order, then sort them, along with eigenvectors. */ if (wantz) { i__1 = *m - 1; for (j = 1; j <= *m-1; ++j) { i = 0; tmp1 = W(j); i__2 = *m; for (jj = j + 1; jj <= *m; ++jj) { if (W(jj) < tmp1) { i = jj; tmp1 = W(jj); } /* L40: */ } if (i != 0) { itmp1 = IWORK(indibl + i - 1); W(i) = W(j); IWORK(indibl + i - 1) = IWORK(indibl + j - 1); W(j) = tmp1; IWORK(indibl + j - 1) = itmp1; sswap_(n, &Z(1,i), &c__1, &Z(1,j), & c__1); if (*info != 0) { itmp1 = IFAIL(i); IFAIL(i) = IFAIL(j); IFAIL(j) = itmp1; } } /* L50: */ } } return 0; /* End of SSBEVX */ } /* ssbevx_ */
/* Subroutine */ int sspevx_(char *jobz, char *range, char *uplo, integer *n, real *ap, real *vl, real *vu, integer *il, integer *iu, real *abstol, integer *m, real *w, real *z__, integer *ldz, real *work, integer * iwork, integer *ifail, integer *info, ftnlen jobz_len, ftnlen range_len, ftnlen uplo_len) { /* System generated locals */ integer z_dim1, z_offset, i__1, i__2; real r__1, r__2; /* Builtin functions */ double sqrt(doublereal); /* Local variables */ static integer i__, j, jj; static real eps, vll, vuu, tmp1; static integer indd, inde; static real anrm; static integer imax; static real rmin, rmax; static integer itmp1, indee; static real sigma; extern logical lsame_(char *, char *, ftnlen, ftnlen); static integer iinfo; extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *); static char order[1]; extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, integer *), sswap_(integer *, real *, integer *, real *, integer * ); static logical wantz, alleig, indeig; static integer iscale, indibl; static logical valeig; extern doublereal slamch_(char *, ftnlen); static real safmin; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); static real abstll, bignum; static integer indtau, indisp, indiwo, indwrk; extern doublereal slansp_(char *, char *, integer *, real *, real *, ftnlen, ftnlen); extern /* Subroutine */ int sstein_(integer *, real *, real *, integer *, real *, integer *, integer *, real *, integer *, real *, integer * , integer *, integer *), ssterf_(integer *, real *, real *, integer *); static integer nsplit; extern /* Subroutine */ int sstebz_(char *, char *, integer *, real *, real *, integer *, integer *, real *, real *, real *, integer *, integer *, real *, integer *, integer *, real *, integer *, integer *, ftnlen, ftnlen); static real smlnum; extern /* Subroutine */ int sopgtr_(char *, integer *, real *, real *, real *, integer *, real *, integer *, ftnlen), ssptrd_(char *, integer *, real *, real *, real *, real *, integer *, ftnlen), ssteqr_(char *, integer *, real *, real *, real *, integer *, real *, integer *, ftnlen), sopmtr_(char *, char *, char *, integer *, integer *, real *, real *, real *, integer *, real *, integer *, ftnlen, ftnlen, ftnlen); /* -- LAPACK driver routine (version 3.0) -- */ /* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */ /* Courant Institute, Argonne National Lab, and Rice University */ /* June 30, 1999 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* SSPEVX computes selected eigenvalues and, optionally, eigenvectors */ /* of a real symmetric matrix A in packed storage. Eigenvalues/vectors */ /* can be selected by specifying either a range of values or a range of */ /* indices for the desired eigenvalues. */ /* Arguments */ /* ========= */ /* JOBZ (input) CHARACTER*1 */ /* = 'N': Compute eigenvalues only; */ /* = 'V': Compute eigenvalues and eigenvectors. */ /* RANGE (input) CHARACTER*1 */ /* = 'A': all eigenvalues will be found; */ /* = 'V': all eigenvalues in the half-open interval (VL,VU] */ /* will be found; */ /* = 'I': the IL-th through IU-th eigenvalues will be found. */ /* UPLO (input) CHARACTER*1 */ /* = 'U': Upper triangle of A is stored; */ /* = 'L': Lower triangle of A is stored. */ /* N (input) INTEGER */ /* The order of the matrix A. N >= 0. */ /* AP (input/output) REAL array, dimension (N*(N+1)/2) */ /* On entry, the upper or lower triangle of the symmetric matrix */ /* A, packed columnwise in a linear array. The j-th column of A */ /* is stored in the array AP as follows: */ /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ /* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ /* On exit, AP is overwritten by values generated during the */ /* reduction to tridiagonal form. If UPLO = 'U', the diagonal */ /* and first superdiagonal of the tridiagonal matrix T overwrite */ /* the corresponding elements of A, and if UPLO = 'L', the */ /* diagonal and first subdiagonal of T overwrite the */ /* corresponding elements of A. */ /* VL (input) REAL */ /* VU (input) REAL */ /* If RANGE='V', the lower and upper bounds of the interval to */ /* be searched for eigenvalues. VL < VU. */ /* Not referenced if RANGE = 'A' or 'I'. */ /* IL (input) INTEGER */ /* IU (input) INTEGER */ /* If RANGE='I', the indices (in ascending order) of the */ /* smallest and largest eigenvalues to be returned. */ /* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */ /* Not referenced if RANGE = 'A' or 'V'. */ /* ABSTOL (input) REAL */ /* The absolute error tolerance for the eigenvalues. */ /* An approximate eigenvalue is accepted as converged */ /* when it is determined to lie in an interval [a,b] */ /* of width less than or equal to */ /* ABSTOL + EPS * max( |a|,|b| ) , */ /* where EPS is the machine precision. If ABSTOL is less than */ /* or equal to zero, then EPS*|T| will be used in its place, */ /* where |T| is the 1-norm of the tridiagonal matrix obtained */ /* by reducing AP to tridiagonal form. */ /* Eigenvalues will be computed most accurately when ABSTOL is */ /* set to twice the underflow threshold 2*SLAMCH('S'), not zero. */ /* If this routine returns with INFO>0, indicating that some */ /* eigenvectors did not converge, try setting ABSTOL to */ /* 2*SLAMCH('S'). */ /* See "Computing Small Singular Values of Bidiagonal Matrices */ /* with Guaranteed High Relative Accuracy," by Demmel and */ /* Kahan, LAPACK Working Note #3. */ /* M (output) INTEGER */ /* The total number of eigenvalues found. 0 <= M <= N. */ /* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ /* W (output) REAL array, dimension (N) */ /* If INFO = 0, the selected eigenvalues in ascending order. */ /* Z (output) REAL array, dimension (LDZ, max(1,M)) */ /* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */ /* contain the orthonormal eigenvectors of the matrix A */ /* corresponding to the selected eigenvalues, with the i-th */ /* column of Z holding the eigenvector associated with W(i). */ /* If an eigenvector fails to converge, then that column of Z */ /* contains the latest approximation to the eigenvector, and the */ /* index of the eigenvector is returned in IFAIL. */ /* If JOBZ = 'N', then Z is not referenced. */ /* Note: the user must ensure that at least max(1,M) columns are */ /* supplied in the array Z; if RANGE = 'V', the exact value of M */ /* is not known in advance and an upper bound must be used. */ /* LDZ (input) INTEGER */ /* The leading dimension of the array Z. LDZ >= 1, and if */ /* JOBZ = 'V', LDZ >= max(1,N). */ /* WORK (workspace) REAL array, dimension (8*N) */ /* IWORK (workspace) INTEGER array, dimension (5*N) */ /* IFAIL (output) INTEGER array, dimension (N) */ /* If JOBZ = 'V', then if INFO = 0, the first M elements of */ /* IFAIL are zero. If INFO > 0, then IFAIL contains the */ /* indices of the eigenvectors that failed to converge. */ /* If JOBZ = 'N', then IFAIL is not referenced. */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value */ /* > 0: if INFO = i, then i eigenvectors failed to converge. */ /* Their indices are stored in array IFAIL. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input parameters. */ /* Parameter adjustments */ --ap; --w; z_dim1 = *ldz; z_offset = 1 + z_dim1; z__ -= z_offset; --work; --iwork; --ifail; /* Function Body */ wantz = lsame_(jobz, "V", (ftnlen)1, (ftnlen)1); alleig = lsame_(range, "A", (ftnlen)1, (ftnlen)1); valeig = lsame_(range, "V", (ftnlen)1, (ftnlen)1); indeig = lsame_(range, "I", (ftnlen)1, (ftnlen)1); *info = 0; if (! (wantz || lsame_(jobz, "N", (ftnlen)1, (ftnlen)1))) { *info = -1; } else if (! (alleig || valeig || indeig)) { *info = -2; } else if (! (lsame_(uplo, "L", (ftnlen)1, (ftnlen)1) || lsame_(uplo, "U", (ftnlen)1, (ftnlen)1))) { *info = -3; } else if (*n < 0) { *info = -4; } else { if (valeig) { if (*n > 0 && *vu <= *vl) { *info = -7; } } else if (indeig) { if (*il < 1 || *il > max(1,*n)) { *info = -8; } else if (*iu < min(*n,*il) || *iu > *n) { *info = -9; } } } if (*info == 0) { if (*ldz < 1 || wantz && *ldz < *n) { *info = -14; } } if (*info != 0) { i__1 = -(*info); xerbla_("SSPEVX", &i__1, (ftnlen)6); return 0; } /* Quick return if possible */ *m = 0; if (*n == 0) { return 0; } if (*n == 1) { if (alleig || indeig) { *m = 1; w[1] = ap[1]; } else { if (*vl < ap[1] && *vu >= ap[1]) { *m = 1; w[1] = ap[1]; } } if (wantz) { z__[z_dim1 + 1] = 1.f; } return 0; } /* Get machine constants. */ safmin = slamch_("Safe minimum", (ftnlen)12); eps = slamch_("Precision", (ftnlen)9); smlnum = safmin / eps; bignum = 1.f / smlnum; rmin = sqrt(smlnum); /* Computing MIN */ r__1 = sqrt(bignum), r__2 = 1.f / sqrt(sqrt(safmin)); rmax = dmin(r__1,r__2); /* Scale matrix to allowable range, if necessary. */ iscale = 0; abstll = *abstol; if (valeig) { vll = *vl; vuu = *vu; } else { vll = 0.f; vuu = 0.f; } anrm = slansp_("M", uplo, n, &ap[1], &work[1], (ftnlen)1, (ftnlen)1); if (anrm > 0.f && anrm < rmin) { iscale = 1; sigma = rmin / anrm; } else if (anrm > rmax) { iscale = 1; sigma = rmax / anrm; } if (iscale == 1) { i__1 = *n * (*n + 1) / 2; sscal_(&i__1, &sigma, &ap[1], &c__1); if (*abstol > 0.f) { abstll = *abstol * sigma; } if (valeig) { vll = *vl * sigma; vuu = *vu * sigma; } } /* Call SSPTRD to reduce symmetric packed matrix to tridiagonal form. */ indtau = 1; inde = indtau + *n; indd = inde + *n; indwrk = indd + *n; ssptrd_(uplo, n, &ap[1], &work[indd], &work[inde], &work[indtau], &iinfo, (ftnlen)1); /* If all eigenvalues are desired and ABSTOL is less than or equal */ /* to zero, then call SSTERF or SOPGTR and SSTEQR. If this fails */ /* for some eigenvalue, then try SSTEBZ. */ if ((alleig || indeig && *il == 1 && *iu == *n) && *abstol <= 0.f) { scopy_(n, &work[indd], &c__1, &w[1], &c__1); indee = indwrk + (*n << 1); if (! wantz) { i__1 = *n - 1; scopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1); ssterf_(n, &w[1], &work[indee], info); } else { sopgtr_(uplo, n, &ap[1], &work[indtau], &z__[z_offset], ldz, & work[indwrk], &iinfo, (ftnlen)1); i__1 = *n - 1; scopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1); ssteqr_(jobz, n, &w[1], &work[indee], &z__[z_offset], ldz, &work[ indwrk], info, (ftnlen)1); if (*info == 0) { i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { ifail[i__] = 0; /* L10: */ } } } if (*info == 0) { *m = *n; goto L20; } *info = 0; } /* Otherwise, call SSTEBZ and, if eigenvectors are desired, SSTEIN. */ if (wantz) { *(unsigned char *)order = 'B'; } else { *(unsigned char *)order = 'E'; } indibl = 1; indisp = indibl + *n; indiwo = indisp + *n; sstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &work[indd], &work[ inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[ indwrk], &iwork[indiwo], info, (ftnlen)1, (ftnlen)1); if (wantz) { sstein_(n, &work[indd], &work[inde], m, &w[1], &iwork[indibl], &iwork[ indisp], &z__[z_offset], ldz, &work[indwrk], &iwork[indiwo], & ifail[1], info); /* Apply orthogonal matrix used in reduction to tridiagonal */ /* form to eigenvectors returned by SSTEIN. */ sopmtr_("L", uplo, "N", n, m, &ap[1], &work[indtau], &z__[z_offset], ldz, &work[indwrk], info, (ftnlen)1, (ftnlen)1, (ftnlen)1); } /* If matrix was scaled, then rescale eigenvalues appropriately. */ L20: if (iscale == 1) { if (*info == 0) { imax = *m; } else { imax = *info - 1; } r__1 = 1.f / sigma; sscal_(&imax, &r__1, &w[1], &c__1); } /* If eigenvalues are not in order, then sort them, along with */ /* eigenvectors. */ if (wantz) { i__1 = *m - 1; for (j = 1; j <= i__1; ++j) { i__ = 0; tmp1 = w[j]; i__2 = *m; for (jj = j + 1; jj <= i__2; ++jj) { if (w[jj] < tmp1) { i__ = jj; tmp1 = w[jj]; } /* L30: */ } if (i__ != 0) { itmp1 = iwork[indibl + i__ - 1]; w[i__] = w[j]; iwork[indibl + i__ - 1] = iwork[indibl + j - 1]; w[j] = tmp1; iwork[indibl + j - 1] = itmp1; sswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], &c__1); if (*info != 0) { itmp1 = ifail[i__]; ifail[i__] = ifail[j]; ifail[j] = itmp1; } } /* L40: */ } } return 0; /* End of SSPEVX */ } /* sspevx_ */
/* Subroutine */ int sstevx_(char *jobz, char *range, integer *n, real *d, real *e, real *vl, real *vu, integer *il, integer *iu, real *abstol, integer *m, real *w, real *z, integer *ldz, real *work, integer * iwork, integer *ifail, integer *info) { /* -- LAPACK driver routine (version 2.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University September 30, 1994 Purpose ======= SSTEVX computes selected eigenvalues and, optionally, eigenvectors of a real symmetric tridiagonal matrix A. Eigenvalues and eigenvectors can be selected by specifying either a range of values or a range of indices for the desired eigenvalues. Arguments ========= JOBZ (input) CHARACTER*1 = 'N': Compute eigenvalues only; = 'V': Compute eigenvalues and eigenvectors. RANGE (input) CHARACTER*1 = 'A': all eigenvalues will be found. = 'V': all eigenvalues in the half-open interval (VL,VU] will be found. = 'I': the IL-th through IU-th eigenvalues will be found. N (input) INTEGER The order of the matrix. N >= 0. D (input/output) REAL array, dimension (N) On entry, the n diagonal elements of the tridiagonal matrix A. On exit, D may be multiplied by a constant factor chosen to avoid over/underflow in computing the eigenvalues. E (input/output) REAL array, dimension (N) On entry, the (n-1) subdiagonal elements of the tridiagonal matrix A in elements 1 to N-1 of E; E(N) need not be set. On exit, E may be multiplied by a constant factor chosen to avoid over/underflow in computing the eigenvalues. VL (input) REAL VU (input) REAL If RANGE='V', the lower and upper bounds of the interval to be searched for eigenvalues. VL < VU. Not referenced if RANGE = 'A' or 'I'. IL (input) INTEGER IU (input) INTEGER If RANGE='I', the indices (in ascending order) of the smallest and largest eigenvalues to be returned. 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. Not referenced if RANGE = 'A' or 'V'. ABSTOL (input) REAL The absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to ABSTOL + EPS * max( |a|,|b| ) , where EPS is the machine precision. If ABSTOL is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix. Eigenvalues will be computed most accurately when ABSTOL is set to twice the underflow threshold 2*SLAMCH('S'), not zero. If this routine returns with INFO>0, indicating that some eigenvectors did not converge, try setting ABSTOL to 2*SLAMCH('S'). See "Computing Small Singular Values of Bidiagonal Matrices with Guaranteed High Relative Accuracy," by Demmel and Kahan, LAPACK Working Note #3. M (output) INTEGER The total number of eigenvalues found. 0 <= M <= N. If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. W (output) REAL array, dimension (N) The first M elements contain the selected eigenvalues in ascending order. Z (output) REAL array, dimension (LDZ, max(1,M) ) If JOBZ = 'V', then if INFO = 0, the first M columns of Z contain the orthonormal eigenvectors of the matrix A corresponding to the selected eigenvalues, with the i-th column of Z holding the eigenvector associated with W(i). If an eigenvector fails to converge (INFO > 0), then that column of Z contains the latest approximation to the eigenvector, and the index of the eigenvector is returned in IFAIL. If JOBZ = 'N', then Z is not referenced. Note: the user must ensure that at least max(1,M) columns are supplied in the array Z; if RANGE = 'V', the exact value of M is not known in advance and an upper bound must be used. LDZ (input) INTEGER The leading dimension of the array Z. LDZ >= 1, and if JOBZ = 'V', LDZ >= max(1,N). WORK (workspace) REAL array, dimension (5*N) IWORK (workspace) INTEGER array, dimension (5*N) IFAIL (output) INTEGER array, dimension (N) If JOBZ = 'V', then if INFO = 0, the first M elements of IFAIL are zero. If INFO > 0, then IFAIL contains the indices of the eigenvectors that failed to converge. If JOBZ = 'N', then IFAIL is not referenced. INFO (output) INTEGER = 0: successful exit < 0: if INFO = -i, the i-th argument had an illegal value > 0: if INFO = i, then i eigenvectors failed to converge. Their indices are stored in array IFAIL. ===================================================================== Test the input parameters. Parameter adjustments Function Body */ /* Table of constant values */ static integer c__1 = 1; /* System generated locals */ integer z_dim1, z_offset, i__1, i__2; real r__1, r__2; /* Builtin functions */ double sqrt(doublereal); /* Local variables */ static integer imax; static real rmin, rmax, tnrm; static integer itmp1, i, j; static real sigma; extern logical lsame_(char *, char *); extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *); static char order[1]; extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, integer *), sswap_(integer *, real *, integer *, real *, integer * ); static logical wantz; static integer jj; static logical alleig, indeig; static integer iscale, indibl; static logical valeig; extern doublereal slamch_(char *); static real safmin; extern /* Subroutine */ int xerbla_(char *, integer *); static real bignum; static integer indisp, indiwo, indwrk; extern doublereal slanst_(char *, integer *, real *, real *); extern /* Subroutine */ int sstein_(integer *, real *, real *, integer *, real *, integer *, integer *, real *, integer *, real *, integer * , integer *, integer *), ssterf_(integer *, real *, real *, integer *); static integer nsplit; extern /* Subroutine */ int sstebz_(char *, char *, integer *, real *, real *, integer *, integer *, real *, real *, real *, integer *, integer *, real *, integer *, integer *, real *, integer *, integer *); static real smlnum; extern /* Subroutine */ int ssteqr_(char *, integer *, real *, real *, real *, integer *, real *, integer *); static real eps, vll, vuu, tmp1; #define D(I) d[(I)-1] #define E(I) e[(I)-1] #define W(I) w[(I)-1] #define WORK(I) work[(I)-1] #define IWORK(I) iwork[(I)-1] #define IFAIL(I) ifail[(I)-1] #define Z(I,J) z[(I)-1 + ((J)-1)* ( *ldz)] wantz = lsame_(jobz, "V"); alleig = lsame_(range, "A"); valeig = lsame_(range, "V"); indeig = lsame_(range, "I"); *info = 0; if (! (wantz || lsame_(jobz, "N"))) { *info = -1; } else if (! (alleig || valeig || indeig)) { *info = -2; } else if (*n < 0) { *info = -3; } else if (valeig && *n > 0 && *vu <= *vl) { *info = -7; } else if (indeig && *il < 1) { *info = -8; } else if (indeig && (*iu < min(*n,*il) || *iu > *n)) { *info = -9; } else if (*ldz < 1 || wantz && *ldz < *n) { *info = -14; } if (*info != 0) { i__1 = -(*info); xerbla_("SSTEVX", &i__1); return 0; } /* Quick return if possible */ *m = 0; if (*n == 0) { return 0; } if (*n == 1) { if (alleig || indeig) { *m = 1; W(1) = D(1); } else { if (*vl < D(1) && *vu >= D(1)) { *m = 1; W(1) = D(1); } } if (wantz) { Z(1,1) = 1.f; } return 0; } /* Get machine constants. */ safmin = slamch_("Safe minimum"); eps = slamch_("Precision"); smlnum = safmin / eps; bignum = 1.f / smlnum; rmin = sqrt(smlnum); /* Computing MIN */ r__1 = sqrt(bignum), r__2 = 1.f / sqrt(sqrt(safmin)); rmax = dmin(r__1,r__2); /* Scale matrix to allowable range, if necessary. */ iscale = 0; if (valeig) { vll = *vl; vuu = *vu; } tnrm = slanst_("M", n, &D(1), &E(1)); if (tnrm > 0.f && tnrm < rmin) { iscale = 1; sigma = rmin / tnrm; } else if (tnrm > rmax) { iscale = 1; sigma = rmax / tnrm; } if (iscale == 1) { sscal_(n, &sigma, &D(1), &c__1); i__1 = *n - 1; sscal_(&i__1, &sigma, &E(1), &c__1); if (valeig) { vll = *vl * sigma; vuu = *vu * sigma; } } /* If all eigenvalues are desired and ABSTOL is less than zero, then call SSTERF or SSTEQR. If this fails for some eigenvalue, then try SSTEBZ. */ if ((alleig || indeig && *il == 1 && *iu == *n) && *abstol <= 0.f) { scopy_(n, &D(1), &c__1, &W(1), &c__1); i__1 = *n - 1; scopy_(&i__1, &E(1), &c__1, &WORK(1), &c__1); indwrk = *n + 1; if (! wantz) { ssterf_(n, &W(1), &WORK(1), info); } else { ssteqr_("I", n, &W(1), &WORK(1), &Z(1,1), ldz, &WORK(indwrk), info); if (*info == 0) { i__1 = *n; for (i = 1; i <= *n; ++i) { IFAIL(i) = 0; /* L10: */ } } } if (*info == 0) { *m = *n; goto L20; } *info = 0; } /* Otherwise, call SSTEBZ and, if eigenvectors are desired, SSTEIN. */ if (wantz) { *(unsigned char *)order = 'B'; } else { *(unsigned char *)order = 'E'; } indwrk = 1; indibl = 1; indisp = indibl + *n; indiwo = indisp + *n; sstebz_(range, order, n, &vll, &vuu, il, iu, abstol, &D(1), &E(1), m, & nsplit, &W(1), &IWORK(indibl), &IWORK(indisp), &WORK(indwrk), & IWORK(indiwo), info); if (wantz) { sstein_(n, &D(1), &E(1), m, &W(1), &IWORK(indibl), &IWORK(indisp), &Z(1,1), ldz, &WORK(indwrk), &IWORK(indiwo), &IFAIL(1), info); } /* If matrix was scaled, then rescale eigenvalues appropriately. */ L20: if (iscale == 1) { if (*info == 0) { imax = *m; } else { imax = *info - 1; } r__1 = 1.f / sigma; sscal_(&imax, &r__1, &W(1), &c__1); } /* If eigenvalues are not in order, then sort them, along with eigenvectors. */ if (wantz) { i__1 = *m - 1; for (j = 1; j <= *m-1; ++j) { i = 0; tmp1 = W(j); i__2 = *m; for (jj = j + 1; jj <= *m; ++jj) { if (W(jj) < tmp1) { i = jj; tmp1 = W(jj); } /* L30: */ } if (i != 0) { itmp1 = IWORK(indibl + i - 1); W(i) = W(j); IWORK(indibl + i - 1) = IWORK(indibl + j - 1); W(j) = tmp1; IWORK(indibl + j - 1) = itmp1; sswap_(n, &Z(1,i), &c__1, &Z(1,j), & c__1); if (*info != 0) { itmp1 = IFAIL(i); IFAIL(i) = IFAIL(j); IFAIL(j) = itmp1; } } /* L40: */ } } return 0; /* End of SSTEVX */ } /* sstevx_ */