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]/Cd(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 ZLAQR4 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 ZLAQR4 + dependencies */
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlaqr4.
538 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlaqr4.
541 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlaqr4.
549 /* SUBROUTINE ZLAQR4( 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*16 H( LDH, * ), W( * ), WORK( * ), Z( LDZ, * ) */
557 /* > \par Purpose: */
562 /* > ZLAQR4 implements one level of recursion for ZLAQR0. */
563 /* > It is a complete implementation of the small bulge multi-shift */
564 /* > QR algorithm. It may be called by ZLAQR0 and, for large enough */
565 /* > deflation window size, it may be called by ZLAQR3. This */
566 /* > subroutine is identical to ZLAQR0 except that it calls ZLAQR2 */
567 /* > instead of ZLAQR3. */
569 /* > ZLAQR4 computes the eigenvalues of a Hessenberg matrix H */
570 /* > and, optionally, the matrices T and Z from the Schur decomposition */
571 /* > H = Z T Z**H, where T is an upper triangular matrix (the */
572 /* > Schur form), and Z is the unitary matrix of Schur vectors. */
574 /* > Optionally Z may be postmultiplied into an input unitary */
575 /* > matrix Q so that this routine can give the Schur factorization */
576 /* > of a matrix A which has been reduced to the Hessenberg form H */
577 /* > by the unitary matrix Q: A = Q*H*Q**H = (QZ)*H*(QZ)**H. */
583 /* > \param[in] WANTT */
585 /* > WANTT is LOGICAL */
586 /* > = .TRUE. : the full Schur form T is required; */
587 /* > = .FALSE.: only eigenvalues are required. */
590 /* > \param[in] WANTZ */
592 /* > WANTZ is LOGICAL */
593 /* > = .TRUE. : the matrix of Schur vectors Z is required; */
594 /* > = .FALSE.: Schur vectors are not required. */
600 /* > The order of the matrix H. N >= 0. */
603 /* > \param[in] ILO */
605 /* > ILO is INTEGER */
608 /* > \param[in] IHI */
610 /* > IHI is INTEGER */
611 /* > It is assumed that H is already upper triangular in rows */
612 /* > and columns 1:ILO-1 and IHI+1:N and, if ILO > 1, */
613 /* > H(ILO,ILO-1) is zero. ILO and IHI are normally set by a */
614 /* > previous call to ZGEBAL, and then passed to ZGEHRD when the */
615 /* > matrix output by ZGEBAL is reduced to Hessenberg form. */
616 /* > Otherwise, ILO and IHI should be set to 1 and N, */
617 /* > respectively. If N > 0, then 1 <= ILO <= IHI <= N. */
618 /* > If N = 0, then ILO = 1 and IHI = 0. */
621 /* > \param[in,out] H */
623 /* > H is COMPLEX*16 array, dimension (LDH,N) */
624 /* > On entry, the upper Hessenberg matrix H. */
625 /* > On exit, if INFO = 0 and WANTT is .TRUE., then H */
626 /* > contains the upper triangular matrix T from the Schur */
627 /* > decomposition (the Schur form). If INFO = 0 and WANT is */
628 /* > .FALSE., then the contents of H are unspecified on exit. */
629 /* > (The output value of H when INFO > 0 is given under the */
630 /* > description of INFO below.) */
632 /* > This subroutine may explicitly set H(i,j) = 0 for i > j and */
633 /* > j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N. */
636 /* > \param[in] LDH */
638 /* > LDH is INTEGER */
639 /* > The leading dimension of the array H. LDH >= f2cmax(1,N). */
642 /* > \param[out] W */
644 /* > W is COMPLEX*16 array, dimension (N) */
645 /* > The computed eigenvalues of H(ILO:IHI,ILO:IHI) are stored */
646 /* > in W(ILO:IHI). If WANTT is .TRUE., then the eigenvalues are */
647 /* > stored in the same order as on the diagonal of the Schur */
648 /* > form returned in H, with W(i) = H(i,i). */
651 /* > \param[in] ILOZ */
653 /* > ILOZ is INTEGER */
656 /* > \param[in] IHIZ */
658 /* > IHIZ is INTEGER */
659 /* > Specify the rows of Z to which transformations must be */
660 /* > applied if WANTZ is .TRUE.. */
661 /* > 1 <= ILOZ <= ILO; IHI <= IHIZ <= N. */
664 /* > \param[in,out] Z */
666 /* > Z is COMPLEX*16 array, dimension (LDZ,IHI) */
667 /* > If WANTZ is .FALSE., then Z is not referenced. */
668 /* > If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is */
669 /* > replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the */
670 /* > orthogonal Schur factor of H(ILO:IHI,ILO:IHI). */
671 /* > (The output value of Z when INFO > 0 is given under */
672 /* > the description of INFO below.) */
675 /* > \param[in] LDZ */
677 /* > LDZ is INTEGER */
678 /* > The leading dimension of the array Z. if WANTZ is .TRUE. */
679 /* > then LDZ >= MAX(1,IHIZ). Otherwise, LDZ >= 1. */
682 /* > \param[out] WORK */
684 /* > WORK is COMPLEX*16 array, dimension LWORK */
685 /* > On exit, if LWORK = -1, WORK(1) returns an estimate of */
686 /* > the optimal value for LWORK. */
689 /* > \param[in] LWORK */
691 /* > LWORK is INTEGER */
692 /* > The dimension of the array WORK. LWORK >= f2cmax(1,N) */
693 /* > is sufficient, but LWORK typically as large as 6*N may */
694 /* > be required for optimal performance. A workspace query */
695 /* > to determine the optimal workspace size is recommended. */
697 /* > If LWORK = -1, then ZLAQR4 does a workspace query. */
698 /* > In this case, ZLAQR4 checks the input parameters and */
699 /* > estimates the optimal workspace size for the given */
700 /* > values of N, ILO and IHI. The estimate is returned */
701 /* > in WORK(1). No error message related to LWORK is */
702 /* > issued by XERBLA. Neither H nor Z are accessed. */
705 /* > \param[out] INFO */
707 /* > INFO is INTEGER */
708 /* > = 0: successful exit */
709 /* > > 0: if INFO = i, ZLAQR4 failed to compute all of */
710 /* > the eigenvalues. Elements 1:ilo-1 and i+1:n of WR */
711 /* > and WI contain those eigenvalues which have been */
712 /* > successfully computed. (Failures are rare.) */
714 /* > If INFO > 0 and WANT is .FALSE., then on exit, */
715 /* > the remaining unconverged eigenvalues are the eigen- */
716 /* > values of the upper Hessenberg matrix rows and */
717 /* > columns ILO through INFO of the final, output */
720 /* > If INFO > 0 and WANTT is .TRUE., then on exit */
722 /* > (*) (initial value of H)*U = U*(final value of H) */
724 /* > where U is a unitary matrix. The final */
725 /* > value of H is upper Hessenberg and triangular in */
726 /* > rows and columns INFO+1 through IHI. */
728 /* > If INFO > 0 and WANTZ is .TRUE., then on exit */
730 /* > (final value of Z(ILO:IHI,ILOZ:IHIZ) */
731 /* > = (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U */
733 /* > where U is the unitary matrix in (*) (regard- */
734 /* > less of the value of WANTT.) */
736 /* > If INFO > 0 and WANTZ is .FALSE., then Z is not */
743 /* > \author Univ. of Tennessee */
744 /* > \author Univ. of California Berkeley */
745 /* > \author Univ. of Colorado Denver */
746 /* > \author NAG Ltd. */
748 /* > \date December 2016 */
750 /* > \ingroup complex16OTHERauxiliary */
752 /* > \par Contributors: */
753 /* ================== */
755 /* > Karen Braman and Ralph Byers, Department of Mathematics, */
756 /* > University of Kansas, USA */
758 /* > \par References: */
759 /* ================ */
761 /* > K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
762 /* > Algorithm Part I: Maintaining Well Focused Shifts, and Level 3 */
763 /* > Performance, SIAM Journal of Matrix Analysis, volume 23, pages */
764 /* > 929--947, 2002. */
766 /* > K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
767 /* > Algorithm Part II: Aggressive Early Deflation, SIAM Journal */
768 /* > of Matrix Analysis, volume 23, pages 948--973, 2002. */
770 /* ===================================================================== */
771 /* Subroutine */ int zlaqr4_(logical *wantt, logical *wantz, integer *n,
772 integer *ilo, integer *ihi, doublecomplex *h__, integer *ldh,
773 doublecomplex *w, integer *iloz, integer *ihiz, doublecomplex *z__,
774 integer *ldz, doublecomplex *work, integer *lwork, integer *info)
776 /* System generated locals */
777 integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
778 doublereal d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8;
779 doublecomplex z__1, z__2, z__3, z__4, z__5;
781 /* Local variables */
782 integer ndec, ndfl, kbot, nmin;
785 doublecomplex zdum[1] /* was [1][1] */;
786 integer kacc22, i__, k;
788 integer itmax, nsmax, nwmax, kwtop;
789 doublecomplex aa, bb, cc, dd;
790 extern /* Subroutine */ int zlaqr2_(logical *, logical *, integer *,
791 integer *, integer *, integer *, doublecomplex *, integer *,
792 integer *, integer *, doublecomplex *, integer *, integer *,
793 integer *, doublecomplex *, doublecomplex *, integer *, integer *,
794 doublecomplex *, integer *, integer *, doublecomplex *, integer *
795 , doublecomplex *, integer *), zlaqr5_(logical *, logical *,
796 integer *, integer *, integer *, integer *, integer *,
797 doublecomplex *, doublecomplex *, integer *, integer *, integer *,
798 doublecomplex *, integer *, doublecomplex *, integer *,
799 doublecomplex *, integer *, integer *, doublecomplex *, integer *,
800 integer *, doublecomplex *, integer *);
801 integer ld, nh, nibble, it, ks, kt, ku, kv, ls, ns, nw;
802 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
803 integer *, integer *, ftnlen, ftnlen);
805 doublecomplex rtdisc;
808 extern /* Subroutine */ int zlahqr_(logical *, logical *, integer *,
809 integer *, integer *, doublecomplex *, integer *, doublecomplex *,
810 integer *, integer *, doublecomplex *, integer *, integer *),
811 zlacpy_(char *, integer *, integer *, doublecomplex *, integer *,
812 doublecomplex *, integer *);
814 doublecomplex tr2, det;
815 integer inf, kdu, nho, nve, kwh, nsr, nwr, kwv;
818 /* -- LAPACK auxiliary routine (version 3.7.0) -- */
819 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
820 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
824 /* ================================================================ */
827 /* ==== Matrices of order NTINY or smaller must be processed by */
828 /* . ZLAHQR because of insufficient subdiagonal scratch space. */
829 /* . (This is a hard limit.) ==== */
831 /* ==== Exceptional deflation windows: try to cure rare */
832 /* . slow convergence by varying the size of the */
833 /* . deflation window after KEXNW iterations. ==== */
835 /* ==== Exceptional shifts: try to cure rare slow convergence */
836 /* . with ad-hoc exceptional shifts every KEXSH iterations. */
839 /* ==== The constant WILK1 is used to form the exceptional */
841 /* Parameter adjustments */
843 h_offset = 1 + h_dim1 * 1;
847 z_offset = 1 + z_dim1 * 1;
854 /* ==== Quick return for N = 0: nothing to do. ==== */
857 work[1].r = 1., work[1].i = 0.;
863 /* ==== Tiny matrices must use ZLAHQR. ==== */
867 zlahqr_(wantt, wantz, n, ilo, ihi, &h__[h_offset], ldh, &w[1],
868 iloz, ihiz, &z__[z_offset], ldz, info);
872 /* ==== Use small bulge multi-shift QR with aggressive early */
873 /* . deflation on larger-than-tiny matrices. ==== */
875 /* ==== Hope for the best. ==== */
879 /* ==== Set up job flags for ILAENV. ==== */
882 *(unsigned char *)jbcmpz = 'S';
884 *(unsigned char *)jbcmpz = 'E';
887 *(unsigned char *)&jbcmpz[1] = 'V';
889 *(unsigned char *)&jbcmpz[1] = 'N';
892 /* ==== NWR = recommended deflation window size. At this */
893 /* . point, N .GT. NTINY = 15, so there is enough */
894 /* . subdiagonal workspace for NWR.GE.2 as required. */
895 /* . (In fact, there is enough subdiagonal space for */
896 /* . NWR.GE.4.) ==== */
898 nwr = ilaenv_(&c__13, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
902 i__1 = *ihi - *ilo + 1, i__2 = (*n - 1) / 3, i__1 = f2cmin(i__1,i__2);
903 nwr = f2cmin(i__1,nwr);
905 /* ==== NSR = recommended number of simultaneous shifts. */
906 /* . At this point N .GT. NTINY = 15, so there is at */
907 /* . enough subdiagonal workspace for NSR to be even */
908 /* . and greater than or equal to two as required. ==== */
910 nsr = ilaenv_(&c__15, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
913 i__1 = nsr, i__2 = (*n - 3) / 6, i__1 = f2cmin(i__1,i__2), i__2 = *ihi -
915 nsr = f2cmin(i__1,i__2);
917 i__1 = 2, i__2 = nsr - nsr % 2;
918 nsr = f2cmax(i__1,i__2);
920 /* ==== Estimate optimal workspace ==== */
922 /* ==== Workspace query call to ZLAQR2 ==== */
925 zlaqr2_(wantt, wantz, n, ilo, ihi, &i__1, &h__[h_offset], ldh, iloz,
926 ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[h_offset],
927 ldh, n, &h__[h_offset], ldh, n, &h__[h_offset], ldh, &work[1],
930 /* ==== Optimal workspace = MAX(ZLAQR5, ZLAQR2) ==== */
933 i__1 = nsr * 3 / 2, i__2 = (integer) work[1].r;
934 lwkopt = f2cmax(i__1,i__2);
936 /* ==== Quick return in case of workspace query. ==== */
939 d__1 = (doublereal) lwkopt;
940 z__1.r = d__1, z__1.i = 0.;
941 work[1].r = z__1.r, work[1].i = z__1.i;
945 /* ==== ZLAHQR/ZLAQR0 crossover point ==== */
947 nmin = ilaenv_(&c__12, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)
949 nmin = f2cmax(15,nmin);
951 /* ==== Nibble crossover point ==== */
953 nibble = ilaenv_(&c__14, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork, (
954 ftnlen)6, (ftnlen)2);
955 nibble = f2cmax(0,nibble);
957 /* ==== Accumulate reflections during ttswp? Use block */
958 /* . 2-by-2 structure during matrix-matrix multiply? ==== */
960 kacc22 = ilaenv_(&c__16, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork, (
961 ftnlen)6, (ftnlen)2);
962 kacc22 = f2cmax(0,kacc22);
963 kacc22 = f2cmin(2,kacc22);
965 /* ==== NWMAX = the largest possible deflation window for */
966 /* . which there is sufficient workspace. ==== */
969 i__1 = (*n - 1) / 3, i__2 = *lwork / 2;
970 nwmax = f2cmin(i__1,i__2);
973 /* ==== NSMAX = the Largest number of simultaneous shifts */
974 /* . for which there is sufficient workspace. ==== */
977 i__1 = (*n - 3) / 6, i__2 = (*lwork << 1) / 3;
978 nsmax = f2cmin(i__1,i__2);
981 /* ==== NDFL: an iteration count restarted at deflation. ==== */
985 /* ==== ITMAX = iteration limit ==== */
988 i__1 = 10, i__2 = *ihi - *ilo + 1;
989 itmax = 30 * f2cmax(i__1,i__2);
991 /* ==== Last row and column in the active block ==== */
995 /* ==== Main Loop ==== */
998 for (it = 1; it <= i__1; ++it) {
1000 /* ==== Done when KBOT falls below ILO ==== */
1006 /* ==== Locate active block ==== */
1009 for (k = kbot; k >= i__2; --k) {
1010 i__3 = k + (k - 1) * h_dim1;
1011 if (h__[i__3].r == 0. && h__[i__3].i == 0.) {
1020 /* ==== Select deflation window size: */
1021 /* . Typical Case: */
1022 /* . If possible and advisable, nibble the entire */
1023 /* . active block. If not, use size MIN(NWR,NWMAX) */
1024 /* . or MIN(NWR+1,NWMAX) depending upon which has */
1025 /* . the smaller corresponding subdiagonal entry */
1026 /* . (a heuristic). */
1028 /* . Exceptional Case: */
1029 /* . If there have been no deflations in KEXNW or */
1030 /* . more iterations, then vary the deflation window */
1031 /* . size. At first, because, larger windows are, */
1032 /* . in general, more powerful than smaller ones, */
1033 /* . rapidly increase the window to the maximum possible. */
1034 /* . Then, gradually reduce the window size. ==== */
1036 nh = kbot - ktop + 1;
1037 nwupbd = f2cmin(nh,nwmax);
1039 nw = f2cmin(nwupbd,nwr);
1042 i__2 = nwupbd, i__3 = nw << 1;
1043 nw = f2cmin(i__2,i__3);
1049 kwtop = kbot - nw + 1;
1050 i__2 = kwtop + (kwtop - 1) * h_dim1;
1051 i__3 = kwtop - 1 + (kwtop - 2) * h_dim1;
1052 if ((d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[
1053 kwtop + (kwtop - 1) * h_dim1]), abs(d__2)) > (
1054 d__3 = h__[i__3].r, abs(d__3)) + (d__4 = d_imag(&
1055 h__[kwtop - 1 + (kwtop - 2) * h_dim1]), abs(d__4))
1063 } else if (ndec >= 0 || nw >= nwupbd) {
1065 if (nw - ndec < 2) {
1071 /* ==== Aggressive early deflation: */
1072 /* . split workspace under the subdiagonal into */
1073 /* . - an nw-by-nw work array V in the lower */
1074 /* . left-hand-corner, */
1075 /* . - an NW-by-at-least-NW-but-more-is-better */
1076 /* . (NW-by-NHO) horizontal work array along */
1077 /* . the bottom edge, */
1078 /* . - an at-least-NW-but-more-is-better (NHV-by-NW) */
1079 /* . vertical work array along the left-hand-edge. */
1084 nho = *n - nw - 1 - kt + 1;
1086 nve = *n - nw - kwv + 1;
1088 /* ==== Aggressive early deflation ==== */
1090 zlaqr2_(wantt, wantz, n, &ktop, &kbot, &nw, &h__[h_offset], ldh,
1091 iloz, ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[kv
1092 + h_dim1], ldh, &nho, &h__[kv + kt * h_dim1], ldh, &nve, &
1093 h__[kwv + h_dim1], ldh, &work[1], lwork);
1095 /* ==== Adjust KBOT accounting for new deflations. ==== */
1099 /* ==== KS points to the shifts. ==== */
1103 /* ==== Skip an expensive QR sweep if there is a (partly */
1104 /* . heuristic) reason to expect that many eigenvalues */
1105 /* . will deflate without it. Here, the QR sweep is */
1106 /* . skipped if many eigenvalues have just been deflated */
1107 /* . or if the remaining active block is small. */
1109 if (ld == 0 || ld * 100 <= nw * nibble && kbot - ktop + 1 > f2cmin(
1112 /* ==== NS = nominal number of simultaneous shifts. */
1113 /* . This may be lowered (slightly) if ZLAQR2 */
1114 /* . did not provide that many shifts. ==== */
1118 i__4 = 2, i__5 = kbot - ktop;
1119 i__2 = f2cmin(nsmax,nsr), i__3 = f2cmax(i__4,i__5);
1120 ns = f2cmin(i__2,i__3);
1123 /* ==== If there have been no deflations */
1124 /* . in a multiple of KEXSH iterations, */
1125 /* . then try exceptional shifts. */
1126 /* . Otherwise use shifts provided by */
1127 /* . ZLAQR2 above or from the eigenvalues */
1128 /* . of a trailing principal submatrix. ==== */
1130 if (ndfl % 6 == 0) {
1133 for (i__ = kbot; i__ >= i__2; i__ += -2) {
1135 i__4 = i__ + i__ * h_dim1;
1136 i__5 = i__ + (i__ - 1) * h_dim1;
1137 d__3 = ((d__1 = h__[i__5].r, abs(d__1)) + (d__2 =
1138 d_imag(&h__[i__ + (i__ - 1) * h_dim1]), abs(
1140 z__1.r = h__[i__4].r + d__3, z__1.i = h__[i__4].i;
1141 w[i__3].r = z__1.r, w[i__3].i = z__1.i;
1144 w[i__3].r = w[i__4].r, w[i__3].i = w[i__4].i;
1149 /* ==== Got NS/2 or fewer shifts? Use ZLAHQR */
1150 /* . on a trailing principal submatrix to */
1151 /* . get more. (Since NS.LE.NSMAX.LE.(N-3)/6, */
1152 /* . there is enough space below the subdiagonal */
1153 /* . to fit an NS-by-NS scratch array.) ==== */
1155 if (kbot - ks + 1 <= ns / 2) {
1158 zlacpy_("A", &ns, &ns, &h__[ks + ks * h_dim1], ldh, &
1159 h__[kt + h_dim1], ldh);
1160 zlahqr_(&c_false, &c_false, &ns, &c__1, &ns, &h__[kt
1161 + h_dim1], ldh, &w[ks], &c__1, &c__1, zdum, &
1165 /* ==== In case of a rare QR failure use */
1166 /* . eigenvalues of the trailing 2-by-2 */
1167 /* . principal submatrix. Scale to avoid */
1168 /* . overflows, underflows and subnormals. */
1169 /* . (The scale factor S can not be zero, */
1170 /* . because H(KBOT,KBOT-1) is nonzero.) ==== */
1173 i__2 = kbot - 1 + (kbot - 1) * h_dim1;
1174 i__3 = kbot + (kbot - 1) * h_dim1;
1175 i__4 = kbot - 1 + kbot * h_dim1;
1176 i__5 = kbot + kbot * h_dim1;
1177 s = (d__1 = h__[i__2].r, abs(d__1)) + (d__2 =
1178 d_imag(&h__[kbot - 1 + (kbot - 1) *
1179 h_dim1]), abs(d__2)) + ((d__3 = h__[i__3]
1180 .r, abs(d__3)) + (d__4 = d_imag(&h__[kbot
1181 + (kbot - 1) * h_dim1]), abs(d__4))) + ((
1182 d__5 = h__[i__4].r, abs(d__5)) + (d__6 =
1183 d_imag(&h__[kbot - 1 + kbot * h_dim1]),
1184 abs(d__6))) + ((d__7 = h__[i__5].r, abs(
1185 d__7)) + (d__8 = d_imag(&h__[kbot + kbot *
1186 h_dim1]), abs(d__8)));
1187 i__2 = kbot - 1 + (kbot - 1) * h_dim1;
1188 z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
1190 aa.r = z__1.r, aa.i = z__1.i;
1191 i__2 = kbot + (kbot - 1) * h_dim1;
1192 z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
1194 cc.r = z__1.r, cc.i = z__1.i;
1195 i__2 = kbot - 1 + kbot * h_dim1;
1196 z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
1198 bb.r = z__1.r, bb.i = z__1.i;
1199 i__2 = kbot + kbot * h_dim1;
1200 z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
1202 dd.r = z__1.r, dd.i = z__1.i;
1203 z__2.r = aa.r + dd.r, z__2.i = aa.i + dd.i;
1204 z__1.r = z__2.r / 2., z__1.i = z__2.i / 2.;
1205 tr2.r = z__1.r, tr2.i = z__1.i;
1206 z__3.r = aa.r - tr2.r, z__3.i = aa.i - tr2.i;
1207 z__4.r = dd.r - tr2.r, z__4.i = dd.i - tr2.i;
1208 z__2.r = z__3.r * z__4.r - z__3.i * z__4.i,
1209 z__2.i = z__3.r * z__4.i + z__3.i *
1211 z__5.r = bb.r * cc.r - bb.i * cc.i, z__5.i = bb.r
1212 * cc.i + bb.i * cc.r;
1213 z__1.r = z__2.r - z__5.r, z__1.i = z__2.i -
1215 det.r = z__1.r, det.i = z__1.i;
1216 z__2.r = -det.r, z__2.i = -det.i;
1217 z_sqrt(&z__1, &z__2);
1218 rtdisc.r = z__1.r, rtdisc.i = z__1.i;
1220 z__2.r = tr2.r + rtdisc.r, z__2.i = tr2.i +
1222 z__1.r = s * z__2.r, z__1.i = s * z__2.i;
1223 w[i__2].r = z__1.r, w[i__2].i = z__1.i;
1225 z__2.r = tr2.r - rtdisc.r, z__2.i = tr2.i -
1227 z__1.r = s * z__2.r, z__1.i = s * z__2.i;
1228 w[i__2].r = z__1.r, w[i__2].i = z__1.i;
1234 if (kbot - ks + 1 > ns) {
1236 /* ==== Sort the shifts (Helps a little) ==== */
1240 for (k = kbot; k >= i__2; --k) {
1246 for (i__ = ks; i__ <= i__3; ++i__) {
1249 if ((d__1 = w[i__4].r, abs(d__1)) + (d__2 =
1250 d_imag(&w[i__]), abs(d__2)) < (d__3 =
1251 w[i__5].r, abs(d__3)) + (d__4 =
1252 d_imag(&w[i__ + 1]), abs(d__4))) {
1255 swap.r = w[i__4].r, swap.i = w[i__4].i;
1258 w[i__4].r = w[i__5].r, w[i__4].i = w[i__5]
1261 w[i__4].r = swap.r, w[i__4].i = swap.i;
1272 /* ==== If there are only two shifts, then use */
1273 /* . only one. ==== */
1275 if (kbot - ks + 1 == 2) {
1277 i__3 = kbot + kbot * h_dim1;
1278 z__2.r = w[i__2].r - h__[i__3].r, z__2.i = w[i__2].i -
1280 z__1.r = z__2.r, z__1.i = z__2.i;
1282 i__5 = kbot + kbot * h_dim1;
1283 z__4.r = w[i__4].r - h__[i__5].r, z__4.i = w[i__4].i -
1285 z__3.r = z__4.r, z__3.i = z__4.i;
1286 if ((d__1 = z__1.r, abs(d__1)) + (d__2 = d_imag(&z__1),
1287 abs(d__2)) < (d__3 = z__3.r, abs(d__3)) + (d__4 =
1288 d_imag(&z__3), abs(d__4))) {
1291 w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
1295 w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
1299 /* ==== Use up to NS of the the smallest magnitude */
1300 /* . shifts. If there aren't NS shifts available, */
1301 /* . then use them all, possibly dropping one to */
1302 /* . make the number of shifts even. ==== */
1305 i__2 = ns, i__3 = kbot - ks + 1;
1306 ns = f2cmin(i__2,i__3);
1310 /* ==== Small-bulge multi-shift QR sweep: */
1311 /* . split workspace under the subdiagonal into */
1312 /* . - a KDU-by-KDU work array U in the lower */
1313 /* . left-hand-corner, */
1314 /* . - a KDU-by-at-least-KDU-but-more-is-better */
1315 /* . (KDU-by-NHo) horizontal work array WH along */
1316 /* . the bottom edge, */
1317 /* . - and an at-least-KDU-but-more-is-better-by-KDU */
1318 /* . (NVE-by-KDU) vertical work WV arrow along */
1319 /* . the left-hand-edge. ==== */
1324 nho = *n - kdu - 3 - (kdu + 1) + 1;
1326 nve = *n - kdu - kwv + 1;
1328 /* ==== Small-bulge multi-shift QR sweep ==== */
1330 zlaqr5_(wantt, wantz, &kacc22, n, &ktop, &kbot, &ns, &w[ks], &
1331 h__[h_offset], ldh, iloz, ihiz, &z__[z_offset], ldz, &
1332 work[1], &c__3, &h__[ku + h_dim1], ldh, &nve, &h__[
1333 kwv + h_dim1], ldh, &nho, &h__[ku + kwh * h_dim1],
1337 /* ==== Note progress (or the lack of it). ==== */
1345 /* ==== End of main loop ==== */
1349 /* ==== Iteration limit exceeded. Set INFO to show where */
1350 /* . the problem occurred and exit. ==== */
1357 /* ==== Return the optimal value of LWORK. ==== */
1359 d__1 = (doublereal) lwkopt;
1360 z__1.r = d__1, z__1.i = 0.;
1361 work[1].r = z__1.r, work[1].i = z__1.i;
1363 /* ==== End of ZLAQR4 ==== */