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__1 = 1;
00019 static integer c_n1 = -1;
00020 static doublereal c_b12 = 0.;
00021 static doublereal c_b13 = 1.;
00022 static logical c_true = TRUE_;
00023
00024 int dlaqr2_(logical *wantt, logical *wantz, integer *n,
00025 integer *ktop, integer *kbot, integer *nw, doublereal *h__, integer *
00026 ldh, integer *iloz, integer *ihiz, doublereal *z__, integer *ldz,
00027 integer *ns, integer *nd, doublereal *sr, doublereal *si, doublereal *
00028 v, integer *ldv, integer *nh, doublereal *t, integer *ldt, integer *
00029 nv, doublereal *wv, integer *ldwv, doublereal *work, integer *lwork)
00030 {
00031
00032 integer h_dim1, h_offset, t_dim1, t_offset, v_dim1, v_offset, wv_dim1,
00033 wv_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4;
00034 doublereal d__1, d__2, d__3, d__4, d__5, d__6;
00035
00036
00037 double sqrt(doublereal);
00038
00039
00040 integer i__, j, k;
00041 doublereal s, aa, bb, cc, dd, cs, sn;
00042 integer jw;
00043 doublereal evi, evk, foo;
00044 integer kln;
00045 doublereal tau, ulp;
00046 integer lwk1, lwk2;
00047 doublereal beta;
00048 integer kend, kcol, info, ifst, ilst, ltop, krow;
00049 extern int dlarf_(char *, integer *, integer *,
00050 doublereal *, integer *, doublereal *, doublereal *, integer *,
00051 doublereal *), dgemm_(char *, char *, integer *, integer *
00052 , integer *, doublereal *, doublereal *, integer *, doublereal *,
00053 integer *, doublereal *, doublereal *, integer *);
00054 logical bulge;
00055 extern int dcopy_(integer *, doublereal *, integer *,
00056 doublereal *, integer *);
00057 integer infqr, kwtop;
00058 extern int dlanv2_(doublereal *, doublereal *,
00059 doublereal *, doublereal *, doublereal *, doublereal *,
00060 doublereal *, doublereal *, doublereal *, doublereal *), dlabad_(
00061 doublereal *, doublereal *);
00062 extern doublereal dlamch_(char *);
00063 extern int dgehrd_(integer *, integer *, integer *,
00064 doublereal *, integer *, doublereal *, doublereal *, integer *,
00065 integer *), dlarfg_(integer *, doublereal *, doublereal *,
00066 integer *, doublereal *), dlahqr_(logical *, logical *, integer *,
00067 integer *, integer *, doublereal *, integer *, doublereal *,
00068 doublereal *, integer *, integer *, doublereal *, integer *,
00069 integer *), dlacpy_(char *, integer *, integer *, doublereal *,
00070 integer *, doublereal *, integer *);
00071 doublereal safmin;
00072 extern int dlaset_(char *, integer *, integer *,
00073 doublereal *, doublereal *, doublereal *, integer *);
00074 doublereal safmax;
00075 extern int dtrexc_(char *, integer *, doublereal *,
00076 integer *, doublereal *, integer *, integer *, integer *,
00077 doublereal *, integer *), dormhr_(char *, char *, integer
00078 *, integer *, integer *, integer *, doublereal *, integer *,
00079 doublereal *, doublereal *, integer *, doublereal *, integer *,
00080 integer *);
00081 logical sorted;
00082 doublereal smlnum;
00083 integer lwkopt;
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 h_dim1 = *ldh;
00252 h_offset = 1 + h_dim1;
00253 h__ -= h_offset;
00254 z_dim1 = *ldz;
00255 z_offset = 1 + z_dim1;
00256 z__ -= z_offset;
00257 --sr;
00258 --si;
00259 v_dim1 = *ldv;
00260 v_offset = 1 + v_dim1;
00261 v -= v_offset;
00262 t_dim1 = *ldt;
00263 t_offset = 1 + t_dim1;
00264 t -= t_offset;
00265 wv_dim1 = *ldwv;
00266 wv_offset = 1 + wv_dim1;
00267 wv -= wv_offset;
00268 --work;
00269
00270
00271
00272 i__1 = *nw, i__2 = *kbot - *ktop + 1;
00273 jw = min(i__1,i__2);
00274 if (jw <= 2) {
00275 lwkopt = 1;
00276 } else {
00277
00278
00279
00280 i__1 = jw - 1;
00281 dgehrd_(&jw, &c__1, &i__1, &t[t_offset], ldt, &work[1], &work[1], &
00282 c_n1, &info);
00283 lwk1 = (integer) work[1];
00284
00285
00286
00287 i__1 = jw - 1;
00288 dormhr_("R", "N", &jw, &jw, &c__1, &i__1, &t[t_offset], ldt, &work[1],
00289 &v[v_offset], ldv, &work[1], &c_n1, &info);
00290 lwk2 = (integer) work[1];
00291
00292
00293
00294 lwkopt = jw + max(lwk1,lwk2);
00295 }
00296
00297
00298
00299 if (*lwork == -1) {
00300 work[1] = (doublereal) lwkopt;
00301 return 0;
00302 }
00303
00304
00305
00306 *ns = 0;
00307 *nd = 0;
00308 work[1] = 1.;
00309 if (*ktop > *kbot) {
00310 return 0;
00311 }
00312
00313 if (*nw < 1) {
00314 return 0;
00315 }
00316
00317
00318
00319 safmin = dlamch_("SAFE MINIMUM");
00320 safmax = 1. / safmin;
00321 dlabad_(&safmin, &safmax);
00322 ulp = dlamch_("PRECISION");
00323 smlnum = safmin * ((doublereal) (*n) / ulp);
00324
00325
00326
00327
00328 i__1 = *nw, i__2 = *kbot - *ktop + 1;
00329 jw = min(i__1,i__2);
00330 kwtop = *kbot - jw + 1;
00331 if (kwtop == *ktop) {
00332 s = 0.;
00333 } else {
00334 s = h__[kwtop + (kwtop - 1) * h_dim1];
00335 }
00336
00337 if (*kbot == kwtop) {
00338
00339
00340
00341 sr[kwtop] = h__[kwtop + kwtop * h_dim1];
00342 si[kwtop] = 0.;
00343 *ns = 1;
00344 *nd = 0;
00345
00346 d__2 = smlnum, d__3 = ulp * (d__1 = h__[kwtop + kwtop * h_dim1], abs(
00347 d__1));
00348 if (abs(s) <= max(d__2,d__3)) {
00349 *ns = 0;
00350 *nd = 1;
00351 if (kwtop > *ktop) {
00352 h__[kwtop + (kwtop - 1) * h_dim1] = 0.;
00353 }
00354 }
00355 work[1] = 1.;
00356 return 0;
00357 }
00358
00359
00360
00361
00362
00363
00364
00365 dlacpy_("U", &jw, &jw, &h__[kwtop + kwtop * h_dim1], ldh, &t[t_offset],
00366 ldt);
00367 i__1 = jw - 1;
00368 i__2 = *ldh + 1;
00369 i__3 = *ldt + 1;
00370 dcopy_(&i__1, &h__[kwtop + 1 + kwtop * h_dim1], &i__2, &t[t_dim1 + 2], &
00371 i__3);
00372
00373 dlaset_("A", &jw, &jw, &c_b12, &c_b13, &v[v_offset], ldv);
00374 dlahqr_(&c_true, &c_true, &jw, &c__1, &jw, &t[t_offset], ldt, &sr[kwtop],
00375 &si[kwtop], &c__1, &jw, &v[v_offset], ldv, &infqr);
00376
00377
00378
00379 i__1 = jw - 3;
00380 for (j = 1; j <= i__1; ++j) {
00381 t[j + 2 + j * t_dim1] = 0.;
00382 t[j + 3 + j * t_dim1] = 0.;
00383
00384 }
00385 if (jw > 2) {
00386 t[jw + (jw - 2) * t_dim1] = 0.;
00387 }
00388
00389
00390
00391 *ns = jw;
00392 ilst = infqr + 1;
00393 L20:
00394 if (ilst <= *ns) {
00395 if (*ns == 1) {
00396 bulge = FALSE_;
00397 } else {
00398 bulge = t[*ns + (*ns - 1) * t_dim1] != 0.;
00399 }
00400
00401
00402
00403 if (! bulge) {
00404
00405
00406
00407 foo = (d__1 = t[*ns + *ns * t_dim1], abs(d__1));
00408 if (foo == 0.) {
00409 foo = abs(s);
00410 }
00411
00412 d__2 = smlnum, d__3 = ulp * foo;
00413 if ((d__1 = s * v[*ns * v_dim1 + 1], abs(d__1)) <= max(d__2,d__3))
00414 {
00415
00416
00417
00418 --(*ns);
00419 } else {
00420
00421
00422
00423
00424 ifst = *ns;
00425 dtrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst,
00426 &ilst, &work[1], &info);
00427 ++ilst;
00428 }
00429 } else {
00430
00431
00432
00433 foo = (d__3 = t[*ns + *ns * t_dim1], abs(d__3)) + sqrt((d__1 = t[*
00434 ns + (*ns - 1) * t_dim1], abs(d__1))) * sqrt((d__2 = t[*
00435 ns - 1 + *ns * t_dim1], abs(d__2)));
00436 if (foo == 0.) {
00437 foo = abs(s);
00438 }
00439
00440 d__3 = (d__1 = s * v[*ns * v_dim1 + 1], abs(d__1)), d__4 = (d__2 =
00441 s * v[(*ns - 1) * v_dim1 + 1], abs(d__2));
00442
00443 d__5 = smlnum, d__6 = ulp * foo;
00444 if (max(d__3,d__4) <= max(d__5,d__6)) {
00445
00446
00447
00448 *ns += -2;
00449 } else {
00450
00451
00452
00453
00454
00455 ifst = *ns;
00456 dtrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst,
00457 &ilst, &work[1], &info);
00458 ilst += 2;
00459 }
00460 }
00461
00462
00463
00464 goto L20;
00465 }
00466
00467
00468
00469 if (*ns == 0) {
00470 s = 0.;
00471 }
00472
00473 if (*ns < jw) {
00474
00475
00476
00477
00478
00479 sorted = FALSE_;
00480 i__ = *ns + 1;
00481 L30:
00482 if (sorted) {
00483 goto L50;
00484 }
00485 sorted = TRUE_;
00486
00487 kend = i__ - 1;
00488 i__ = infqr + 1;
00489 if (i__ == *ns) {
00490 k = i__ + 1;
00491 } else if (t[i__ + 1 + i__ * t_dim1] == 0.) {
00492 k = i__ + 1;
00493 } else {
00494 k = i__ + 2;
00495 }
00496 L40:
00497 if (k <= kend) {
00498 if (k == i__ + 1) {
00499 evi = (d__1 = t[i__ + i__ * t_dim1], abs(d__1));
00500 } else {
00501 evi = (d__3 = t[i__ + i__ * t_dim1], abs(d__3)) + sqrt((d__1 =
00502 t[i__ + 1 + i__ * t_dim1], abs(d__1))) * sqrt((d__2 =
00503 t[i__ + (i__ + 1) * t_dim1], abs(d__2)));
00504 }
00505
00506 if (k == kend) {
00507 evk = (d__1 = t[k + k * t_dim1], abs(d__1));
00508 } else if (t[k + 1 + k * t_dim1] == 0.) {
00509 evk = (d__1 = t[k + k * t_dim1], abs(d__1));
00510 } else {
00511 evk = (d__3 = t[k + k * t_dim1], abs(d__3)) + sqrt((d__1 = t[
00512 k + 1 + k * t_dim1], abs(d__1))) * sqrt((d__2 = t[k +
00513 (k + 1) * t_dim1], abs(d__2)));
00514 }
00515
00516 if (evi >= evk) {
00517 i__ = k;
00518 } else {
00519 sorted = FALSE_;
00520 ifst = i__;
00521 ilst = k;
00522 dtrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst,
00523 &ilst, &work[1], &info);
00524 if (info == 0) {
00525 i__ = ilst;
00526 } else {
00527 i__ = k;
00528 }
00529 }
00530 if (i__ == kend) {
00531 k = i__ + 1;
00532 } else if (t[i__ + 1 + i__ * t_dim1] == 0.) {
00533 k = i__ + 1;
00534 } else {
00535 k = i__ + 2;
00536 }
00537 goto L40;
00538 }
00539 goto L30;
00540 L50:
00541 ;
00542 }
00543
00544
00545
00546 i__ = jw;
00547 L60:
00548 if (i__ >= infqr + 1) {
00549 if (i__ == infqr + 1) {
00550 sr[kwtop + i__ - 1] = t[i__ + i__ * t_dim1];
00551 si[kwtop + i__ - 1] = 0.;
00552 --i__;
00553 } else if (t[i__ + (i__ - 1) * t_dim1] == 0.) {
00554 sr[kwtop + i__ - 1] = t[i__ + i__ * t_dim1];
00555 si[kwtop + i__ - 1] = 0.;
00556 --i__;
00557 } else {
00558 aa = t[i__ - 1 + (i__ - 1) * t_dim1];
00559 cc = t[i__ + (i__ - 1) * t_dim1];
00560 bb = t[i__ - 1 + i__ * t_dim1];
00561 dd = t[i__ + i__ * t_dim1];
00562 dlanv2_(&aa, &bb, &cc, &dd, &sr[kwtop + i__ - 2], &si[kwtop + i__
00563 - 2], &sr[kwtop + i__ - 1], &si[kwtop + i__ - 1], &cs, &
00564 sn);
00565 i__ += -2;
00566 }
00567 goto L60;
00568 }
00569
00570 if (*ns < jw || s == 0.) {
00571 if (*ns > 1 && s != 0.) {
00572
00573
00574
00575 dcopy_(ns, &v[v_offset], ldv, &work[1], &c__1);
00576 beta = work[1];
00577 dlarfg_(ns, &beta, &work[2], &c__1, &tau);
00578 work[1] = 1.;
00579
00580 i__1 = jw - 2;
00581 i__2 = jw - 2;
00582 dlaset_("L", &i__1, &i__2, &c_b12, &c_b12, &t[t_dim1 + 3], ldt);
00583
00584 dlarf_("L", ns, &jw, &work[1], &c__1, &tau, &t[t_offset], ldt, &
00585 work[jw + 1]);
00586 dlarf_("R", ns, ns, &work[1], &c__1, &tau, &t[t_offset], ldt, &
00587 work[jw + 1]);
00588 dlarf_("R", &jw, ns, &work[1], &c__1, &tau, &v[v_offset], ldv, &
00589 work[jw + 1]);
00590
00591 i__1 = *lwork - jw;
00592 dgehrd_(&jw, &c__1, ns, &t[t_offset], ldt, &work[1], &work[jw + 1]
00593 , &i__1, &info);
00594 }
00595
00596
00597
00598 if (kwtop > 1) {
00599 h__[kwtop + (kwtop - 1) * h_dim1] = s * v[v_dim1 + 1];
00600 }
00601 dlacpy_("U", &jw, &jw, &t[t_offset], ldt, &h__[kwtop + kwtop * h_dim1]
00602 , ldh);
00603 i__1 = jw - 1;
00604 i__2 = *ldt + 1;
00605 i__3 = *ldh + 1;
00606 dcopy_(&i__1, &t[t_dim1 + 2], &i__2, &h__[kwtop + 1 + kwtop * h_dim1],
00607 &i__3);
00608
00609
00610
00611
00612 if (*ns > 1 && s != 0.) {
00613 i__1 = *lwork - jw;
00614 dormhr_("R", "N", &jw, ns, &c__1, ns, &t[t_offset], ldt, &work[1],
00615 &v[v_offset], ldv, &work[jw + 1], &i__1, &info);
00616 }
00617
00618
00619
00620 if (*wantt) {
00621 ltop = 1;
00622 } else {
00623 ltop = *ktop;
00624 }
00625 i__1 = kwtop - 1;
00626 i__2 = *nv;
00627 for (krow = ltop; i__2 < 0 ? krow >= i__1 : krow <= i__1; krow +=
00628 i__2) {
00629
00630 i__3 = *nv, i__4 = kwtop - krow;
00631 kln = min(i__3,i__4);
00632 dgemm_("N", "N", &kln, &jw, &jw, &c_b13, &h__[krow + kwtop *
00633 h_dim1], ldh, &v[v_offset], ldv, &c_b12, &wv[wv_offset],
00634 ldwv);
00635 dlacpy_("A", &kln, &jw, &wv[wv_offset], ldwv, &h__[krow + kwtop *
00636 h_dim1], ldh);
00637
00638 }
00639
00640
00641
00642 if (*wantt) {
00643 i__2 = *n;
00644 i__1 = *nh;
00645 for (kcol = *kbot + 1; i__1 < 0 ? kcol >= i__2 : kcol <= i__2;
00646 kcol += i__1) {
00647
00648 i__3 = *nh, i__4 = *n - kcol + 1;
00649 kln = min(i__3,i__4);
00650 dgemm_("C", "N", &jw, &kln, &jw, &c_b13, &v[v_offset], ldv, &
00651 h__[kwtop + kcol * h_dim1], ldh, &c_b12, &t[t_offset],
00652 ldt);
00653 dlacpy_("A", &jw, &kln, &t[t_offset], ldt, &h__[kwtop + kcol *
00654 h_dim1], ldh);
00655
00656 }
00657 }
00658
00659
00660
00661 if (*wantz) {
00662 i__1 = *ihiz;
00663 i__2 = *nv;
00664 for (krow = *iloz; i__2 < 0 ? krow >= i__1 : krow <= i__1; krow +=
00665 i__2) {
00666
00667 i__3 = *nv, i__4 = *ihiz - krow + 1;
00668 kln = min(i__3,i__4);
00669 dgemm_("N", "N", &kln, &jw, &jw, &c_b13, &z__[krow + kwtop *
00670 z_dim1], ldz, &v[v_offset], ldv, &c_b12, &wv[
00671 wv_offset], ldwv);
00672 dlacpy_("A", &kln, &jw, &wv[wv_offset], ldwv, &z__[krow +
00673 kwtop * z_dim1], ldz);
00674
00675 }
00676 }
00677 }
00678
00679
00680
00681 *nd = jw - *ns;
00682
00683
00684
00685
00686
00687
00688
00689 *ns -= infqr;
00690
00691
00692
00693 work[1] = (doublereal) lwkopt;
00694
00695
00696
00697 return 0;
00698 }