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__13 = 13;
516 static integer c__15 = 15;
517 static integer c_n1 = -1;
518 static integer c__12 = 12;
519 static integer c__14 = 14;
520 static integer c__16 = 16;
521 static logical c_false = FALSE_;
522 static integer c__1 = 1;
523 static integer c__3 = 3;
525 /* > \brief \b CLAQR4 computes the eigenvalues of a Hessenberg matrix, and optionally the matrices from the Sc
526 hur decomposition. */
528 /* =========== DOCUMENTATION =========== */
530 /* Online html documentation available at */
531 /* http://www.netlib.org/lapack/explore-html/ */
534 /* > Download CLAQR4 + dependencies */
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/claqr4.
538 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/claqr4.
541 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/claqr4.
549 /* SUBROUTINE CLAQR4( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ, */
550 /* IHIZ, Z, LDZ, WORK, LWORK, INFO ) */
552 /* INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, LWORK, N */
553 /* LOGICAL WANTT, WANTZ */
554 /* COMPLEX H( LDH, * ), W( * ), WORK( * ), Z( LDZ, * ) */
558 /* > \par Purpose: */
563 /* > CLAQR4 implements one level of recursion for CLAQR0. */
564 /* > It is a complete implementation of the small bulge multi-shift */
565 /* > QR algorithm. It may be called by CLAQR0 and, for large enough */
566 /* > deflation window size, it may be called by CLAQR3. This */
567 /* > subroutine is identical to CLAQR0 except that it calls CLAQR2 */
568 /* > instead of CLAQR3. */
570 /* > CLAQR4 computes the eigenvalues of a Hessenberg matrix H */
571 /* > and, optionally, the matrices T and Z from the Schur decomposition */
572 /* > H = Z T Z**H, where T is an upper triangular matrix (the */
573 /* > Schur form), and Z is the unitary matrix of Schur vectors. */
575 /* > Optionally Z may be postmultiplied into an input unitary */
576 /* > matrix Q so that this routine can give the Schur factorization */
577 /* > of a matrix A which has been reduced to the Hessenberg form H */
578 /* > by the unitary matrix Q: A = Q*H*Q**H = (QZ)*H*(QZ)**H. */
584 /* > \param[in] WANTT */
586 /* > WANTT is LOGICAL */
587 /* > = .TRUE. : the full Schur form T is required; */
588 /* > = .FALSE.: only eigenvalues are required. */
591 /* > \param[in] WANTZ */
593 /* > WANTZ is LOGICAL */
594 /* > = .TRUE. : the matrix of Schur vectors Z is required; */
595 /* > = .FALSE.: Schur vectors are not required. */
601 /* > The order of the matrix H. N >= 0. */
604 /* > \param[in] ILO */
606 /* > ILO is INTEGER */
609 /* > \param[in] IHI */
611 /* > IHI is INTEGER */
612 /* > It is assumed that H is already upper triangular in rows */
613 /* > and columns 1:ILO-1 and IHI+1:N and, if ILO > 1, */
614 /* > H(ILO,ILO-1) is zero. ILO and IHI are normally set by a */
615 /* > previous call to CGEBAL, and then passed to CGEHRD when the */
616 /* > matrix output by CGEBAL is reduced to Hessenberg form. */
617 /* > Otherwise, ILO and IHI should be set to 1 and N, */
618 /* > respectively. If N > 0, then 1 <= ILO <= IHI <= N. */
619 /* > If N = 0, then ILO = 1 and IHI = 0. */
622 /* > \param[in,out] H */
624 /* > H is COMPLEX array, dimension (LDH,N) */
625 /* > On entry, the upper Hessenberg matrix H. */
626 /* > On exit, if INFO = 0 and WANTT is .TRUE., then H */
627 /* > contains the upper triangular matrix T from the Schur */
628 /* > decomposition (the Schur form). If INFO = 0 and WANT is */
629 /* > .FALSE., then the contents of H are unspecified on exit. */
630 /* > (The output value of H when INFO > 0 is given under the */
631 /* > description of INFO below.) */
633 /* > This subroutine may explicitly set H(i,j) = 0 for i > j and */
634 /* > j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N. */
637 /* > \param[in] LDH */
639 /* > LDH is INTEGER */
640 /* > The leading dimension of the array H. LDH >= f2cmax(1,N). */
643 /* > \param[out] W */
645 /* > W is COMPLEX array, dimension (N) */
646 /* > The computed eigenvalues of H(ILO:IHI,ILO:IHI) are stored */
647 /* > in W(ILO:IHI). If WANTT is .TRUE., then the eigenvalues are */
648 /* > stored in the same order as on the diagonal of the Schur */
649 /* > form returned in H, with W(i) = H(i,i). */
652 /* > \param[in] ILOZ */
654 /* > ILOZ is INTEGER */
657 /* > \param[in] IHIZ */
659 /* > IHIZ is INTEGER */
660 /* > Specify the rows of Z to which transformations must be */
661 /* > applied if WANTZ is .TRUE.. */
662 /* > 1 <= ILOZ <= ILO; IHI <= IHIZ <= N. */
665 /* > \param[in,out] Z */
667 /* > Z is COMPLEX array, dimension (LDZ,IHI) */
668 /* > If WANTZ is .FALSE., then Z is not referenced. */
669 /* > If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is */
670 /* > replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the */
671 /* > orthogonal Schur factor of H(ILO:IHI,ILO:IHI). */
672 /* > (The output value of Z when INFO > 0 is given under */
673 /* > the description of INFO below.) */
676 /* > \param[in] LDZ */
678 /* > LDZ is INTEGER */
679 /* > The leading dimension of the array Z. if WANTZ is .TRUE. */
680 /* > then LDZ >= MAX(1,IHIZ). Otherwise, LDZ >= 1. */
683 /* > \param[out] WORK */
685 /* > WORK is COMPLEX array, dimension LWORK */
686 /* > On exit, if LWORK = -1, WORK(1) returns an estimate of */
687 /* > the optimal value for LWORK. */
690 /* > \param[in] LWORK */
692 /* > LWORK is INTEGER */
693 /* > The dimension of the array WORK. LWORK >= f2cmax(1,N) */
694 /* > is sufficient, but LWORK typically as large as 6*N may */
695 /* > be required for optimal performance. A workspace query */
696 /* > to determine the optimal workspace size is recommended. */
698 /* > If LWORK = -1, then CLAQR4 does a workspace query. */
699 /* > In this case, CLAQR4 checks the input parameters and */
700 /* > estimates the optimal workspace size for the given */
701 /* > values of N, ILO and IHI. The estimate is returned */
702 /* > in WORK(1). No error message related to LWORK is */
703 /* > issued by XERBLA. Neither H nor Z are accessed. */
706 /* > \param[out] INFO */
708 /* > INFO is INTEGER */
709 /* > = 0: successful exit */
710 /* > > 0: if INFO = i, CLAQR4 failed to compute all of */
711 /* > the eigenvalues. Elements 1:ilo-1 and i+1:n of WR */
712 /* > and WI contain those eigenvalues which have been */
713 /* > successfully computed. (Failures are rare.) */
715 /* > If INFO > 0 and WANT is .FALSE., then on exit, */
716 /* > the remaining unconverged eigenvalues are the eigen- */
717 /* > values of the upper Hessenberg matrix rows and */
718 /* > columns ILO through INFO of the final, output */
721 /* > If INFO > 0 and WANTT is .TRUE., then on exit */
723 /* > (*) (initial value of H)*U = U*(final value of H) */
725 /* > where U is a unitary matrix. The final */
726 /* > value of H is upper Hessenberg and triangular in */
727 /* > rows and columns INFO+1 through IHI. */
729 /* > If INFO > 0 and WANTZ is .TRUE., then on exit */
731 /* > (final value of Z(ILO:IHI,ILOZ:IHIZ) */
732 /* > = (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U */
734 /* > where U is the unitary matrix in (*) (regard- */
735 /* > less of the value of WANTT.) */
737 /* > If INFO > 0 and WANTZ is .FALSE., then Z is not */
744 /* > \author Univ. of Tennessee */
745 /* > \author Univ. of California Berkeley */
746 /* > \author Univ. of Colorado Denver */
747 /* > \author NAG Ltd. */
749 /* > \date June 2017 */
751 /* > \ingroup complexOTHERauxiliary */
753 /* > \par Contributors: */
754 /* ================== */
756 /* > Karen Braman and Ralph Byers, Department of Mathematics, */
757 /* > University of Kansas, USA */
759 /* > \par References: */
760 /* ================ */
762 /* > K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
763 /* > Algorithm Part I: Maintaining Well Focused Shifts, and Level 3 */
764 /* > Performance, SIAM Journal of Matrix Analysis, volume 23, pages */
765 /* > 929--947, 2002. */
767 /* > K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
768 /* > Algorithm Part II: Aggressive Early Deflation, SIAM Journal */
769 /* > of Matrix Analysis, volume 23, pages 948--973, 2002. */
771 /* ===================================================================== */
772 /* Subroutine */ int claqr4_(logical *wantt, logical *wantz, integer *n,
773 integer *ilo, integer *ihi, complex *h__, integer *ldh, complex *w,
774 integer *iloz, integer *ihiz, complex *z__, integer *ldz, complex *
775 work, integer *lwork, integer *info)
777 /* System generated locals */
778 integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
779 real r__1, r__2, r__3, r__4, r__5, r__6, r__7, r__8;
780 complex q__1, q__2, q__3, q__4, q__5;
782 /* Local variables */
783 integer ndec, ndfl, kbot, nmin;
786 complex zdum[1] /* was [1][1] */;
787 integer kacc22, i__, k;
789 integer itmax, nsmax, nwmax, kwtop;
790 extern /* Subroutine */ int claqr2_(logical *, logical *, integer *,
791 integer *, integer *, integer *, complex *, integer *, integer *,
792 integer *, complex *, integer *, integer *, integer *, complex *,
793 complex *, integer *, integer *, complex *, integer *, integer *,
794 complex *, integer *, complex *, integer *), claqr5_(logical *,
795 logical *, integer *, integer *, integer *, integer *, integer *,
796 complex *, complex *, integer *, integer *, integer *, complex *,
797 integer *, complex *, integer *, complex *, integer *, integer *,
798 complex *, integer *, integer *, complex *, integer *);
799 complex aa, bb, cc, dd;
800 integer ld, nh, nibble, it, ks, kt, ku, kv, ls, ns, nw;
801 extern /* Subroutine */ int clahqr_(logical *, logical *, integer *,
802 integer *, integer *, complex *, integer *, complex *, integer *,
803 integer *, complex *, integer *, integer *), clacpy_(char *,
804 integer *, integer *, complex *, integer *, complex *, integer *);
805 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
806 integer *, integer *, ftnlen, ftnlen);
813 integer inf, kdu, nho, nve, kwh, nsr, nwr, kwv;
816 /* -- LAPACK auxiliary routine (version 3.7.1) -- */
817 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
818 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
823 /* ================================================================ */
826 /* ==== Matrices of order NTINY or smaller must be processed by */
827 /* . CLAHQR because of insufficient subdiagonal scratch space. */
828 /* . (This is a hard limit.) ==== */
830 /* ==== Exceptional deflation windows: try to cure rare */
831 /* . slow convergence by varying the size of the */
832 /* . deflation window after KEXNW iterations. ==== */
834 /* ==== Exceptional shifts: try to cure rare slow convergence */
835 /* . with ad-hoc exceptional shifts every KEXSH iterations. */
838 /* ==== The constant WILK1 is used to form the exceptional */
840 /* Parameter adjustments */
842 h_offset = 1 + h_dim1 * 1;
846 z_offset = 1 + z_dim1 * 1;
853 /* ==== Quick return for N = 0: nothing to do. ==== */
856 work[1].r = 1.f, work[1].i = 0.f;
862 /* ==== Tiny matrices must use CLAHQR. ==== */
866 clahqr_(wantt, wantz, n, ilo, ihi, &h__[h_offset], ldh, &w[1],
867 iloz, ihiz, &z__[z_offset], ldz, info);
871 /* ==== Use small bulge multi-shift QR with aggressive early */
872 /* . deflation on larger-than-tiny matrices. ==== */
874 /* ==== Hope for the best. ==== */
878 /* ==== Set up job flags for ILAENV. ==== */
881 *(unsigned char *)jbcmpz = 'S';
883 *(unsigned char *)jbcmpz = 'E';
886 *(unsigned char *)&jbcmpz[1] = 'V';
888 *(unsigned char *)&jbcmpz[1] = 'N';
891 /* ==== NWR = recommended deflation window size. At this */
892 /* . point, N .GT. NTINY = 15, so there is enough */
893 /* . subdiagonal workspace for NWR.GE.2 as required. */
894 /* . (In fact, there is enough subdiagonal space for */
895 /* . NWR.GE.4.) ==== */
897 nwr = ilaenv_(&c__13, "CLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
901 i__1 = *ihi - *ilo + 1, i__2 = (*n - 1) / 3, i__1 = f2cmin(i__1,i__2);
902 nwr = f2cmin(i__1,nwr);
904 /* ==== NSR = recommended number of simultaneous shifts. */
905 /* . At this point N .GT. NTINY = 15, so there is at */
906 /* . enough subdiagonal workspace for NSR to be even */
907 /* . and greater than or equal to two as required. ==== */
909 nsr = ilaenv_(&c__15, "CLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
912 i__1 = nsr, i__2 = (*n - 3) / 6, i__1 = f2cmin(i__1,i__2), i__2 = *ihi -
914 nsr = f2cmin(i__1,i__2);
916 i__1 = 2, i__2 = nsr - nsr % 2;
917 nsr = f2cmax(i__1,i__2);
919 /* ==== Estimate optimal workspace ==== */
921 /* ==== Workspace query call to CLAQR2 ==== */
924 claqr2_(wantt, wantz, n, ilo, ihi, &i__1, &h__[h_offset], ldh, iloz,
925 ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[h_offset],
926 ldh, n, &h__[h_offset], ldh, n, &h__[h_offset], ldh, &work[1],
929 /* ==== Optimal workspace = MAX(CLAQR5, CLAQR2) ==== */
932 i__1 = nsr * 3 / 2, i__2 = (integer) work[1].r;
933 lwkopt = f2cmax(i__1,i__2);
935 /* ==== Quick return in case of workspace query. ==== */
938 r__1 = (real) lwkopt;
939 q__1.r = r__1, q__1.i = 0.f;
940 work[1].r = q__1.r, work[1].i = q__1.i;
944 /* ==== CLAHQR/CLAQR0 crossover point ==== */
946 nmin = ilaenv_(&c__12, "CLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)
948 nmin = f2cmax(15,nmin);
950 /* ==== Nibble crossover point ==== */
952 nibble = ilaenv_(&c__14, "CLAQR4", jbcmpz, n, ilo, ihi, lwork, (
953 ftnlen)6, (ftnlen)2);
954 nibble = f2cmax(0,nibble);
956 /* ==== Accumulate reflections during ttswp? Use block */
957 /* . 2-by-2 structure during matrix-matrix multiply? ==== */
959 kacc22 = ilaenv_(&c__16, "CLAQR4", jbcmpz, n, ilo, ihi, lwork, (
960 ftnlen)6, (ftnlen)2);
961 kacc22 = f2cmax(0,kacc22);
962 kacc22 = f2cmin(2,kacc22);
964 /* ==== NWMAX = the largest possible deflation window for */
965 /* . which there is sufficient workspace. ==== */
968 i__1 = (*n - 1) / 3, i__2 = *lwork / 2;
969 nwmax = f2cmin(i__1,i__2);
972 /* ==== NSMAX = the Largest number of simultaneous shifts */
973 /* . for which there is sufficient workspace. ==== */
976 i__1 = (*n - 3) / 6, i__2 = (*lwork << 1) / 3;
977 nsmax = f2cmin(i__1,i__2);
980 /* ==== NDFL: an iteration count restarted at deflation. ==== */
984 /* ==== ITMAX = iteration limit ==== */
987 i__1 = 10, i__2 = *ihi - *ilo + 1;
988 itmax = 30 * f2cmax(i__1,i__2);
990 /* ==== Last row and column in the active block ==== */
994 /* ==== Main Loop ==== */
997 for (it = 1; it <= i__1; ++it) {
999 /* ==== Done when KBOT falls below ILO ==== */
1005 /* ==== Locate active block ==== */
1008 for (k = kbot; k >= i__2; --k) {
1009 i__3 = k + (k - 1) * h_dim1;
1010 if (h__[i__3].r == 0.f && h__[i__3].i == 0.f) {
1019 /* ==== Select deflation window size: */
1020 /* . Typical Case: */
1021 /* . If possible and advisable, nibble the entire */
1022 /* . active block. If not, use size MIN(NWR,NWMAX) */
1023 /* . or MIN(NWR+1,NWMAX) depending upon which has */
1024 /* . the smaller corresponding subdiagonal entry */
1025 /* . (a heuristic). */
1027 /* . Exceptional Case: */
1028 /* . If there have been no deflations in KEXNW or */
1029 /* . more iterations, then vary the deflation window */
1030 /* . size. At first, because, larger windows are, */
1031 /* . in general, more powerful than smaller ones, */
1032 /* . rapidly increase the window to the maximum possible. */
1033 /* . Then, gradually reduce the window size. ==== */
1035 nh = kbot - ktop + 1;
1036 nwupbd = f2cmin(nh,nwmax);
1038 nw = f2cmin(nwupbd,nwr);
1041 i__2 = nwupbd, i__3 = nw << 1;
1042 nw = f2cmin(i__2,i__3);
1048 kwtop = kbot - nw + 1;
1049 i__2 = kwtop + (kwtop - 1) * h_dim1;
1050 i__3 = kwtop - 1 + (kwtop - 2) * h_dim1;
1051 if ((r__1 = h__[i__2].r, abs(r__1)) + (r__2 = r_imag(&h__[
1052 kwtop + (kwtop - 1) * h_dim1]), abs(r__2)) > (
1053 r__3 = h__[i__3].r, abs(r__3)) + (r__4 = r_imag(&
1054 h__[kwtop - 1 + (kwtop - 2) * h_dim1]), abs(r__4))
1062 } else if (ndec >= 0 || nw >= nwupbd) {
1064 if (nw - ndec < 2) {
1070 /* ==== Aggressive early deflation: */
1071 /* . split workspace under the subdiagonal into */
1072 /* . - an nw-by-nw work array V in the lower */
1073 /* . left-hand-corner, */
1074 /* . - an NW-by-at-least-NW-but-more-is-better */
1075 /* . (NW-by-NHO) horizontal work array along */
1076 /* . the bottom edge, */
1077 /* . - an at-least-NW-but-more-is-better (NHV-by-NW) */
1078 /* . vertical work array along the left-hand-edge. */
1083 nho = *n - nw - 1 - kt + 1;
1085 nve = *n - nw - kwv + 1;
1087 /* ==== Aggressive early deflation ==== */
1089 claqr2_(wantt, wantz, n, &ktop, &kbot, &nw, &h__[h_offset], ldh,
1090 iloz, ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[kv
1091 + h_dim1], ldh, &nho, &h__[kv + kt * h_dim1], ldh, &nve, &
1092 h__[kwv + h_dim1], ldh, &work[1], lwork);
1094 /* ==== Adjust KBOT accounting for new deflations. ==== */
1098 /* ==== KS points to the shifts. ==== */
1102 /* ==== Skip an expensive QR sweep if there is a (partly */
1103 /* . heuristic) reason to expect that many eigenvalues */
1104 /* . will deflate without it. Here, the QR sweep is */
1105 /* . skipped if many eigenvalues have just been deflated */
1106 /* . or if the remaining active block is small. */
1108 if (ld == 0 || ld * 100 <= nw * nibble && kbot - ktop + 1 > f2cmin(
1111 /* ==== NS = nominal number of simultaneous shifts. */
1112 /* . This may be lowered (slightly) if CLAQR2 */
1113 /* . did not provide that many shifts. ==== */
1117 i__4 = 2, i__5 = kbot - ktop;
1118 i__2 = f2cmin(nsmax,nsr), i__3 = f2cmax(i__4,i__5);
1119 ns = f2cmin(i__2,i__3);
1122 /* ==== If there have been no deflations */
1123 /* . in a multiple of KEXSH iterations, */
1124 /* . then try exceptional shifts. */
1125 /* . Otherwise use shifts provided by */
1126 /* . CLAQR2 above or from the eigenvalues */
1127 /* . of a trailing principal submatrix. ==== */
1129 if (ndfl % 6 == 0) {
1132 for (i__ = kbot; i__ >= i__2; i__ += -2) {
1134 i__4 = i__ + i__ * h_dim1;
1135 i__5 = i__ + (i__ - 1) * h_dim1;
1136 r__3 = ((r__1 = h__[i__5].r, abs(r__1)) + (r__2 =
1137 r_imag(&h__[i__ + (i__ - 1) * h_dim1]), abs(
1139 q__1.r = h__[i__4].r + r__3, q__1.i = h__[i__4].i;
1140 w[i__3].r = q__1.r, w[i__3].i = q__1.i;
1143 w[i__3].r = w[i__4].r, w[i__3].i = w[i__4].i;
1148 /* ==== Got NS/2 or fewer shifts? Use CLAHQR */
1149 /* . on a trailing principal submatrix to */
1150 /* . get more. (Since NS.LE.NSMAX.LE.(N-3)/6, */
1151 /* . there is enough space below the subdiagonal */
1152 /* . to fit an NS-by-NS scratch array.) ==== */
1154 if (kbot - ks + 1 <= ns / 2) {
1157 clacpy_("A", &ns, &ns, &h__[ks + ks * h_dim1], ldh, &
1158 h__[kt + h_dim1], ldh);
1159 clahqr_(&c_false, &c_false, &ns, &c__1, &ns, &h__[kt
1160 + h_dim1], ldh, &w[ks], &c__1, &c__1, zdum, &
1164 /* ==== In case of a rare QR failure use */
1165 /* . eigenvalues of the trailing 2-by-2 */
1166 /* . principal submatrix. Scale to avoid */
1167 /* . overflows, underflows and subnormals. */
1168 /* . (The scale factor S can not be zero, */
1169 /* . because H(KBOT,KBOT-1) is nonzero.) ==== */
1172 i__2 = kbot - 1 + (kbot - 1) * h_dim1;
1173 i__3 = kbot + (kbot - 1) * h_dim1;
1174 i__4 = kbot - 1 + kbot * h_dim1;
1175 i__5 = kbot + kbot * h_dim1;
1176 s = (r__1 = h__[i__2].r, abs(r__1)) + (r__2 =
1177 r_imag(&h__[kbot - 1 + (kbot - 1) *
1178 h_dim1]), abs(r__2)) + ((r__3 = h__[i__3]
1179 .r, abs(r__3)) + (r__4 = r_imag(&h__[kbot
1180 + (kbot - 1) * h_dim1]), abs(r__4))) + ((
1181 r__5 = h__[i__4].r, abs(r__5)) + (r__6 =
1182 r_imag(&h__[kbot - 1 + kbot * h_dim1]),
1183 abs(r__6))) + ((r__7 = h__[i__5].r, abs(
1184 r__7)) + (r__8 = r_imag(&h__[kbot + kbot *
1185 h_dim1]), abs(r__8)));
1186 i__2 = kbot - 1 + (kbot - 1) * h_dim1;
1187 q__1.r = h__[i__2].r / s, q__1.i = h__[i__2].i /
1189 aa.r = q__1.r, aa.i = q__1.i;
1190 i__2 = kbot + (kbot - 1) * h_dim1;
1191 q__1.r = h__[i__2].r / s, q__1.i = h__[i__2].i /
1193 cc.r = q__1.r, cc.i = q__1.i;
1194 i__2 = kbot - 1 + kbot * h_dim1;
1195 q__1.r = h__[i__2].r / s, q__1.i = h__[i__2].i /
1197 bb.r = q__1.r, bb.i = q__1.i;
1198 i__2 = kbot + kbot * h_dim1;
1199 q__1.r = h__[i__2].r / s, q__1.i = h__[i__2].i /
1201 dd.r = q__1.r, dd.i = q__1.i;
1202 q__2.r = aa.r + dd.r, q__2.i = aa.i + dd.i;
1203 q__1.r = q__2.r / 2.f, q__1.i = q__2.i / 2.f;
1204 tr2.r = q__1.r, tr2.i = q__1.i;
1205 q__3.r = aa.r - tr2.r, q__3.i = aa.i - tr2.i;
1206 q__4.r = dd.r - tr2.r, q__4.i = dd.i - tr2.i;
1207 q__2.r = q__3.r * q__4.r - q__3.i * q__4.i,
1208 q__2.i = q__3.r * q__4.i + q__3.i *
1210 q__5.r = bb.r * cc.r - bb.i * cc.i, q__5.i = bb.r
1211 * cc.i + bb.i * cc.r;
1212 q__1.r = q__2.r - q__5.r, q__1.i = q__2.i -
1214 det.r = q__1.r, det.i = q__1.i;
1215 q__2.r = -det.r, q__2.i = -det.i;
1216 c_sqrt(&q__1, &q__2);
1217 rtdisc.r = q__1.r, rtdisc.i = q__1.i;
1219 q__2.r = tr2.r + rtdisc.r, q__2.i = tr2.i +
1221 q__1.r = s * q__2.r, q__1.i = s * q__2.i;
1222 w[i__2].r = q__1.r, w[i__2].i = q__1.i;
1224 q__2.r = tr2.r - rtdisc.r, q__2.i = tr2.i -
1226 q__1.r = s * q__2.r, q__1.i = s * q__2.i;
1227 w[i__2].r = q__1.r, w[i__2].i = q__1.i;
1233 if (kbot - ks + 1 > ns) {
1235 /* ==== Sort the shifts (Helps a little) ==== */
1239 for (k = kbot; k >= i__2; --k) {
1245 for (i__ = ks; i__ <= i__3; ++i__) {
1248 if ((r__1 = w[i__4].r, abs(r__1)) + (r__2 =
1249 r_imag(&w[i__]), abs(r__2)) < (r__3 =
1250 w[i__5].r, abs(r__3)) + (r__4 =
1251 r_imag(&w[i__ + 1]), abs(r__4))) {
1254 swap.r = w[i__4].r, swap.i = w[i__4].i;
1257 w[i__4].r = w[i__5].r, w[i__4].i = w[i__5]
1260 w[i__4].r = swap.r, w[i__4].i = swap.i;
1271 /* ==== If there are only two shifts, then use */
1272 /* . only one. ==== */
1274 if (kbot - ks + 1 == 2) {
1276 i__3 = kbot + kbot * h_dim1;
1277 q__2.r = w[i__2].r - h__[i__3].r, q__2.i = w[i__2].i -
1279 q__1.r = q__2.r, q__1.i = q__2.i;
1281 i__5 = kbot + kbot * h_dim1;
1282 q__4.r = w[i__4].r - h__[i__5].r, q__4.i = w[i__4].i -
1284 q__3.r = q__4.r, q__3.i = q__4.i;
1285 if ((r__1 = q__1.r, abs(r__1)) + (r__2 = r_imag(&q__1),
1286 abs(r__2)) < (r__3 = q__3.r, abs(r__3)) + (r__4 =
1287 r_imag(&q__3), abs(r__4))) {
1290 w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
1294 w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
1298 /* ==== Use up to NS of the the smallest magnitude */
1299 /* . shifts. If there aren't NS shifts available, */
1300 /* . then use them all, possibly dropping one to */
1301 /* . make the number of shifts even. ==== */
1304 i__2 = ns, i__3 = kbot - ks + 1;
1305 ns = f2cmin(i__2,i__3);
1309 /* ==== Small-bulge multi-shift QR sweep: */
1310 /* . split workspace under the subdiagonal into */
1311 /* . - a KDU-by-KDU work array U in the lower */
1312 /* . left-hand-corner, */
1313 /* . - a KDU-by-at-least-KDU-but-more-is-better */
1314 /* . (KDU-by-NHo) horizontal work array WH along */
1315 /* . the bottom edge, */
1316 /* . - and an at-least-KDU-but-more-is-better-by-KDU */
1317 /* . (NVE-by-KDU) vertical work WV arrow along */
1318 /* . the left-hand-edge. ==== */
1323 nho = *n - kdu - 3 - (kdu + 1) + 1;
1325 nve = *n - kdu - kwv + 1;
1327 /* ==== Small-bulge multi-shift QR sweep ==== */
1329 claqr5_(wantt, wantz, &kacc22, n, &ktop, &kbot, &ns, &w[ks], &
1330 h__[h_offset], ldh, iloz, ihiz, &z__[z_offset], ldz, &
1331 work[1], &c__3, &h__[ku + h_dim1], ldh, &nve, &h__[
1332 kwv + h_dim1], ldh, &nho, &h__[ku + kwh * h_dim1],
1336 /* ==== Note progress (or the lack of it). ==== */
1344 /* ==== End of main loop ==== */
1348 /* ==== Iteration limit exceeded. Set INFO to show where */
1349 /* . the problem occurred and exit. ==== */
1356 /* ==== Return the optimal value of LWORK. ==== */
1358 r__1 = (real) lwkopt;
1359 q__1.r = r__1, q__1.i = 0.f;
1360 work[1].r = q__1.r, work[1].i = q__1.i;
1362 /* ==== End of CLAQR4 ==== */