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 integer c__2 = 2;
518 /* > \brief \b SLARRE given the tridiagonal matrix T, sets small off-diagonal elements to zero and for each un
519 reduced block Ti, finds base representations and eigenvalues. */
521 /* =========== DOCUMENTATION =========== */
523 /* Online html documentation available at */
524 /* http://www.netlib.org/lapack/explore-html/ */
527 /* > Download SLARRE + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slarre.
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slarre.
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slarre.
542 /* SUBROUTINE SLARRE( RANGE, N, VL, VU, IL, IU, D, E, E2, */
543 /* RTOL1, RTOL2, SPLTOL, NSPLIT, ISPLIT, M, */
544 /* W, WERR, WGAP, IBLOCK, INDEXW, GERS, PIVMIN, */
545 /* WORK, IWORK, INFO ) */
547 /* CHARACTER RANGE */
548 /* INTEGER IL, INFO, IU, M, N, NSPLIT */
549 /* REAL PIVMIN, RTOL1, RTOL2, SPLTOL, VL, VU */
550 /* INTEGER IBLOCK( * ), ISPLIT( * ), IWORK( * ), */
552 /* REAL D( * ), E( * ), E2( * ), GERS( * ), */
553 /* $ W( * ),WERR( * ), WGAP( * ), WORK( * ) */
556 /* > \par Purpose: */
561 /* > To find the desired eigenvalues of a given real symmetric */
562 /* > tridiagonal matrix T, SLARRE sets any "small" off-diagonal */
563 /* > elements to zero, and for each unreduced block T_i, it finds */
564 /* > (a) a suitable shift at one end of the block's spectrum, */
565 /* > (b) the base representation, T_i - sigma_i I = L_i D_i L_i^T, and */
566 /* > (c) eigenvalues of each L_i D_i L_i^T. */
567 /* > The representations and eigenvalues found are then used by */
568 /* > SSTEMR to compute the eigenvectors of T. */
569 /* > The accuracy varies depending on whether bisection is used to */
570 /* > find a few eigenvalues or the dqds algorithm (subroutine SLASQ2) to */
571 /* > conpute all and then discard any unwanted one. */
572 /* > As an added benefit, SLARRE also outputs the n */
573 /* > Gerschgorin intervals for the matrices L_i D_i L_i^T. */
579 /* > \param[in] RANGE */
581 /* > RANGE is CHARACTER*1 */
582 /* > = 'A': ("All") all eigenvalues will be found. */
583 /* > = 'V': ("Value") all eigenvalues in the half-open interval */
584 /* > (VL, VU] will be found. */
585 /* > = 'I': ("Index") the IL-th through IU-th eigenvalues (of the */
586 /* > entire matrix) will be found. */
592 /* > The order of the matrix. N > 0. */
595 /* > \param[in,out] VL */
598 /* > If RANGE='V', the lower bound for the eigenvalues. */
599 /* > Eigenvalues less than or equal to VL, or greater than VU, */
600 /* > will not be returned. VL < VU. */
601 /* > If RANGE='I' or ='A', SLARRE computes bounds on the desired */
602 /* > part of the spectrum. */
605 /* > \param[in,out] VU */
608 /* > If RANGE='V', the upper bound for the eigenvalues. */
609 /* > Eigenvalues less than or equal to VL, or greater than VU, */
610 /* > will not be returned. VL < VU. */
611 /* > If RANGE='I' or ='A', SLARRE computes bounds on the desired */
612 /* > part of the spectrum. */
615 /* > \param[in] IL */
617 /* > IL is INTEGER */
618 /* > If RANGE='I', the index of the */
619 /* > smallest eigenvalue to be returned. */
620 /* > 1 <= IL <= IU <= N. */
623 /* > \param[in] IU */
625 /* > IU is INTEGER */
626 /* > If RANGE='I', the index of the */
627 /* > largest eigenvalue to be returned. */
628 /* > 1 <= IL <= IU <= N. */
631 /* > \param[in,out] D */
633 /* > D is REAL array, dimension (N) */
634 /* > On entry, the N diagonal elements of the tridiagonal */
636 /* > On exit, the N diagonal elements of the diagonal */
637 /* > matrices D_i. */
640 /* > \param[in,out] E */
642 /* > E is REAL array, dimension (N) */
643 /* > On entry, the first (N-1) entries contain the subdiagonal */
644 /* > elements of the tridiagonal matrix T; E(N) need not be set. */
645 /* > On exit, E contains the subdiagonal elements of the unit */
646 /* > bidiagonal matrices L_i. The entries E( ISPLIT( I ) ), */
647 /* > 1 <= I <= NSPLIT, contain the base points sigma_i on output. */
650 /* > \param[in,out] E2 */
652 /* > E2 is REAL array, dimension (N) */
653 /* > On entry, the first (N-1) entries contain the SQUARES of the */
654 /* > subdiagonal elements of the tridiagonal matrix T; */
655 /* > E2(N) need not be set. */
656 /* > On exit, the entries E2( ISPLIT( I ) ), */
657 /* > 1 <= I <= NSPLIT, have been set to zero */
660 /* > \param[in] RTOL1 */
662 /* > RTOL1 is REAL */
665 /* > \param[in] RTOL2 */
667 /* > RTOL2 is REAL */
668 /* > Parameters for bisection. */
669 /* > An interval [LEFT,RIGHT] has converged if */
670 /* > RIGHT-LEFT < MAX( RTOL1*GAP, RTOL2*MAX(|LEFT|,|RIGHT|) ) */
673 /* > \param[in] SPLTOL */
675 /* > SPLTOL is REAL */
676 /* > The threshold for splitting. */
679 /* > \param[out] NSPLIT */
681 /* > NSPLIT is INTEGER */
682 /* > The number of blocks T splits into. 1 <= NSPLIT <= N. */
685 /* > \param[out] ISPLIT */
687 /* > ISPLIT is INTEGER array, dimension (N) */
688 /* > The splitting points, at which T breaks up into blocks. */
689 /* > The first block consists of rows/columns 1 to ISPLIT(1), */
690 /* > the second of rows/columns ISPLIT(1)+1 through ISPLIT(2), */
691 /* > etc., and the NSPLIT-th consists of rows/columns */
692 /* > ISPLIT(NSPLIT-1)+1 through ISPLIT(NSPLIT)=N. */
695 /* > \param[out] M */
698 /* > The total number of eigenvalues (of all L_i D_i L_i^T) */
702 /* > \param[out] W */
704 /* > W is REAL array, dimension (N) */
705 /* > The first M elements contain the eigenvalues. The */
706 /* > eigenvalues of each of the blocks, L_i D_i L_i^T, are */
707 /* > sorted in ascending order ( SLARRE may use the */
708 /* > remaining N-M elements as workspace). */
711 /* > \param[out] WERR */
713 /* > WERR is REAL array, dimension (N) */
714 /* > The error bound on the corresponding eigenvalue in W. */
717 /* > \param[out] WGAP */
719 /* > WGAP is REAL array, dimension (N) */
720 /* > The separation from the right neighbor eigenvalue in W. */
721 /* > The gap is only with respect to the eigenvalues of the same block */
722 /* > as each block has its own representation tree. */
723 /* > Exception: at the right end of a block we store the left gap */
726 /* > \param[out] IBLOCK */
728 /* > IBLOCK is INTEGER array, dimension (N) */
729 /* > The indices of the blocks (submatrices) associated with the */
730 /* > corresponding eigenvalues in W; IBLOCK(i)=1 if eigenvalue */
731 /* > W(i) belongs to the first block from the top, =2 if W(i) */
732 /* > belongs to the second block, etc. */
735 /* > \param[out] INDEXW */
737 /* > INDEXW is INTEGER array, dimension (N) */
738 /* > The indices of the eigenvalues within each block (submatrix); */
739 /* > for example, INDEXW(i)= 10 and IBLOCK(i)=2 imply that the */
740 /* > i-th eigenvalue W(i) is the 10-th eigenvalue in block 2 */
743 /* > \param[out] GERS */
745 /* > GERS is REAL array, dimension (2*N) */
746 /* > The N Gerschgorin intervals (the i-th Gerschgorin interval */
747 /* > is (GERS(2*i-1), GERS(2*i)). */
750 /* > \param[out] PIVMIN */
752 /* > PIVMIN is REAL */
753 /* > The minimum pivot in the Sturm sequence for T. */
756 /* > \param[out] WORK */
758 /* > WORK is REAL array, dimension (6*N) */
762 /* > \param[out] IWORK */
764 /* > IWORK is INTEGER array, dimension (5*N) */
768 /* > \param[out] INFO */
770 /* > INFO is INTEGER */
771 /* > = 0: successful exit */
772 /* > > 0: A problem occurred in SLARRE. */
773 /* > < 0: One of the called subroutines signaled an internal problem. */
774 /* > Needs inspection of the corresponding parameter IINFO */
775 /* > for further information. */
777 /* > =-1: Problem in SLARRD. */
778 /* > = 2: No base representation could be found in MAXTRY iterations. */
779 /* > Increasing MAXTRY and recompilation might be a remedy. */
780 /* > =-3: Problem in SLARRB when computing the refined root */
781 /* > representation for SLASQ2. */
782 /* > =-4: Problem in SLARRB when preforming bisection on the */
783 /* > desired part of the spectrum. */
784 /* > =-5: Problem in SLASQ2. */
785 /* > =-6: Problem in SLASQ2. */
791 /* > \author Univ. of Tennessee */
792 /* > \author Univ. of California Berkeley */
793 /* > \author Univ. of Colorado Denver */
794 /* > \author NAG Ltd. */
796 /* > \date June 2016 */
798 /* > \ingroup OTHERauxiliary */
800 /* > \par Further Details: */
801 /* ===================== */
805 /* > The base representations are required to suffer very little */
806 /* > element growth and consequently define all their eigenvalues to */
807 /* > high relative accuracy. */
810 /* > \par Contributors: */
811 /* ================== */
813 /* > Beresford Parlett, University of California, Berkeley, USA \n */
814 /* > Jim Demmel, University of California, Berkeley, USA \n */
815 /* > Inderjit Dhillon, University of Texas, Austin, USA \n */
816 /* > Osni Marques, LBNL/NERSC, USA \n */
817 /* > Christof Voemel, University of California, Berkeley, USA \n */
819 /* ===================================================================== */
820 /* Subroutine */ int slarre_(char *range, integer *n, real *vl, real *vu,
821 integer *il, integer *iu, real *d__, real *e, real *e2, real *rtol1,
822 real *rtol2, real *spltol, integer *nsplit, integer *isplit, integer *
823 m, real *w, real *werr, real *wgap, integer *iblock, integer *indexw,
824 real *gers, real *pivmin, real *work, integer *iwork, integer *info)
826 /* System generated locals */
828 real r__1, r__2, r__3;
830 /* Local variables */
836 integer wend, idum, indu;
838 integer i__, j, iseed[4];
840 extern logical lsame_(char *, char *);
843 extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
846 extern /* Subroutine */ int slasq2_(integer *, real *, integer *);
855 extern real slamch_(char *);
858 extern /* Subroutine */ int slarra_(integer *, real *, real *, real *,
859 real *, real *, integer *, integer *, integer *);
862 extern /* Subroutine */ int slarrb_(integer *, real *, real *, integer *,
863 integer *, real *, real *, integer *, real *, real *, real *,
864 real *, integer *, real *, real *, integer *, integer *), slarrc_(
865 char *, integer *, real *, real *, real *, real *, real *,
866 integer *, integer *, integer *, integer *), slarrd_(char
867 *, char *, integer *, real *, real *, integer *, integer *, real *
868 , real *, real *, real *, real *, real *, integer *, integer *,
869 integer *, real *, real *, real *, real *, integer *, integer *,
870 real *, integer *, integer *), slarrk_(integer *,
871 integer *, real *, real *, real *, real *, real *, real *, real *,
873 real isrght, bsrtol, dpivot;
874 extern /* Subroutine */ int slarnv_(integer *, integer *, integer *, real
877 real eps, tau, tmp, rtl;
882 /* -- LAPACK auxiliary routine (version 3.8.0) -- */
883 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
884 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
888 /* ===================================================================== */
891 /* Parameter adjustments */
908 /* Quick return if possible */
916 if (lsame_(range, "A")) {
918 } else if (lsame_(range, "V")) {
920 } else if (lsame_(range, "I")) {
924 /* Get machine constants */
925 safmin = slamch_("S");
929 /* If one were ever to ask for less initial precision in BSRTOL, */
930 /* one should keep in mind that for the subset case, the extremal */
931 /* eigenvalues must be at least as accurate as the current setting */
932 /* (eigenvalues in the middle need not as much accuracy) */
933 bsrtol = sqrt(eps) * 5e-4f;
934 /* Treat case of 1x1 matrix for quick return */
936 if (irange == 1 || irange == 3 && d__[1] > *vl && d__[1] <= *vu ||
937 irange == 2 && *il == 1 && *iu == 1) {
940 /* The computation error of the eigenvalue is zero */
948 /* store the shift for the initial RRR, which is zero in this case */
952 /* General case: tridiagonal matrix of order > 1 */
954 /* Init WERR, WGAP. Compute Gerschgorin intervals and spectral diameter. */
955 /* Compute maximum off-diagonal entry and pivmin. */
962 for (i__ = 1; i__ <= i__1; ++i__) {
965 eabs = (r__1 = e[i__], abs(r__1));
970 gers[(i__ << 1) - 1] = d__[i__] - tmp1;
972 r__1 = gl, r__2 = gers[(i__ << 1) - 1];
973 gl = f2cmin(r__1,r__2);
974 gers[i__ * 2] = d__[i__] + tmp1;
976 r__1 = gu, r__2 = gers[i__ * 2];
977 gu = f2cmax(r__1,r__2);
981 /* The minimum pivot allowed in the Sturm sequence for T */
983 /* Computing 2nd power */
985 r__1 = 1.f, r__2 = r__3 * r__3;
986 *pivmin = safmin * f2cmax(r__1,r__2);
987 /* Compute spectral diameter. The Gerschgorin bounds give an */
988 /* estimate that is wrong by at most a factor of SQRT(2) */
990 /* Compute splitting points */
991 slarra_(n, &d__[1], &e[1], &e2[1], spltol, &spdiam, nsplit, &isplit[1], &
993 /* Can force use of bisection instead of faster DQDS. */
994 /* Option left in the code for future multisection work. */
996 /* Initialize USEDQD, DQDS should be used for ALLRNG unless someone */
997 /* explicitly wants bisection. */
998 usedqd = irange == 1 && ! forceb;
999 if (irange == 1 && ! forceb) {
1000 /* Set interval [VL,VU] that contains all eigenvalues */
1004 /* We call SLARRD to find crude approximations to the eigenvalues */
1005 /* in the desired range. In case IRANGE = INDRNG, we also obtain the */
1006 /* interval (VL,VU] that contains all the wanted eigenvalues. */
1007 /* An interval [LEFT,RIGHT] has converged if */
1008 /* RIGHT-LEFT.LT.RTOL*MAX(ABS(LEFT),ABS(RIGHT)) */
1009 /* SLARRD needs a WORK of size 4*N, IWORK of size 3*N */
1010 slarrd_(range, "B", n, vl, vu, il, iu, &gers[1], &bsrtol, &d__[1], &e[
1011 1], &e2[1], pivmin, nsplit, &isplit[1], &mm, &w[1], &werr[1],
1012 vl, vu, &iblock[1], &indexw[1], &work[1], &iwork[1], &iinfo);
1017 /* Make sure that the entries M+1 to N in W, WERR, IBLOCK, INDEXW are 0 */
1019 for (i__ = mm + 1; i__ <= i__1; ++i__) {
1028 /* Loop over unreduced blocks */
1032 for (jblk = 1; jblk <= i__1; ++jblk) {
1033 iend = isplit[jblk];
1034 in = iend - ibegin + 1;
1037 if (irange == 1 || irange == 3 && d__[ibegin] > *vl && d__[ibegin]
1038 <= *vu || irange == 2 && iblock[wbegin] == jblk) {
1040 w[*m] = d__[ibegin];
1042 /* The gap for a single block doesn't matter for the later */
1043 /* algorithm and is assigned an arbitrary large value */
1049 /* E( IEND ) holds the shift for the initial RRR */
1055 /* Blocks of size larger than 1x1 */
1057 /* E( IEND ) will hold the shift for the initial RRR, for now set it =0 */
1060 /* Find local outer bounds GL,GU for the block */
1064 for (i__ = ibegin; i__ <= i__2; ++i__) {
1066 r__1 = gers[(i__ << 1) - 1];
1067 gl = f2cmin(r__1,gl);
1069 r__1 = gers[i__ * 2];
1070 gu = f2cmax(r__1,gu);
1074 if (! (irange == 1 && ! forceb)) {
1075 /* Count the number of eigenvalues in the current block. */
1078 for (i__ = wbegin; i__ <= i__2; ++i__) {
1079 if (iblock[i__] == jblk) {
1088 /* No eigenvalue in the current block lies in the desired range */
1089 /* E( IEND ) holds the shift for the initial RRR */
1094 /* Decide whether dqds or bisection is more efficient */
1095 usedqd = (real) mb > in * .5f && ! forceb;
1096 wend = wbegin + mb - 1;
1097 /* Calculate gaps for the current block */
1098 /* In later stages, when representations for individual */
1099 /* eigenvalues are different, we use SIGMA = E( IEND ). */
1102 for (i__ = wbegin; i__ <= i__2; ++i__) {
1104 r__1 = 0.f, r__2 = w[i__ + 1] - werr[i__ + 1] - (w[i__] +
1106 wgap[i__] = f2cmax(r__1,r__2);
1110 r__1 = 0.f, r__2 = *vu - sigma - (w[wend] + werr[wend]);
1111 wgap[wend] = f2cmax(r__1,r__2);
1112 /* Find local index of the first and last desired evalue. */
1113 indl = indexw[wbegin];
1114 indu = indexw[wend];
1117 if (irange == 1 && ! forceb || usedqd) {
1119 /* Find approximations to the extremal eigenvalues of the block */
1120 slarrk_(&in, &c__1, &gl, &gu, &d__[ibegin], &e2[ibegin], pivmin, &
1121 rtl, &tmp, &tmp1, &iinfo);
1127 r__2 = gl, r__3 = tmp - tmp1 - eps * 100.f * (r__1 = tmp - tmp1,
1129 isleft = f2cmax(r__2,r__3);
1130 slarrk_(&in, &in, &gl, &gu, &d__[ibegin], &e2[ibegin], pivmin, &
1131 rtl, &tmp, &tmp1, &iinfo);
1137 r__2 = gu, r__3 = tmp + tmp1 + eps * 100.f * (r__1 = tmp + tmp1,
1139 isrght = f2cmin(r__2,r__3);
1140 /* Improve the estimate of the spectral diameter */
1141 spdiam = isrght - isleft;
1143 /* Case of bisection */
1144 /* Find approximations to the wanted extremal eigenvalues */
1146 r__2 = gl, r__3 = w[wbegin] - werr[wbegin] - eps * 100.f * (r__1 =
1147 w[wbegin] - werr[wbegin], abs(r__1));
1148 isleft = f2cmax(r__2,r__3);
1150 r__2 = gu, r__3 = w[wend] + werr[wend] + eps * 100.f * (r__1 = w[
1151 wend] + werr[wend], abs(r__1));
1152 isrght = f2cmin(r__2,r__3);
1154 /* Decide whether the base representation for the current block */
1155 /* L_JBLK D_JBLK L_JBLK^T = T_JBLK - sigma_JBLK I */
1156 /* should be on the left or the right end of the current block. */
1157 /* The strategy is to shift to the end which is "more populated" */
1158 /* Furthermore, decide whether to use DQDS for the computation of */
1159 /* the eigenvalue approximations at the end of SLARRE or bisection. */
1160 /* dqds is chosen if all eigenvalues are desired or the number of */
1161 /* eigenvalues to be computed is large compared to the blocksize. */
1162 if (irange == 1 && ! forceb) {
1163 /* If all the eigenvalues have to be computed, we use dqd */
1165 /* INDL is the local index of the first eigenvalue to compute */
1168 /* MB = number of eigenvalues to compute */
1170 wend = wbegin + mb - 1;
1171 /* Define 1/4 and 3/4 points of the spectrum */
1172 s1 = isleft + spdiam * .25f;
1173 s2 = isrght - spdiam * .25f;
1175 /* SLARRD has computed IBLOCK and INDEXW for each eigenvalue */
1176 /* approximation. */
1179 s1 = isleft + spdiam * .25f;
1180 s2 = isrght - spdiam * .25f;
1182 tmp = f2cmin(isrght,*vu) - f2cmax(isleft,*vl);
1183 s1 = f2cmax(isleft,*vl) + tmp * .25f;
1184 s2 = f2cmin(isrght,*vu) - tmp * .25f;
1187 /* Compute the negcount at the 1/4 and 3/4 points */
1189 slarrc_("T", &in, &s1, &s2, &d__[ibegin], &e[ibegin], pivmin, &
1190 cnt, &cnt1, &cnt2, &iinfo);
1195 } else if (cnt1 - indl >= indu - cnt2) {
1196 if (irange == 1 && ! forceb) {
1197 sigma = f2cmax(isleft,gl);
1198 } else if (usedqd) {
1199 /* use Gerschgorin bound as shift to get pos def matrix */
1203 /* use approximation of the first desired eigenvalue of the */
1204 /* block as shift */
1205 sigma = f2cmax(isleft,*vl);
1209 if (irange == 1 && ! forceb) {
1210 sigma = f2cmin(isrght,gu);
1211 } else if (usedqd) {
1212 /* use Gerschgorin bound as shift to get neg def matrix */
1216 /* use approximation of the first desired eigenvalue of the */
1217 /* block as shift */
1218 sigma = f2cmin(isrght,*vu);
1222 /* An initial SIGMA has been chosen that will be used for computing */
1223 /* T - SIGMA I = L D L^T */
1224 /* Define the increment TAU of the shift in case the initial shift */
1225 /* needs to be refined to obtain a factorization with not too much */
1226 /* element growth. */
1228 /* The initial SIGMA was to the outer end of the spectrum */
1229 /* the matrix is definite and we need not retreat. */
1230 tau = spdiam * eps * *n + *pivmin * 2.f;
1232 r__1 = tau, r__2 = eps * 2.f * abs(sigma);
1233 tau = f2cmax(r__1,r__2);
1236 clwdth = w[wend] + werr[wend] - w[wbegin] - werr[wbegin];
1237 avgap = (r__1 = clwdth / (real) (wend - wbegin), abs(r__1));
1238 if (sgndef == 1.f) {
1240 r__1 = wgap[wbegin];
1241 tau = f2cmax(r__1,avgap) * .5f;
1243 r__1 = tau, r__2 = werr[wbegin];
1244 tau = f2cmax(r__1,r__2);
1247 r__1 = wgap[wend - 1];
1248 tau = f2cmax(r__1,avgap) * .5f;
1250 r__1 = tau, r__2 = werr[wend];
1251 tau = f2cmax(r__1,r__2);
1258 for (idum = 1; idum <= 6; ++idum) {
1259 /* Compute L D L^T factorization of tridiagonal matrix T - sigma I. */
1260 /* Store D in WORK(1:IN), L in WORK(IN+1:2*IN), and reciprocals of */
1261 /* pivots in WORK(2*IN+1:3*IN) */
1262 dpivot = d__[ibegin] - sigma;
1264 dmax__ = abs(work[1]);
1267 for (i__ = 1; i__ <= i__2; ++i__) {
1268 work[(in << 1) + i__] = 1.f / work[i__];
1269 tmp = e[j] * work[(in << 1) + i__];
1270 work[in + i__] = tmp;
1271 dpivot = d__[j + 1] - sigma - tmp * e[j];
1272 work[i__ + 1] = dpivot;
1274 r__1 = dmax__, r__2 = abs(dpivot);
1275 dmax__ = f2cmax(r__1,r__2);
1279 /* check for element growth */
1280 if (dmax__ > spdiam * 64.f) {
1285 if (usedqd && ! norep) {
1286 /* Ensure the definiteness of the representation */
1287 /* All entries of D (of L D L^T) must have the same sign */
1289 for (i__ = 1; i__ <= i__2; ++i__) {
1290 tmp = sgndef * work[i__];
1298 /* Note that in the case of IRANGE=ALLRNG, we use the Gerschgorin */
1299 /* shift which makes the matrix definite. So we should end up */
1300 /* here really only in the case of IRANGE = VALRNG or INDRNG. */
1302 if (sgndef == 1.f) {
1303 /* The fudged Gerschgorin shift should succeed */
1304 sigma = gl - spdiam * 2.f * eps * *n - *pivmin * 4.f;
1306 sigma = gu + spdiam * 2.f * eps * *n + *pivmin * 4.f;
1309 sigma -= sgndef * tau;
1313 /* an initial RRR is found */
1318 /* if the program reaches this point, no base representation could be */
1319 /* found in MAXTRY iterations. */
1323 /* At this point, we have found an initial base representation */
1324 /* T - SIGMA I = L D L^T with not too much element growth. */
1325 /* Store the shift. */
1327 /* Store D and L. */
1328 scopy_(&in, &work[1], &c__1, &d__[ibegin], &c__1);
1330 scopy_(&i__2, &work[in + 1], &c__1, &e[ibegin], &c__1);
1333 /* Perturb each entry of the base representation by a small */
1334 /* (but random) relative amount to overcome difficulties with */
1335 /* glued matrices. */
1337 for (i__ = 1; i__ <= 4; ++i__) {
1341 i__2 = (in << 1) - 1;
1342 slarnv_(&c__2, iseed, &i__2, &work[1]);
1344 for (i__ = 1; i__ <= i__2; ++i__) {
1345 d__[ibegin + i__ - 1] *= eps * 4.f * work[i__] + 1.f;
1346 e[ibegin + i__ - 1] *= eps * 4.f * work[in + i__] + 1.f;
1349 d__[iend] *= eps * 4.f * work[in] + 1.f;
1353 /* Don't update the Gerschgorin intervals because keeping track */
1354 /* of the updates would be too much work in SLARRV. */
1355 /* We update W instead and use it to locate the proper Gerschgorin */
1357 /* Compute the required eigenvalues of L D L' by bisection or dqds */
1359 /* If SLARRD has been used, shift the eigenvalue approximations */
1360 /* according to their representation. This is necessary for */
1361 /* a uniform SLARRV since dqds computes eigenvalues of the */
1362 /* shifted representation. In SLARRV, W will always hold the */
1363 /* UNshifted eigenvalue approximation. */
1365 for (j = wbegin; j <= i__2; ++j) {
1367 werr[j] += (r__1 = w[j], abs(r__1)) * eps;
1370 /* call SLARRB to reduce eigenvalue error of the approximations */
1373 for (i__ = ibegin; i__ <= i__2; ++i__) {
1374 /* Computing 2nd power */
1376 work[i__] = d__[i__] * (r__1 * r__1);
1379 /* use bisection to find EV from INDL to INDU */
1381 slarrb_(&in, &d__[ibegin], &work[ibegin], &indl, &indu, rtol1,
1382 rtol2, &i__2, &w[wbegin], &wgap[wbegin], &werr[wbegin], &
1383 work[(*n << 1) + 1], &iwork[1], pivmin, &spdiam, &in, &
1389 /* SLARRB computes all gaps correctly except for the last one */
1390 /* Record distance to VU/GU */
1392 r__1 = 0.f, r__2 = *vu - sigma - (w[wend] + werr[wend]);
1393 wgap[wend] = f2cmax(r__1,r__2);
1395 for (i__ = indl; i__ <= i__2; ++i__) {
1402 /* Call dqds to get all eigs (and then possibly delete unwanted */
1404 /* Note that dqds finds the eigenvalues of the L D L^T representation */
1405 /* of T to high relative accuracy. High relative accuracy */
1406 /* might be lost when the shift of the RRR is subtracted to obtain */
1407 /* the eigenvalues of T. However, T is not guaranteed to define its */
1408 /* eigenvalues to high relative accuracy anyway. */
1409 /* Set RTOL to the order of the tolerance used in SLASQ2 */
1410 /* This is an ESTIMATED error, the worst case bound is 4*N*EPS */
1411 /* which is usually too large and requires unnecessary work to be */
1412 /* done by bisection when computing the eigenvectors */
1413 rtol = log((real) in) * 4.f * eps;
1416 for (i__ = 1; i__ <= i__2; ++i__) {
1417 work[(i__ << 1) - 1] = (r__1 = d__[j], abs(r__1));
1418 work[i__ * 2] = e[j] * e[j] * work[(i__ << 1) - 1];
1422 work[(in << 1) - 1] = (r__1 = d__[iend], abs(r__1));
1424 slasq2_(&in, &work[1], &iinfo);
1426 /* If IINFO = -5 then an index is part of a tight cluster */
1427 /* and should be changed. The index is in IWORK(1) and the */
1428 /* gap is in WORK(N+1) */
1432 /* Test that all eigenvalues are positive as expected */
1434 for (i__ = 1; i__ <= i__2; ++i__) {
1435 if (work[i__] < 0.f) {
1444 for (i__ = indl; i__ <= i__2; ++i__) {
1446 w[*m] = work[in - i__ + 1];
1453 for (i__ = indl; i__ <= i__2; ++i__) {
1462 for (i__ = *m - mb + 1; i__ <= i__2; ++i__) {
1463 /* the value of RTOL below should be the tolerance in SLASQ2 */
1464 werr[i__] = rtol * (r__1 = w[i__], abs(r__1));
1468 for (i__ = *m - mb + 1; i__ <= i__2; ++i__) {
1469 /* compute the right gap between the intervals */
1471 r__1 = 0.f, r__2 = w[i__ + 1] - werr[i__ + 1] - (w[i__] +
1473 wgap[i__] = f2cmax(r__1,r__2);
1477 r__1 = 0.f, r__2 = *vu - sigma - (w[*m] + werr[*m]);
1478 wgap[*m] = f2cmax(r__1,r__2);
1480 /* proceed with next block */