00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static integer c__13 = 13;
00019 static integer c__15 = 15;
00020 static integer c_n1 = -1;
00021 static integer c__12 = 12;
00022 static integer c__14 = 14;
00023 static integer c__16 = 16;
00024 static logical c_false = FALSE_;
00025 static integer c__1 = 1;
00026 static integer c__3 = 3;
00027
00028 int zlaqr0_(logical *wantt, logical *wantz, integer *n,
00029 integer *ilo, integer *ihi, doublecomplex *h__, integer *ldh,
00030 doublecomplex *w, integer *iloz, integer *ihiz, doublecomplex *z__,
00031 integer *ldz, doublecomplex *work, integer *lwork, integer *info)
00032 {
00033
00034 integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
00035 doublereal d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8;
00036 doublecomplex z__1, z__2, z__3, z__4, z__5;
00037
00038
00039 double d_imag(doublecomplex *);
00040 void z_sqrt(doublecomplex *, doublecomplex *);
00041
00042
00043 integer i__, k;
00044 doublereal s;
00045 doublecomplex aa, bb, cc, dd;
00046 integer ld, nh, it, ks, kt, ku, kv, ls, ns, nw;
00047 doublecomplex tr2, det;
00048 integer inf, kdu, nho, nve, kwh, nsr, nwr, kwv, ndec, ndfl, kbot, nmin;
00049 doublecomplex swap;
00050 integer ktop;
00051 doublecomplex zdum[1] ;
00052 integer kacc22, itmax, nsmax, nwmax, kwtop;
00053 extern int zlaqr3_(logical *, logical *, integer *,
00054 integer *, integer *, integer *, doublecomplex *, integer *,
00055 integer *, integer *, doublecomplex *, integer *, integer *,
00056 integer *, doublecomplex *, doublecomplex *, integer *, integer *,
00057 doublecomplex *, integer *, integer *, doublecomplex *, integer *
00058 , doublecomplex *, integer *), zlaqr4_(logical *, logical *,
00059 integer *, integer *, integer *, doublecomplex *, integer *,
00060 doublecomplex *, integer *, integer *, doublecomplex *, integer *,
00061 doublecomplex *, integer *, integer *), zlaqr5_(logical *,
00062 logical *, integer *, integer *, integer *, integer *, integer *,
00063 doublecomplex *, doublecomplex *, integer *, integer *, integer *,
00064 doublecomplex *, integer *, doublecomplex *, integer *,
00065 doublecomplex *, integer *, integer *, doublecomplex *, integer *,
00066 integer *, doublecomplex *, integer *);
00067 integer nibble;
00068 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00069 integer *, integer *);
00070 char jbcmpz[2];
00071 doublecomplex rtdisc;
00072 integer nwupbd;
00073 logical sorted;
00074 extern int zlahqr_(logical *, logical *, integer *,
00075 integer *, integer *, doublecomplex *, integer *, doublecomplex *,
00076 integer *, integer *, doublecomplex *, integer *, integer *),
00077 zlacpy_(char *, integer *, integer *, doublecomplex *, integer *,
00078 doublecomplex *, integer *);
00079 integer lwkopt;
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 h_dim1 = *ldh;
00263 h_offset = 1 + h_dim1;
00264 h__ -= h_offset;
00265 --w;
00266 z_dim1 = *ldz;
00267 z_offset = 1 + z_dim1;
00268 z__ -= z_offset;
00269 --work;
00270
00271
00272 *info = 0;
00273
00274
00275
00276 if (*n == 0) {
00277 work[1].r = 1., work[1].i = 0.;
00278 return 0;
00279 }
00280
00281 if (*n <= 11) {
00282
00283
00284
00285 lwkopt = 1;
00286 if (*lwork != -1) {
00287 zlahqr_(wantt, wantz, n, ilo, ihi, &h__[h_offset], ldh, &w[1],
00288 iloz, ihiz, &z__[z_offset], ldz, info);
00289 }
00290 } else {
00291
00292
00293
00294
00295
00296
00297 *info = 0;
00298
00299
00300
00301 if (*wantt) {
00302 *(unsigned char *)jbcmpz = 'S';
00303 } else {
00304 *(unsigned char *)jbcmpz = 'E';
00305 }
00306 if (*wantz) {
00307 *(unsigned char *)&jbcmpz[1] = 'V';
00308 } else {
00309 *(unsigned char *)&jbcmpz[1] = 'N';
00310 }
00311
00312
00313
00314
00315
00316
00317
00318 nwr = ilaenv_(&c__13, "ZLAQR0", jbcmpz, n, ilo, ihi, lwork);
00319 nwr = max(2,nwr);
00320
00321 i__1 = *ihi - *ilo + 1, i__2 = (*n - 1) / 3, i__1 = min(i__1,i__2);
00322 nwr = min(i__1,nwr);
00323
00324
00325
00326
00327
00328
00329 nsr = ilaenv_(&c__15, "ZLAQR0", jbcmpz, n, ilo, ihi, lwork);
00330
00331 i__1 = nsr, i__2 = (*n + 6) / 9, i__1 = min(i__1,i__2), i__2 = *ihi -
00332 *ilo;
00333 nsr = min(i__1,i__2);
00334
00335 i__1 = 2, i__2 = nsr - nsr % 2;
00336 nsr = max(i__1,i__2);
00337
00338
00339
00340
00341
00342 i__1 = nwr + 1;
00343 zlaqr3_(wantt, wantz, n, ilo, ihi, &i__1, &h__[h_offset], ldh, iloz,
00344 ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[h_offset],
00345 ldh, n, &h__[h_offset], ldh, n, &h__[h_offset], ldh, &work[1],
00346 &c_n1);
00347
00348
00349
00350
00351 i__1 = nsr * 3 / 2, i__2 = (integer) work[1].r;
00352 lwkopt = max(i__1,i__2);
00353
00354
00355
00356 if (*lwork == -1) {
00357 d__1 = (doublereal) lwkopt;
00358 z__1.r = d__1, z__1.i = 0.;
00359 work[1].r = z__1.r, work[1].i = z__1.i;
00360 return 0;
00361 }
00362
00363
00364
00365 nmin = ilaenv_(&c__12, "ZLAQR0", jbcmpz, n, ilo, ihi, lwork);
00366 nmin = max(11,nmin);
00367
00368
00369
00370 nibble = ilaenv_(&c__14, "ZLAQR0", jbcmpz, n, ilo, ihi, lwork);
00371 nibble = max(0,nibble);
00372
00373
00374
00375
00376 kacc22 = ilaenv_(&c__16, "ZLAQR0", jbcmpz, n, ilo, ihi, lwork);
00377 kacc22 = max(0,kacc22);
00378 kacc22 = min(2,kacc22);
00379
00380
00381
00382
00383
00384 i__1 = (*n - 1) / 3, i__2 = *lwork / 2;
00385 nwmax = min(i__1,i__2);
00386 nw = nwmax;
00387
00388
00389
00390
00391
00392 i__1 = (*n + 6) / 9, i__2 = (*lwork << 1) / 3;
00393 nsmax = min(i__1,i__2);
00394 nsmax -= nsmax % 2;
00395
00396
00397
00398 ndfl = 1;
00399
00400
00401
00402
00403 i__1 = 10, i__2 = *ihi - *ilo + 1;
00404 itmax = max(i__1,i__2) * 30;
00405
00406
00407
00408 kbot = *ihi;
00409
00410
00411
00412 i__1 = itmax;
00413 for (it = 1; it <= i__1; ++it) {
00414
00415
00416
00417 if (kbot < *ilo) {
00418 goto L80;
00419 }
00420
00421
00422
00423 i__2 = *ilo + 1;
00424 for (k = kbot; k >= i__2; --k) {
00425 i__3 = k + (k - 1) * h_dim1;
00426 if (h__[i__3].r == 0. && h__[i__3].i == 0.) {
00427 goto L20;
00428 }
00429
00430 }
00431 k = *ilo;
00432 L20:
00433 ktop = k;
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451 nh = kbot - ktop + 1;
00452 nwupbd = min(nh,nwmax);
00453 if (ndfl < 5) {
00454 nw = min(nwupbd,nwr);
00455 } else {
00456
00457 i__2 = nwupbd, i__3 = nw << 1;
00458 nw = min(i__2,i__3);
00459 }
00460 if (nw < nwmax) {
00461 if (nw >= nh - 1) {
00462 nw = nh;
00463 } else {
00464 kwtop = kbot - nw + 1;
00465 i__2 = kwtop + (kwtop - 1) * h_dim1;
00466 i__3 = kwtop - 1 + (kwtop - 2) * h_dim1;
00467 if ((d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[
00468 kwtop + (kwtop - 1) * h_dim1]), abs(d__2)) > (
00469 d__3 = h__[i__3].r, abs(d__3)) + (d__4 = d_imag(&
00470 h__[kwtop - 1 + (kwtop - 2) * h_dim1]), abs(d__4))
00471 ) {
00472 ++nw;
00473 }
00474 }
00475 }
00476 if (ndfl < 5) {
00477 ndec = -1;
00478 } else if (ndec >= 0 || nw >= nwupbd) {
00479 ++ndec;
00480 if (nw - ndec < 2) {
00481 ndec = 0;
00482 }
00483 nw -= ndec;
00484 }
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497 kv = *n - nw + 1;
00498 kt = nw + 1;
00499 nho = *n - nw - 1 - kt + 1;
00500 kwv = nw + 2;
00501 nve = *n - nw - kwv + 1;
00502
00503
00504
00505 zlaqr3_(wantt, wantz, n, &ktop, &kbot, &nw, &h__[h_offset], ldh,
00506 iloz, ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[kv
00507 + h_dim1], ldh, &nho, &h__[kv + kt * h_dim1], ldh, &nve, &
00508 h__[kwv + h_dim1], ldh, &work[1], lwork);
00509
00510
00511
00512 kbot -= ld;
00513
00514
00515
00516 ks = kbot - ls + 1;
00517
00518
00519
00520
00521
00522
00523
00524 if (ld == 0 || ld * 100 <= nw * nibble && kbot - ktop + 1 > min(
00525 nmin,nwmax)) {
00526
00527
00528
00529
00530
00531
00532
00533 i__4 = 2, i__5 = kbot - ktop;
00534 i__2 = min(nsmax,nsr), i__3 = max(i__4,i__5);
00535 ns = min(i__2,i__3);
00536 ns -= ns % 2;
00537
00538
00539
00540
00541
00542
00543
00544
00545 if (ndfl % 6 == 0) {
00546 ks = kbot - ns + 1;
00547 i__2 = ks + 1;
00548 for (i__ = kbot; i__ >= i__2; i__ += -2) {
00549 i__3 = i__;
00550 i__4 = i__ + i__ * h_dim1;
00551 i__5 = i__ + (i__ - 1) * h_dim1;
00552 d__3 = ((d__1 = h__[i__5].r, abs(d__1)) + (d__2 =
00553 d_imag(&h__[i__ + (i__ - 1) * h_dim1]), abs(
00554 d__2))) * .75;
00555 z__1.r = h__[i__4].r + d__3, z__1.i = h__[i__4].i;
00556 w[i__3].r = z__1.r, w[i__3].i = z__1.i;
00557 i__3 = i__ - 1;
00558 i__4 = i__;
00559 w[i__3].r = w[i__4].r, w[i__3].i = w[i__4].i;
00560
00561 }
00562 } else {
00563
00564
00565
00566
00567
00568
00569
00570 if (kbot - ks + 1 <= ns / 2) {
00571 ks = kbot - ns + 1;
00572 kt = *n - ns + 1;
00573 zlacpy_("A", &ns, &ns, &h__[ks + ks * h_dim1], ldh, &
00574 h__[kt + h_dim1], ldh);
00575 if (ns > nmin) {
00576 zlaqr4_(&c_false, &c_false, &ns, &c__1, &ns, &h__[
00577 kt + h_dim1], ldh, &w[ks], &c__1, &c__1,
00578 zdum, &c__1, &work[1], lwork, &inf);
00579 } else {
00580 zlahqr_(&c_false, &c_false, &ns, &c__1, &ns, &h__[
00581 kt + h_dim1], ldh, &w[ks], &c__1, &c__1,
00582 zdum, &c__1, &inf);
00583 }
00584 ks += inf;
00585
00586
00587
00588
00589
00590
00591
00592
00593 if (ks >= kbot) {
00594 i__2 = kbot - 1 + (kbot - 1) * h_dim1;
00595 i__3 = kbot + (kbot - 1) * h_dim1;
00596 i__4 = kbot - 1 + kbot * h_dim1;
00597 i__5 = kbot + kbot * h_dim1;
00598 s = (d__1 = h__[i__2].r, abs(d__1)) + (d__2 =
00599 d_imag(&h__[kbot - 1 + (kbot - 1) *
00600 h_dim1]), abs(d__2)) + ((d__3 = h__[i__3]
00601 .r, abs(d__3)) + (d__4 = d_imag(&h__[kbot
00602 + (kbot - 1) * h_dim1]), abs(d__4))) + ((
00603 d__5 = h__[i__4].r, abs(d__5)) + (d__6 =
00604 d_imag(&h__[kbot - 1 + kbot * h_dim1]),
00605 abs(d__6))) + ((d__7 = h__[i__5].r, abs(
00606 d__7)) + (d__8 = d_imag(&h__[kbot + kbot *
00607 h_dim1]), abs(d__8)));
00608 i__2 = kbot - 1 + (kbot - 1) * h_dim1;
00609 z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
00610 s;
00611 aa.r = z__1.r, aa.i = z__1.i;
00612 i__2 = kbot + (kbot - 1) * h_dim1;
00613 z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
00614 s;
00615 cc.r = z__1.r, cc.i = z__1.i;
00616 i__2 = kbot - 1 + kbot * h_dim1;
00617 z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
00618 s;
00619 bb.r = z__1.r, bb.i = z__1.i;
00620 i__2 = kbot + kbot * h_dim1;
00621 z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
00622 s;
00623 dd.r = z__1.r, dd.i = z__1.i;
00624 z__2.r = aa.r + dd.r, z__2.i = aa.i + dd.i;
00625 z__1.r = z__2.r / 2., z__1.i = z__2.i / 2.;
00626 tr2.r = z__1.r, tr2.i = z__1.i;
00627 z__3.r = aa.r - tr2.r, z__3.i = aa.i - tr2.i;
00628 z__4.r = dd.r - tr2.r, z__4.i = dd.i - tr2.i;
00629 z__2.r = z__3.r * z__4.r - z__3.i * z__4.i,
00630 z__2.i = z__3.r * z__4.i + z__3.i *
00631 z__4.r;
00632 z__5.r = bb.r * cc.r - bb.i * cc.i, z__5.i = bb.r
00633 * cc.i + bb.i * cc.r;
00634 z__1.r = z__2.r - z__5.r, z__1.i = z__2.i -
00635 z__5.i;
00636 det.r = z__1.r, det.i = z__1.i;
00637 z__2.r = -det.r, z__2.i = -det.i;
00638 z_sqrt(&z__1, &z__2);
00639 rtdisc.r = z__1.r, rtdisc.i = z__1.i;
00640 i__2 = kbot - 1;
00641 z__2.r = tr2.r + rtdisc.r, z__2.i = tr2.i +
00642 rtdisc.i;
00643 z__1.r = s * z__2.r, z__1.i = s * z__2.i;
00644 w[i__2].r = z__1.r, w[i__2].i = z__1.i;
00645 i__2 = kbot;
00646 z__2.r = tr2.r - rtdisc.r, z__2.i = tr2.i -
00647 rtdisc.i;
00648 z__1.r = s * z__2.r, z__1.i = s * z__2.i;
00649 w[i__2].r = z__1.r, w[i__2].i = z__1.i;
00650
00651 ks = kbot - 1;
00652 }
00653 }
00654
00655 if (kbot - ks + 1 > ns) {
00656
00657
00658
00659 sorted = FALSE_;
00660 i__2 = ks + 1;
00661 for (k = kbot; k >= i__2; --k) {
00662 if (sorted) {
00663 goto L60;
00664 }
00665 sorted = TRUE_;
00666 i__3 = k - 1;
00667 for (i__ = ks; i__ <= i__3; ++i__) {
00668 i__4 = i__;
00669 i__5 = i__ + 1;
00670 if ((d__1 = w[i__4].r, abs(d__1)) + (d__2 =
00671 d_imag(&w[i__]), abs(d__2)) < (d__3 =
00672 w[i__5].r, abs(d__3)) + (d__4 =
00673 d_imag(&w[i__ + 1]), abs(d__4))) {
00674 sorted = FALSE_;
00675 i__4 = i__;
00676 swap.r = w[i__4].r, swap.i = w[i__4].i;
00677 i__4 = i__;
00678 i__5 = i__ + 1;
00679 w[i__4].r = w[i__5].r, w[i__4].i = w[i__5]
00680 .i;
00681 i__4 = i__ + 1;
00682 w[i__4].r = swap.r, w[i__4].i = swap.i;
00683 }
00684
00685 }
00686
00687 }
00688 L60:
00689 ;
00690 }
00691 }
00692
00693
00694
00695
00696 if (kbot - ks + 1 == 2) {
00697 i__2 = kbot;
00698 i__3 = kbot + kbot * h_dim1;
00699 z__2.r = w[i__2].r - h__[i__3].r, z__2.i = w[i__2].i -
00700 h__[i__3].i;
00701 z__1.r = z__2.r, z__1.i = z__2.i;
00702 i__4 = kbot - 1;
00703 i__5 = kbot + kbot * h_dim1;
00704 z__4.r = w[i__4].r - h__[i__5].r, z__4.i = w[i__4].i -
00705 h__[i__5].i;
00706 z__3.r = z__4.r, z__3.i = z__4.i;
00707 if ((d__1 = z__1.r, abs(d__1)) + (d__2 = d_imag(&z__1),
00708 abs(d__2)) < (d__3 = z__3.r, abs(d__3)) + (d__4 =
00709 d_imag(&z__3), abs(d__4))) {
00710 i__2 = kbot - 1;
00711 i__3 = kbot;
00712 w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
00713 } else {
00714 i__2 = kbot;
00715 i__3 = kbot - 1;
00716 w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
00717 }
00718 }
00719
00720
00721
00722
00723
00724
00725
00726 i__2 = ns, i__3 = kbot - ks + 1;
00727 ns = min(i__2,i__3);
00728 ns -= ns % 2;
00729 ks = kbot - ns + 1;
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742 kdu = ns * 3 - 3;
00743 ku = *n - kdu + 1;
00744 kwh = kdu + 1;
00745 nho = *n - kdu - 3 - (kdu + 1) + 1;
00746 kwv = kdu + 4;
00747 nve = *n - kdu - kwv + 1;
00748
00749
00750
00751 zlaqr5_(wantt, wantz, &kacc22, n, &ktop, &kbot, &ns, &w[ks], &
00752 h__[h_offset], ldh, iloz, ihiz, &z__[z_offset], ldz, &
00753 work[1], &c__3, &h__[ku + h_dim1], ldh, &nve, &h__[
00754 kwv + h_dim1], ldh, &nho, &h__[ku + kwh * h_dim1],
00755 ldh);
00756 }
00757
00758
00759
00760 if (ld > 0) {
00761 ndfl = 1;
00762 } else {
00763 ++ndfl;
00764 }
00765
00766
00767
00768 }
00769
00770
00771
00772
00773 *info = kbot;
00774 L80:
00775 ;
00776 }
00777
00778
00779
00780 d__1 = (doublereal) lwkopt;
00781 z__1.r = d__1, z__1.i = 0.;
00782 work[1].r = z__1.r, work[1].i = z__1.i;
00783
00784
00785
00786 return 0;
00787 }