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 DLARRE 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 DLARRE + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlarre.
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlarre.
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlarre.
542 /* SUBROUTINE DLARRE( 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 /* DOUBLE PRECISION PIVMIN, RTOL1, RTOL2, SPLTOL, VL, VU */
550 /* INTEGER IBLOCK( * ), ISPLIT( * ), IWORK( * ), */
552 /* DOUBLE PRECISION 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, DLARRE 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 /* > DSTEMR 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 DLASQ2) to */
571 /* > conpute all and then discard any unwanted one. */
572 /* > As an added benefit, DLARRE 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 */
597 /* > VL is DOUBLE PRECISION */
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', DLARRE computes bounds on the desired */
602 /* > part of the spectrum. */
605 /* > \param[in,out] VU */
607 /* > VU is DOUBLE PRECISION */
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', DLARRE 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION */
665 /* > \param[in] RTOL2 */
667 /* > RTOL2 is DOUBLE PRECISION */
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 DOUBLE PRECISION */
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 DOUBLE PRECISION 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 ( DLARRE may use the */
708 /* > remaining N-M elements as workspace). */
711 /* > \param[out] WERR */
713 /* > WERR is DOUBLE PRECISION array, dimension (N) */
714 /* > The error bound on the corresponding eigenvalue in W. */
717 /* > \param[out] WGAP */
719 /* > WGAP is DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION */
753 /* > The minimum pivot in the Sturm sequence for T. */
756 /* > \param[out] WORK */
758 /* > WORK is DOUBLE PRECISION 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 DLARRE. */
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 DLARRD. */
778 /* > = 2: No base representation could be found in MAXTRY iterations. */
779 /* > Increasing MAXTRY and recompilation might be a remedy. */
780 /* > =-3: Problem in DLARRB when computing the refined root */
781 /* > representation for DLASQ2. */
782 /* > =-4: Problem in DLARRB when preforming bisection on the */
783 /* > desired part of the spectrum. */
784 /* > =-5: Problem in DLASQ2. */
785 /* > =-6: Problem in DLASQ2. */
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 dlarre_(char *range, integer *n, doublereal *vl,
821 doublereal *vu, integer *il, integer *iu, doublereal *d__, doublereal
822 *e, doublereal *e2, doublereal *rtol1, doublereal *rtol2, doublereal *
823 spltol, integer *nsplit, integer *isplit, integer *m, doublereal *w,
824 doublereal *werr, doublereal *wgap, integer *iblock, integer *indexw,
825 doublereal *gers, doublereal *pivmin, doublereal *work, integer *
826 iwork, integer *info)
828 /* System generated locals */
830 doublereal d__1, d__2, d__3;
832 /* Local variables */
837 doublereal dmax__, emax;
838 integer wend, idum, indu;
840 integer i__, j, iseed[4];
841 doublereal avgap, sigma;
842 extern logical lsame_(char *, char *);
844 extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
845 doublereal *, integer *);
848 extern /* Subroutine */ int dlasq2_(integer *, doublereal *, integer *);
852 extern doublereal dlamch_(char *);
859 extern /* Subroutine */ int dlarra_(integer *, doublereal *, doublereal *,
860 doublereal *, doublereal *, doublereal *, integer *, integer *,
861 integer *), dlarrb_(integer *, doublereal *, doublereal *,
862 integer *, integer *, doublereal *, doublereal *, integer *,
863 doublereal *, doublereal *, doublereal *, doublereal *, integer *,
864 doublereal *, doublereal *, integer *, integer *), dlarrc_(char *
865 , integer *, doublereal *, doublereal *, doublereal *, doublereal
866 *, doublereal *, integer *, integer *, integer *, integer *);
868 doublereal safmin, spdiam;
869 extern /* Subroutine */ int dlarrd_(char *, char *, integer *, doublereal
870 *, doublereal *, integer *, integer *, doublereal *, doublereal *,
871 doublereal *, doublereal *, doublereal *, doublereal *, integer *
872 , integer *, integer *, doublereal *, doublereal *, doublereal *,
873 doublereal *, integer *, integer *, doublereal *, integer *,
874 integer *), dlarrk_(integer *, integer *,
875 doublereal *, doublereal *, doublereal *, doublereal *,
876 doublereal *, doublereal *, doublereal *, doublereal *, integer *)
879 doublereal clwdth, isleft;
880 extern /* Subroutine */ int dlarnv_(integer *, integer *, integer *,
882 doublereal isrght, bsrtol, dpivot;
884 doublereal eps, tau, tmp, rtl;
889 /* -- LAPACK auxiliary routine (version 3.8.0) -- */
890 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
891 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
895 /* ===================================================================== */
898 /* Parameter adjustments */
915 /* Quick return if possible */
923 if (lsame_(range, "A")) {
925 } else if (lsame_(range, "V")) {
927 } else if (lsame_(range, "I")) {
931 /* Get machine constants */
932 safmin = dlamch_("S");
937 /* Treat case of 1x1 matrix for quick return */
939 if (irange == 1 || irange == 3 && d__[1] > *vl && d__[1] <= *vu ||
940 irange == 2 && *il == 1 && *iu == 1) {
943 /* The computation error of the eigenvalue is zero */
951 /* store the shift for the initial RRR, which is zero in this case */
955 /* General case: tridiagonal matrix of order > 1 */
957 /* Init WERR, WGAP. Compute Gerschgorin intervals and spectral diameter. */
958 /* Compute maximum off-diagonal entry and pivmin. */
965 for (i__ = 1; i__ <= i__1; ++i__) {
968 eabs = (d__1 = e[i__], abs(d__1));
973 gers[(i__ << 1) - 1] = d__[i__] - tmp1;
975 d__1 = gl, d__2 = gers[(i__ << 1) - 1];
976 gl = f2cmin(d__1,d__2);
977 gers[i__ * 2] = d__[i__] + tmp1;
979 d__1 = gu, d__2 = gers[i__ * 2];
980 gu = f2cmax(d__1,d__2);
984 /* The minimum pivot allowed in the Sturm sequence for T */
986 /* Computing 2nd power */
988 d__1 = 1., d__2 = d__3 * d__3;
989 *pivmin = safmin * f2cmax(d__1,d__2);
990 /* Compute spectral diameter. The Gerschgorin bounds give an */
991 /* estimate that is wrong by at most a factor of SQRT(2) */
993 /* Compute splitting points */
994 dlarra_(n, &d__[1], &e[1], &e2[1], spltol, &spdiam, nsplit, &isplit[1], &
996 /* Can force use of bisection instead of faster DQDS. */
997 /* Option left in the code for future multisection work. */
999 /* Initialize USEDQD, DQDS should be used for ALLRNG unless someone */
1000 /* explicitly wants bisection. */
1001 usedqd = irange == 1 && ! forceb;
1002 if (irange == 1 && ! forceb) {
1003 /* Set interval [VL,VU] that contains all eigenvalues */
1007 /* We call DLARRD to find crude approximations to the eigenvalues */
1008 /* in the desired range. In case IRANGE = INDRNG, we also obtain the */
1009 /* interval (VL,VU] that contains all the wanted eigenvalues. */
1010 /* An interval [LEFT,RIGHT] has converged if */
1011 /* RIGHT-LEFT.LT.RTOL*MAX(ABS(LEFT),ABS(RIGHT)) */
1012 /* DLARRD needs a WORK of size 4*N, IWORK of size 3*N */
1013 dlarrd_(range, "B", n, vl, vu, il, iu, &gers[1], &bsrtol, &d__[1], &e[
1014 1], &e2[1], pivmin, nsplit, &isplit[1], &mm, &w[1], &werr[1],
1015 vl, vu, &iblock[1], &indexw[1], &work[1], &iwork[1], &iinfo);
1020 /* Make sure that the entries M+1 to N in W, WERR, IBLOCK, INDEXW are 0 */
1022 for (i__ = mm + 1; i__ <= i__1; ++i__) {
1031 /* Loop over unreduced blocks */
1035 for (jblk = 1; jblk <= i__1; ++jblk) {
1036 iend = isplit[jblk];
1037 in = iend - ibegin + 1;
1040 if (irange == 1 || irange == 3 && d__[ibegin] > *vl && d__[ibegin]
1041 <= *vu || irange == 2 && iblock[wbegin] == jblk) {
1043 w[*m] = d__[ibegin];
1045 /* The gap for a single block doesn't matter for the later */
1046 /* algorithm and is assigned an arbitrary large value */
1052 /* E( IEND ) holds the shift for the initial RRR */
1058 /* Blocks of size larger than 1x1 */
1060 /* E( IEND ) will hold the shift for the initial RRR, for now set it =0 */
1063 /* Find local outer bounds GL,GU for the block */
1067 for (i__ = ibegin; i__ <= i__2; ++i__) {
1069 d__1 = gers[(i__ << 1) - 1];
1070 gl = f2cmin(d__1,gl);
1072 d__1 = gers[i__ * 2];
1073 gu = f2cmax(d__1,gu);
1077 if (! (irange == 1 && ! forceb)) {
1078 /* Count the number of eigenvalues in the current block. */
1081 for (i__ = wbegin; i__ <= i__2; ++i__) {
1082 if (iblock[i__] == jblk) {
1091 /* No eigenvalue in the current block lies in the desired range */
1092 /* E( IEND ) holds the shift for the initial RRR */
1097 /* Decide whether dqds or bisection is more efficient */
1098 usedqd = (doublereal) mb > in * .5 && ! forceb;
1099 wend = wbegin + mb - 1;
1100 /* Calculate gaps for the current block */
1101 /* In later stages, when representations for individual */
1102 /* eigenvalues are different, we use SIGMA = E( IEND ). */
1105 for (i__ = wbegin; i__ <= i__2; ++i__) {
1107 d__1 = 0., d__2 = w[i__ + 1] - werr[i__ + 1] - (w[i__] +
1109 wgap[i__] = f2cmax(d__1,d__2);
1113 d__1 = 0., d__2 = *vu - sigma - (w[wend] + werr[wend]);
1114 wgap[wend] = f2cmax(d__1,d__2);
1115 /* Find local index of the first and last desired evalue. */
1116 indl = indexw[wbegin];
1117 indu = indexw[wend];
1120 if (irange == 1 && ! forceb || usedqd) {
1122 /* Find approximations to the extremal eigenvalues of the block */
1123 dlarrk_(&in, &c__1, &gl, &gu, &d__[ibegin], &e2[ibegin], pivmin, &
1124 rtl, &tmp, &tmp1, &iinfo);
1130 d__2 = gl, d__3 = tmp - tmp1 - eps * 100. * (d__1 = tmp - tmp1,
1132 isleft = f2cmax(d__2,d__3);
1133 dlarrk_(&in, &in, &gl, &gu, &d__[ibegin], &e2[ibegin], pivmin, &
1134 rtl, &tmp, &tmp1, &iinfo);
1140 d__2 = gu, d__3 = tmp + tmp1 + eps * 100. * (d__1 = tmp + tmp1,
1142 isrght = f2cmin(d__2,d__3);
1143 /* Improve the estimate of the spectral diameter */
1144 spdiam = isrght - isleft;
1146 /* Case of bisection */
1147 /* Find approximations to the wanted extremal eigenvalues */
1149 d__2 = gl, d__3 = w[wbegin] - werr[wbegin] - eps * 100. * (d__1 =
1150 w[wbegin] - werr[wbegin], abs(d__1));
1151 isleft = f2cmax(d__2,d__3);
1153 d__2 = gu, d__3 = w[wend] + werr[wend] + eps * 100. * (d__1 = w[
1154 wend] + werr[wend], abs(d__1));
1155 isrght = f2cmin(d__2,d__3);
1157 /* Decide whether the base representation for the current block */
1158 /* L_JBLK D_JBLK L_JBLK^T = T_JBLK - sigma_JBLK I */
1159 /* should be on the left or the right end of the current block. */
1160 /* The strategy is to shift to the end which is "more populated" */
1161 /* Furthermore, decide whether to use DQDS for the computation of */
1162 /* the eigenvalue approximations at the end of DLARRE or bisection. */
1163 /* dqds is chosen if all eigenvalues are desired or the number of */
1164 /* eigenvalues to be computed is large compared to the blocksize. */
1165 if (irange == 1 && ! forceb) {
1166 /* If all the eigenvalues have to be computed, we use dqd */
1168 /* INDL is the local index of the first eigenvalue to compute */
1171 /* MB = number of eigenvalues to compute */
1173 wend = wbegin + mb - 1;
1174 /* Define 1/4 and 3/4 points of the spectrum */
1175 s1 = isleft + spdiam * .25;
1176 s2 = isrght - spdiam * .25;
1178 /* DLARRD has computed IBLOCK and INDEXW for each eigenvalue */
1179 /* approximation. */
1182 s1 = isleft + spdiam * .25;
1183 s2 = isrght - spdiam * .25;
1185 tmp = f2cmin(isrght,*vu) - f2cmax(isleft,*vl);
1186 s1 = f2cmax(isleft,*vl) + tmp * .25;
1187 s2 = f2cmin(isrght,*vu) - tmp * .25;
1190 /* Compute the negcount at the 1/4 and 3/4 points */
1192 dlarrc_("T", &in, &s1, &s2, &d__[ibegin], &e[ibegin], pivmin, &
1193 cnt, &cnt1, &cnt2, &iinfo);
1198 } else if (cnt1 - indl >= indu - cnt2) {
1199 if (irange == 1 && ! forceb) {
1200 sigma = f2cmax(isleft,gl);
1201 } else if (usedqd) {
1202 /* use Gerschgorin bound as shift to get pos def matrix */
1206 /* use approximation of the first desired eigenvalue of the */
1207 /* block as shift */
1208 sigma = f2cmax(isleft,*vl);
1212 if (irange == 1 && ! forceb) {
1213 sigma = f2cmin(isrght,gu);
1214 } else if (usedqd) {
1215 /* use Gerschgorin bound as shift to get neg def matrix */
1219 /* use approximation of the first desired eigenvalue of the */
1220 /* block as shift */
1221 sigma = f2cmin(isrght,*vu);
1225 /* An initial SIGMA has been chosen that will be used for computing */
1226 /* T - SIGMA I = L D L^T */
1227 /* Define the increment TAU of the shift in case the initial shift */
1228 /* needs to be refined to obtain a factorization with not too much */
1229 /* element growth. */
1231 /* The initial SIGMA was to the outer end of the spectrum */
1232 /* the matrix is definite and we need not retreat. */
1233 tau = spdiam * eps * *n + *pivmin * 2.;
1235 d__1 = tau, d__2 = eps * 2. * abs(sigma);
1236 tau = f2cmax(d__1,d__2);
1239 clwdth = w[wend] + werr[wend] - w[wbegin] - werr[wbegin];
1240 avgap = (d__1 = clwdth / (doublereal) (wend - wbegin), abs(
1244 d__1 = wgap[wbegin];
1245 tau = f2cmax(d__1,avgap) * .5;
1247 d__1 = tau, d__2 = werr[wbegin];
1248 tau = f2cmax(d__1,d__2);
1251 d__1 = wgap[wend - 1];
1252 tau = f2cmax(d__1,avgap) * .5;
1254 d__1 = tau, d__2 = werr[wend];
1255 tau = f2cmax(d__1,d__2);
1262 for (idum = 1; idum <= 6; ++idum) {
1263 /* Compute L D L^T factorization of tridiagonal matrix T - sigma I. */
1264 /* Store D in WORK(1:IN), L in WORK(IN+1:2*IN), and reciprocals of */
1265 /* pivots in WORK(2*IN+1:3*IN) */
1266 dpivot = d__[ibegin] - sigma;
1268 dmax__ = abs(work[1]);
1271 for (i__ = 1; i__ <= i__2; ++i__) {
1272 work[(in << 1) + i__] = 1. / work[i__];
1273 tmp = e[j] * work[(in << 1) + i__];
1274 work[in + i__] = tmp;
1275 dpivot = d__[j + 1] - sigma - tmp * e[j];
1276 work[i__ + 1] = dpivot;
1278 d__1 = dmax__, d__2 = abs(dpivot);
1279 dmax__ = f2cmax(d__1,d__2);
1283 /* check for element growth */
1284 if (dmax__ > spdiam * 64.) {
1289 if (usedqd && ! norep) {
1290 /* Ensure the definiteness of the representation */
1291 /* All entries of D (of L D L^T) must have the same sign */
1293 for (i__ = 1; i__ <= i__2; ++i__) {
1294 tmp = sgndef * work[i__];
1302 /* Note that in the case of IRANGE=ALLRNG, we use the Gerschgorin */
1303 /* shift which makes the matrix definite. So we should end up */
1304 /* here really only in the case of IRANGE = VALRNG or INDRNG. */
1307 /* The fudged Gerschgorin shift should succeed */
1308 sigma = gl - spdiam * 2. * eps * *n - *pivmin * 4.;
1310 sigma = gu + spdiam * 2. * eps * *n + *pivmin * 4.;
1313 sigma -= sgndef * tau;
1317 /* an initial RRR is found */
1322 /* if the program reaches this point, no base representation could be */
1323 /* found in MAXTRY iterations. */
1327 /* At this point, we have found an initial base representation */
1328 /* T - SIGMA I = L D L^T with not too much element growth. */
1329 /* Store the shift. */
1331 /* Store D and L. */
1332 dcopy_(&in, &work[1], &c__1, &d__[ibegin], &c__1);
1334 dcopy_(&i__2, &work[in + 1], &c__1, &e[ibegin], &c__1);
1337 /* Perturb each entry of the base representation by a small */
1338 /* (but random) relative amount to overcome difficulties with */
1339 /* glued matrices. */
1341 for (i__ = 1; i__ <= 4; ++i__) {
1345 i__2 = (in << 1) - 1;
1346 dlarnv_(&c__2, iseed, &i__2, &work[1]);
1348 for (i__ = 1; i__ <= i__2; ++i__) {
1349 d__[ibegin + i__ - 1] *= eps * 8. * work[i__] + 1.;
1350 e[ibegin + i__ - 1] *= eps * 8. * work[in + i__] + 1.;
1353 d__[iend] *= eps * 4. * work[in] + 1.;
1357 /* Don't update the Gerschgorin intervals because keeping track */
1358 /* of the updates would be too much work in DLARRV. */
1359 /* We update W instead and use it to locate the proper Gerschgorin */
1361 /* Compute the required eigenvalues of L D L' by bisection or dqds */
1363 /* If DLARRD has been used, shift the eigenvalue approximations */
1364 /* according to their representation. This is necessary for */
1365 /* a uniform DLARRV since dqds computes eigenvalues of the */
1366 /* shifted representation. In DLARRV, W will always hold the */
1367 /* UNshifted eigenvalue approximation. */
1369 for (j = wbegin; j <= i__2; ++j) {
1371 werr[j] += (d__1 = w[j], abs(d__1)) * eps;
1374 /* call DLARRB to reduce eigenvalue error of the approximations */
1377 for (i__ = ibegin; i__ <= i__2; ++i__) {
1378 /* Computing 2nd power */
1380 work[i__] = d__[i__] * (d__1 * d__1);
1383 /* use bisection to find EV from INDL to INDU */
1385 dlarrb_(&in, &d__[ibegin], &work[ibegin], &indl, &indu, rtol1,
1386 rtol2, &i__2, &w[wbegin], &wgap[wbegin], &werr[wbegin], &
1387 work[(*n << 1) + 1], &iwork[1], pivmin, &spdiam, &in, &
1393 /* DLARRB computes all gaps correctly except for the last one */
1394 /* Record distance to VU/GU */
1396 d__1 = 0., d__2 = *vu - sigma - (w[wend] + werr[wend]);
1397 wgap[wend] = f2cmax(d__1,d__2);
1399 for (i__ = indl; i__ <= i__2; ++i__) {
1406 /* Call dqds to get all eigs (and then possibly delete unwanted */
1408 /* Note that dqds finds the eigenvalues of the L D L^T representation */
1409 /* of T to high relative accuracy. High relative accuracy */
1410 /* might be lost when the shift of the RRR is subtracted to obtain */
1411 /* the eigenvalues of T. However, T is not guaranteed to define its */
1412 /* eigenvalues to high relative accuracy anyway. */
1413 /* Set RTOL to the order of the tolerance used in DLASQ2 */
1414 /* This is an ESTIMATED error, the worst case bound is 4*N*EPS */
1415 /* which is usually too large and requires unnecessary work to be */
1416 /* done by bisection when computing the eigenvectors */
1417 rtol = log((doublereal) in) * 4. * eps;
1420 for (i__ = 1; i__ <= i__2; ++i__) {
1421 work[(i__ << 1) - 1] = (d__1 = d__[j], abs(d__1));
1422 work[i__ * 2] = e[j] * e[j] * work[(i__ << 1) - 1];
1426 work[(in << 1) - 1] = (d__1 = d__[iend], abs(d__1));
1428 dlasq2_(&in, &work[1], &iinfo);
1430 /* If IINFO = -5 then an index is part of a tight cluster */
1431 /* and should be changed. The index is in IWORK(1) and the */
1432 /* gap is in WORK(N+1) */
1436 /* Test that all eigenvalues are positive as expected */
1438 for (i__ = 1; i__ <= i__2; ++i__) {
1439 if (work[i__] < 0.) {
1448 for (i__ = indl; i__ <= i__2; ++i__) {
1450 w[*m] = work[in - i__ + 1];
1457 for (i__ = indl; i__ <= i__2; ++i__) {
1466 for (i__ = *m - mb + 1; i__ <= i__2; ++i__) {
1467 /* the value of RTOL below should be the tolerance in DLASQ2 */
1468 werr[i__] = rtol * (d__1 = w[i__], abs(d__1));
1472 for (i__ = *m - mb + 1; i__ <= i__2; ++i__) {
1473 /* compute the right gap between the intervals */
1475 d__1 = 0., d__2 = w[i__ + 1] - werr[i__ + 1] - (w[i__] + werr[
1477 wgap[i__] = f2cmax(d__1,d__2);
1481 d__1 = 0., d__2 = *vu - sigma - (w[*m] + werr[*m]);
1482 wgap[*m] = f2cmax(d__1,d__2);
1484 /* proceed with next block */