14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
22 typedef BLASLONG blasint;
24 #define blasabs(x) llabs(x)
26 #define blasabs(x) labs(x)
30 #define blasabs(x) abs(x)
33 typedef blasint integer;
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
63 /* Extern is for use with -E */
74 /*external read, write*/
83 /*internal read, write*/
113 /*rewind, backspace, endfile*/
125 ftnint *inex; /*parameters in standard's order*/
151 union Multitype { /* for multiple entry points */
162 typedef union Multitype Multitype;
164 struct Vardesc { /* for Namelist */
170 typedef struct Vardesc Vardesc;
177 typedef struct Namelist Namelist;
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b) ((a) >> (b) & 1)
186 #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
261 /* procedure parameter types for -A and -C++ */
263 #define F2C_proc_par_types 1
265 typedef logical (*L_fp)(...);
267 typedef logical (*L_fp)();
270 static float spow_ui(float x, integer n) {
271 float pow=1.0; unsigned long int u;
273 if(n < 0) n = -n, x = 1/x;
282 static double dpow_ui(double x, integer n) {
283 double pow=1.0; unsigned long int u;
285 if(n < 0) n = -n, x = 1/x;
295 static _Fcomplex cpow_ui(complex x, integer n) {
296 complex pow={1.0,0.0}; unsigned long int u;
298 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
300 if(u & 01) pow.r *= x.r, pow.i *= x.i;
301 if(u >>= 1) x.r *= x.r, x.i *= x.i;
305 _Fcomplex p={pow.r, pow.i};
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310 _Complex float pow=1.0; unsigned long int u;
312 if(n < 0) n = -n, x = 1/x;
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324 _Dcomplex pow={1.0,0.0}; unsigned long int u;
326 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
328 if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329 if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
333 _Dcomplex p = {pow._Val[0], pow._Val[1]};
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338 _Complex double pow=1.0; unsigned long int u;
340 if(n < 0) n = -n, x = 1/x;
350 static integer pow_ii(integer x, integer n) {
351 integer pow; unsigned long int u;
353 if (n == 0 || x == 1) pow = 1;
354 else if (x != -1) pow = x == 0 ? 1/x : 0;
357 if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
369 double m; integer i, mi;
370 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371 if (w[i-1]>m) mi=i ,m=w[i-1];
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
376 float m; integer i, mi;
377 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378 if (w[i-1]>m) mi=i ,m=w[i-1];
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382 integer n = *n_, incx = *incx_, incy = *incy_, i;
384 _Fcomplex zdotc = {0.0, 0.0};
385 if (incx == 1 && incy == 1) {
386 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387 zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388 zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
391 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392 zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393 zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
399 _Complex float zdotc = 0.0;
400 if (incx == 1 && incy == 1) {
401 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402 zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
405 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406 zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413 integer n = *n_, incx = *incx_, incy = *incy_, i;
415 _Dcomplex zdotc = {0.0, 0.0};
416 if (incx == 1 && incy == 1) {
417 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418 zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419 zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
422 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423 zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424 zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
430 _Complex double zdotc = 0.0;
431 if (incx == 1 && incy == 1) {
432 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433 zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
436 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437 zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444 integer n = *n_, incx = *incx_, incy = *incy_, i;
446 _Fcomplex zdotc = {0.0, 0.0};
447 if (incx == 1 && incy == 1) {
448 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449 zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450 zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
453 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454 zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455 zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
461 _Complex float zdotc = 0.0;
462 if (incx == 1 && incy == 1) {
463 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464 zdotc += Cf(&x[i]) * Cf(&y[i]);
467 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468 zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475 integer n = *n_, incx = *incx_, incy = *incy_, i;
477 _Dcomplex zdotc = {0.0, 0.0};
478 if (incx == 1 && incy == 1) {
479 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480 zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481 zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
484 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485 zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486 zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
492 _Complex double zdotc = 0.0;
493 if (incx == 1 && incy == 1) {
494 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495 zdotc += Cd(&x[i]) * Cd(&y[i]);
498 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499 zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
505 /* -- translated by f2c (version 20000121).
506 You must link the resulting object file with the libraries:
507 -lf2c -lm (in that order)
513 /* Table of constant values */
515 static integer c__1 = 1;
516 static real c_b18 = .003f;
518 /* > \brief \b SSTEMR */
520 /* =========== DOCUMENTATION =========== */
522 /* Online html documentation available at */
523 /* http://www.netlib.org/lapack/explore-html/ */
526 /* > Download SSTEMR + dependencies */
527 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sstemr.
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sstemr.
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sstemr.
541 /* SUBROUTINE SSTEMR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU, */
542 /* M, W, Z, LDZ, NZC, ISUPPZ, TRYRAC, WORK, LWORK, */
543 /* IWORK, LIWORK, INFO ) */
545 /* CHARACTER JOBZ, RANGE */
547 /* INTEGER IL, INFO, IU, LDZ, NZC, LIWORK, LWORK, M, N */
549 /* INTEGER ISUPPZ( * ), IWORK( * ) */
550 /* REAL D( * ), E( * ), W( * ), WORK( * ) */
551 /* REAL Z( LDZ, * ) */
554 /* > \par Purpose: */
559 /* > SSTEMR computes selected eigenvalues and, optionally, eigenvectors */
560 /* > of a real symmetric tridiagonal matrix T. Any such unreduced matrix has */
561 /* > a well defined set of pairwise different real eigenvalues, the corresponding */
562 /* > real eigenvectors are pairwise orthogonal. */
564 /* > The spectrum may be computed either completely or partially by specifying */
565 /* > either an interval (VL,VU] or a range of indices IL:IU for the desired */
568 /* > Depending on the number of desired eigenvalues, these are computed either */
569 /* > by bisection or the dqds algorithm. Numerically orthogonal eigenvectors are */
570 /* > computed by the use of various suitable L D L^T factorizations near clusters */
571 /* > of close eigenvalues (referred to as RRRs, Relatively Robust */
572 /* > Representations). An informal sketch of the algorithm follows. */
574 /* > For each unreduced block (submatrix) of T, */
575 /* > (a) Compute T - sigma I = L D L^T, so that L and D */
576 /* > define all the wanted eigenvalues to high relative accuracy. */
577 /* > This means that small relative changes in the entries of D and L */
578 /* > cause only small relative changes in the eigenvalues and */
579 /* > eigenvectors. The standard (unfactored) representation of the */
580 /* > tridiagonal matrix T does not have this property in general. */
581 /* > (b) Compute the eigenvalues to suitable accuracy. */
582 /* > If the eigenvectors are desired, the algorithm attains full */
583 /* > accuracy of the computed eigenvalues only right before */
584 /* > the corresponding vectors have to be computed, see steps c) and d). */
585 /* > (c) For each cluster of close eigenvalues, select a new */
586 /* > shift close to the cluster, find a new factorization, and refine */
587 /* > the shifted eigenvalues to suitable accuracy. */
588 /* > (d) For each eigenvalue with a large enough relative separation compute */
589 /* > the corresponding eigenvector by forming a rank revealing twisted */
590 /* > factorization. Go back to (c) for any clusters that remain. */
592 /* > For more details, see: */
593 /* > - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
594 /* > to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
595 /* > Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
596 /* > - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
597 /* > Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
598 /* > 2004. Also LAPACK Working Note 154. */
599 /* > - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
600 /* > tridiagonal eigenvalue/eigenvector problem", */
601 /* > Computer Science Division Technical Report No. UCB/CSD-97-971, */
602 /* > UC Berkeley, May 1997. */
604 /* > Further Details */
605 /* > 1.SSTEMR works only on machines which follow IEEE-754 */
606 /* > floating-point standard in their handling of infinities and NaNs. */
607 /* > This permits the use of efficient inner loops avoiding a check for */
608 /* > zero divisors. */
614 /* > \param[in] JOBZ */
616 /* > JOBZ is CHARACTER*1 */
617 /* > = 'N': Compute eigenvalues only; */
618 /* > = 'V': Compute eigenvalues and eigenvectors. */
621 /* > \param[in] RANGE */
623 /* > RANGE is CHARACTER*1 */
624 /* > = 'A': all eigenvalues will be found. */
625 /* > = 'V': all eigenvalues in the half-open interval (VL,VU] */
626 /* > will be found. */
627 /* > = 'I': the IL-th through IU-th eigenvalues will be found. */
633 /* > The order of the matrix. N >= 0. */
636 /* > \param[in,out] D */
638 /* > D is REAL array, dimension (N) */
639 /* > On entry, the N diagonal elements of the tridiagonal matrix */
640 /* > T. On exit, D is overwritten. */
643 /* > \param[in,out] E */
645 /* > E is REAL array, dimension (N) */
646 /* > On entry, the (N-1) subdiagonal elements of the tridiagonal */
647 /* > matrix T in elements 1 to N-1 of E. E(N) need not be set on */
648 /* > input, but is used internally as workspace. */
649 /* > On exit, E is overwritten. */
652 /* > \param[in] VL */
656 /* > If RANGE='V', the lower bound of the interval to */
657 /* > be searched for eigenvalues. VL < VU. */
658 /* > Not referenced if RANGE = 'A' or 'I'. */
661 /* > \param[in] VU */
665 /* > If RANGE='V', the upper bound of the interval to */
666 /* > be searched for eigenvalues. VL < VU. */
667 /* > Not referenced if RANGE = 'A' or 'I'. */
670 /* > \param[in] IL */
672 /* > IL is INTEGER */
674 /* > If RANGE='I', the index of the */
675 /* > smallest eigenvalue to be returned. */
676 /* > 1 <= IL <= IU <= N, if N > 0. */
677 /* > Not referenced if RANGE = 'A' or 'V'. */
680 /* > \param[in] IU */
682 /* > IU is INTEGER */
684 /* > If RANGE='I', the index of the */
685 /* > largest eigenvalue to be returned. */
686 /* > 1 <= IL <= IU <= N, if N > 0. */
687 /* > Not referenced if RANGE = 'A' or 'V'. */
690 /* > \param[out] M */
693 /* > The total number of eigenvalues found. 0 <= M <= N. */
694 /* > If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
697 /* > \param[out] W */
699 /* > W is REAL array, dimension (N) */
700 /* > The first M elements contain the selected eigenvalues in */
701 /* > ascending order. */
704 /* > \param[out] Z */
706 /* > Z is REAL array, dimension (LDZ, f2cmax(1,M) ) */
707 /* > If JOBZ = 'V', and if INFO = 0, then the first M columns of Z */
708 /* > contain the orthonormal eigenvectors of the matrix T */
709 /* > corresponding to the selected eigenvalues, with the i-th */
710 /* > column of Z holding the eigenvector associated with W(i). */
711 /* > If JOBZ = 'N', then Z is not referenced. */
712 /* > Note: the user must ensure that at least f2cmax(1,M) columns are */
713 /* > supplied in the array Z; if RANGE = 'V', the exact value of M */
714 /* > is not known in advance and can be computed with a workspace */
715 /* > query by setting NZC = -1, see below. */
718 /* > \param[in] LDZ */
720 /* > LDZ is INTEGER */
721 /* > The leading dimension of the array Z. LDZ >= 1, and if */
722 /* > JOBZ = 'V', then LDZ >= f2cmax(1,N). */
725 /* > \param[in] NZC */
727 /* > NZC is INTEGER */
728 /* > The number of eigenvectors to be held in the array Z. */
729 /* > If RANGE = 'A', then NZC >= f2cmax(1,N). */
730 /* > If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU]. */
731 /* > If RANGE = 'I', then NZC >= IU-IL+1. */
732 /* > If NZC = -1, then a workspace query is assumed; the */
733 /* > routine calculates the number of columns of the array Z that */
734 /* > are needed to hold the eigenvectors. */
735 /* > This value is returned as the first entry of the Z array, and */
736 /* > no error message related to NZC is issued by XERBLA. */
739 /* > \param[out] ISUPPZ */
741 /* > ISUPPZ is INTEGER array, dimension ( 2*f2cmax(1,M) ) */
742 /* > The support of the eigenvectors in Z, i.e., the indices */
743 /* > indicating the nonzero elements in Z. The i-th computed eigenvector */
744 /* > is nonzero only in elements ISUPPZ( 2*i-1 ) through */
745 /* > ISUPPZ( 2*i ). This is relevant in the case when the matrix */
746 /* > is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0. */
749 /* > \param[in,out] TRYRAC */
751 /* > TRYRAC is LOGICAL */
752 /* > If TRYRAC = .TRUE., indicates that the code should check whether */
753 /* > the tridiagonal matrix defines its eigenvalues to high relative */
754 /* > accuracy. If so, the code uses relative-accuracy preserving */
755 /* > algorithms that might be (a bit) slower depending on the matrix. */
756 /* > If the matrix does not define its eigenvalues to high relative */
757 /* > accuracy, the code can uses possibly faster algorithms. */
758 /* > If TRYRAC = .FALSE., the code is not required to guarantee */
759 /* > relatively accurate eigenvalues and can use the fastest possible */
761 /* > On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix */
762 /* > does not define its eigenvalues to high relative accuracy. */
765 /* > \param[out] WORK */
767 /* > WORK is REAL array, dimension (LWORK) */
768 /* > On exit, if INFO = 0, WORK(1) returns the optimal */
769 /* > (and minimal) LWORK. */
772 /* > \param[in] LWORK */
774 /* > LWORK is INTEGER */
775 /* > The dimension of the array WORK. LWORK >= f2cmax(1,18*N) */
776 /* > if JOBZ = 'V', and LWORK >= f2cmax(1,12*N) if JOBZ = 'N'. */
777 /* > If LWORK = -1, then a workspace query is assumed; the routine */
778 /* > only calculates the optimal size of the WORK array, returns */
779 /* > this value as the first entry of the WORK array, and no error */
780 /* > message related to LWORK is issued by XERBLA. */
783 /* > \param[out] IWORK */
785 /* > IWORK is INTEGER array, dimension (LIWORK) */
786 /* > On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
789 /* > \param[in] LIWORK */
791 /* > LIWORK is INTEGER */
792 /* > The dimension of the array IWORK. LIWORK >= f2cmax(1,10*N) */
793 /* > if the eigenvectors are desired, and LIWORK >= f2cmax(1,8*N) */
794 /* > if only the eigenvalues are to be computed. */
795 /* > If LIWORK = -1, then a workspace query is assumed; the */
796 /* > routine only calculates the optimal size of the IWORK array, */
797 /* > returns this value as the first entry of the IWORK array, and */
798 /* > no error message related to LIWORK is issued by XERBLA. */
801 /* > \param[out] INFO */
803 /* > INFO is INTEGER */
804 /* > On exit, INFO */
805 /* > = 0: successful exit */
806 /* > < 0: if INFO = -i, the i-th argument had an illegal value */
807 /* > > 0: if INFO = 1X, internal error in SLARRE, */
808 /* > if INFO = 2X, internal error in SLARRV. */
809 /* > Here, the digit X = ABS( IINFO ) < 10, where IINFO is */
810 /* > the nonzero error code returned by SLARRE or */
811 /* > SLARRV, respectively. */
817 /* > \author Univ. of Tennessee */
818 /* > \author Univ. of California Berkeley */
819 /* > \author Univ. of Colorado Denver */
820 /* > \author NAG Ltd. */
822 /* > \date June 2016 */
824 /* > \ingroup realOTHERcomputational */
826 /* > \par Contributors: */
827 /* ================== */
829 /* > Beresford Parlett, University of California, Berkeley, USA \n */
830 /* > Jim Demmel, University of California, Berkeley, USA \n */
831 /* > Inderjit Dhillon, University of Texas, Austin, USA \n */
832 /* > Osni Marques, LBNL/NERSC, USA \n */
833 /* > Christof Voemel, University of California, Berkeley, USA */
835 /* ===================================================================== */
836 /* Subroutine */ int sstemr_(char *jobz, char *range, integer *n, real *d__,
837 real *e, real *vl, real *vu, integer *il, integer *iu, integer *m,
838 real *w, real *z__, integer *ldz, integer *nzc, integer *isuppz,
839 logical *tryrac, real *work, integer *lwork, integer *iwork, integer *
840 liwork, integer *info)
842 /* System generated locals */
843 integer z_dim1, z_offset, i__1, i__2;
846 /* Local variables */
847 integer indd, iend, jblk, wend;
852 extern /* Subroutine */ int slae2_(real *, real *, real *, real *, real *)
859 extern logical lsame_(char *, char *);
861 extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
862 integer iindw, ilast, lwmin;
863 extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
864 integer *), sswap_(integer *, real *, integer *, real *, integer *
868 extern /* Subroutine */ int slaev2_(real *, real *, real *, real *, real *
873 logical alleig, indeig;
874 integer ibegin, iindbl;
877 extern real slamch_(char *);
880 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
882 integer inderr, iindwk, indgrs, offset;
883 extern /* Subroutine */ int slarrc_(char *, integer *, real *, real *,
884 real *, real *, real *, integer *, integer *, integer *, integer *
885 ), slarre_(char *, integer *, real *, real *, integer *,
886 integer *, real *, real *, real *, real *, real *, real *,
887 integer *, integer *, integer *, real *, real *, real *, integer *
888 , integer *, real *, real *, real *, integer *, integer *)
891 integer iinspl, indwrk, ifirst, liwmin, nzcmin;
893 extern real slanst_(char *, integer *, real *, real *);
894 extern /* Subroutine */ int slarrj_(integer *, real *, real *, integer *,
895 integer *, real *, integer *, real *, real *, real *, integer *,
896 real *, real *, integer *), slarrr_(integer *, real *, real *,
899 extern /* Subroutine */ int slarrv_(integer *, real *, real *, real *,
900 real *, real *, integer *, integer *, integer *, integer *, real *
901 , real *, real *, real *, real *, real *, integer *, integer *,
902 real *, real *, integer *, integer *, real *, integer *, integer *
905 extern /* Subroutine */ int slasrt_(char *, integer *, real *, integer *);
906 logical lquery, zquery;
911 /* -- LAPACK computational routine (version 3.7.1) -- */
912 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
913 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
917 /* ===================================================================== */
920 /* Test the input parameters. */
922 /* Parameter adjustments */
927 z_offset = 1 + z_dim1 * 1;
934 wantz = lsame_(jobz, "V");
935 alleig = lsame_(range, "A");
936 valeig = lsame_(range, "V");
937 indeig = lsame_(range, "I");
939 lquery = *lwork == -1 || *liwork == -1;
941 /* SSTEMR needs WORK of size 6*N, IWORK of size 3*N. */
942 /* In addition, SLARRE needs WORK of size 6*N, IWORK of size 5*N. */
943 /* Furthermore, SLARRV needs WORK of size 12*N, IWORK of size 7*N. */
948 /* need less workspace if only the eigenvalues are wanted */
958 /* We do not reference VL, VU in the cases RANGE = 'I','A' */
959 /* The interval (WL, WU] contains all the wanted eigenvalues. */
960 /* It is either given by the user or computed in SLARRE. */
964 /* We do not reference IL, IU in the cases RANGE = 'V','A' */
970 if (! (wantz || lsame_(jobz, "N"))) {
972 } else if (! (alleig || valeig || indeig)) {
976 } else if (valeig && *n > 0 && wu <= wl) {
978 } else if (indeig && (iil < 1 || iil > *n)) {
980 } else if (indeig && (iiu < iil || iiu > *n)) {
982 } else if (*ldz < 1 || wantz && *ldz < *n) {
984 } else if (*lwork < lwmin && ! lquery) {
986 } else if (*liwork < liwmin && ! lquery) {
990 /* Get machine constants. */
992 safmin = slamch_("Safe minimum");
993 eps = slamch_("Precision");
994 smlnum = safmin / eps;
995 bignum = 1.f / smlnum;
998 r__1 = sqrt(bignum), r__2 = 1.f / sqrt(sqrt(safmin));
999 rmax = f2cmin(r__1,r__2);
1002 work[1] = (real) lwmin;
1005 if (wantz && alleig) {
1007 } else if (wantz && valeig) {
1008 slarrc_("T", n, vl, vu, &d__[1], &e[1], &safmin, &nzcmin, &itmp, &
1010 } else if (wantz && indeig) {
1011 nzcmin = iiu - iil + 1;
1013 /* WANTZ .EQ. FALSE. */
1016 if (zquery && *info == 0) {
1017 z__[z_dim1 + 1] = (real) nzcmin;
1018 } else if (*nzc < nzcmin && ! zquery) {
1025 xerbla_("SSTEMR", &i__1, (ftnlen)6);
1028 } else if (lquery || zquery) {
1032 /* Handle N = 0, 1, and 2 cases immediately */
1040 if (alleig || indeig) {
1044 if (wl < d__[1] && wu >= d__[1]) {
1049 if (wantz && ! zquery) {
1050 z__[z_dim1 + 1] = 1.f;
1059 slae2_(&d__[1], &e[1], &d__[2], &r1, &r2);
1060 } else if (wantz && ! zquery) {
1061 slaev2_(&d__[1], &e[1], &d__[2], &r1, &r2, &cs, &sn);
1063 if (alleig || valeig && r2 > wl && r2 <= wu || indeig && iil == 1) {
1066 if (wantz && ! zquery) {
1067 z__[*m * z_dim1 + 1] = -sn;
1068 z__[*m * z_dim1 + 2] = cs;
1069 /* Note: At most one of SN and CS can be zero. */
1072 isuppz[(*m << 1) - 1] = 1;
1075 isuppz[(*m << 1) - 1] = 1;
1079 isuppz[(*m << 1) - 1] = 2;
1084 if (alleig || valeig && r1 > wl && r1 <= wu || indeig && iiu == 2) {
1087 if (wantz && ! zquery) {
1088 z__[*m * z_dim1 + 1] = cs;
1089 z__[*m * z_dim1 + 2] = sn;
1090 /* Note: At most one of SN and CS can be zero. */
1093 isuppz[(*m << 1) - 1] = 1;
1096 isuppz[(*m << 1) - 1] = 1;
1100 isuppz[(*m << 1) - 1] = 2;
1106 /* Continue with general N */
1108 inderr = (*n << 1) + 1;
1110 indd = (*n << 2) + 1;
1112 indwrk = *n * 6 + 1;
1116 iindw = (*n << 1) + 1;
1117 iindwk = *n * 3 + 1;
1119 /* Scale matrix to allowable range, if necessary. */
1120 /* The allowable range is related to the PIVMIN parameter; see the */
1121 /* comments in SLARRD. The preference for scaling small values */
1122 /* up is heuristic; we expect users' matrices not to be close to the */
1123 /* RMAX threshold. */
1126 tnrm = slanst_("M", n, &d__[1], &e[1]);
1127 if (tnrm > 0.f && tnrm < rmin) {
1128 scale = rmin / tnrm;
1129 } else if (tnrm > rmax) {
1130 scale = rmax / tnrm;
1133 sscal_(n, &scale, &d__[1], &c__1);
1135 sscal_(&i__1, &scale, &e[1], &c__1);
1138 /* If eigenvalues in interval have to be found, */
1139 /* scale (WL, WU] accordingly */
1145 /* Compute the desired eigenvalues of the tridiagonal after splitting */
1146 /* into smaller subblocks if the corresponding off-diagonal elements */
1148 /* THRESH is the splitting parameter for SLARRE */
1149 /* A negative THRESH forces the old splitting criterion based on the */
1150 /* size of the off-diagonal. A positive THRESH switches to splitting */
1151 /* which preserves relative accuracy. */
1154 /* Test whether the matrix warrants the more expensive relative approach. */
1155 slarrr_(n, &d__[1], &e[1], &iinfo);
1157 /* The user does not care about relative accurately eigenvalues */
1160 /* Set the splitting criterion */
1165 /* relative accuracy is desired but T does not guarantee it */
1170 /* Copy original diagonal, needed to guarantee relative accuracy */
1171 scopy_(n, &d__[1], &c__1, &work[indd], &c__1);
1173 /* Store the squares of the offdiagonal values of T */
1175 for (j = 1; j <= i__1; ++j) {
1176 /* Computing 2nd power */
1178 work[inde2 + j - 1] = r__1 * r__1;
1181 /* Set the tolerance parameters for bisection */
1183 /* SLARRE computes the eigenvalues to full precision. */
1187 /* SLARRE computes the eigenvalues to less than full precision. */
1188 /* SLARRV will refine the eigenvalue approximations, and we can */
1189 /* need less accurate initial bisection in SLARRE. */
1190 /* Note: these settings do only affect the subset case and SLARRE */
1192 r__1 = sqrt(eps) * .05f, r__2 = eps * 4.f;
1193 rtol1 = f2cmax(r__1,r__2);
1195 r__1 = sqrt(eps) * .005f, r__2 = eps * 4.f;
1196 rtol2 = f2cmax(r__1,r__2);
1198 slarre_(range, n, &wl, &wu, &iil, &iiu, &d__[1], &e[1], &work[inde2],
1199 &rtol1, &rtol2, &thresh, &nsplit, &iwork[iinspl], m, &w[1], &
1200 work[inderr], &work[indgp], &iwork[iindbl], &iwork[iindw], &
1201 work[indgrs], &pivmin, &work[indwrk], &iwork[iindwk], &iinfo);
1203 *info = abs(iinfo) + 10;
1206 /* Note that if RANGE .NE. 'V', SLARRE computes bounds on the desired */
1207 /* part of the spectrum. All desired eigenvalues are contained in */
1211 /* Compute the desired eigenvectors corresponding to the computed */
1214 slarrv_(n, &wl, &wu, &d__[1], &e[1], &pivmin, &iwork[iinspl], m, &
1215 c__1, m, &c_b18, &rtol1, &rtol2, &w[1], &work[inderr], &
1216 work[indgp], &iwork[iindbl], &iwork[iindw], &work[indgrs],
1217 &z__[z_offset], ldz, &isuppz[1], &work[indwrk], &iwork[
1220 *info = abs(iinfo) + 20;
1224 /* SLARRE computes eigenvalues of the (shifted) root representation */
1225 /* SLARRV returns the eigenvalues of the unshifted matrix. */
1226 /* However, if the eigenvectors are not desired by the user, we need */
1227 /* to apply the corresponding shifts from SLARRE to obtain the */
1228 /* eigenvalues of the original matrix. */
1230 for (j = 1; j <= i__1; ++j) {
1231 itmp = iwork[iindbl + j - 1];
1232 w[j] += e[iwork[iinspl + itmp - 1]];
1238 /* Refine computed eigenvalues so that they are relatively accurate */
1239 /* with respect to the original matrix T. */
1242 i__1 = iwork[iindbl + *m - 1];
1243 for (jblk = 1; jblk <= i__1; ++jblk) {
1244 iend = iwork[iinspl + jblk - 1];
1245 in = iend - ibegin + 1;
1247 /* check if any eigenvalues have to be refined in this block */
1250 if (iwork[iindbl + wend] == jblk) {
1255 if (wend < wbegin) {
1259 offset = iwork[iindw + wbegin - 1] - 1;
1260 ifirst = iwork[iindw + wbegin - 1];
1261 ilast = iwork[iindw + wend - 1];
1263 slarrj_(&in, &work[indd + ibegin - 1], &work[inde2 + ibegin -
1264 1], &ifirst, &ilast, &rtol2, &offset, &w[wbegin], &
1265 work[inderr + wbegin - 1], &work[indwrk], &iwork[
1266 iindwk], &pivmin, &tnrm, &iinfo);
1274 /* If matrix was scaled, then rescale eigenvalues appropriately. */
1278 sscal_(m, &r__1, &w[1], &c__1);
1282 /* If eigenvalues are not in increasing order, then sort them, */
1283 /* possibly along with eigenvectors. */
1285 if (nsplit > 1 || *n == 2) {
1287 slasrt_("I", m, &w[1], &iinfo);
1294 for (j = 1; j <= i__1; ++j) {
1298 for (jj = j + 1; jj <= i__2; ++jj) {
1309 sswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j *
1310 z_dim1 + 1], &c__1);
1311 itmp = isuppz[(i__ << 1) - 1];
1312 isuppz[(i__ << 1) - 1] = isuppz[(j << 1) - 1];
1313 isuppz[(j << 1) - 1] = itmp;
1314 itmp = isuppz[i__ * 2];
1315 isuppz[i__ * 2] = isuppz[j * 2];
1316 isuppz[j * 2] = itmp;
1325 work[1] = (real) lwmin;