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 doublecomplex c_b1 = {0.,0.};
00019 static doublecomplex c_b2 = {1.,0.};
00020 static integer c__1 = 1;
00021 static integer c_n1 = -1;
00022 static logical c_true = TRUE_;
00023 static integer c__12 = 12;
00024
00025 int zlaqr3_(logical *wantt, logical *wantz, integer *n,
00026 integer *ktop, integer *kbot, integer *nw, doublecomplex *h__,
00027 integer *ldh, integer *iloz, integer *ihiz, doublecomplex *z__,
00028 integer *ldz, integer *ns, integer *nd, doublecomplex *sh,
00029 doublecomplex *v, integer *ldv, integer *nh, doublecomplex *t,
00030 integer *ldt, integer *nv, doublecomplex *wv, integer *ldwv,
00031 doublecomplex *work, integer *lwork)
00032 {
00033
00034 integer h_dim1, h_offset, t_dim1, t_offset, v_dim1, v_offset, wv_dim1,
00035 wv_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4;
00036 doublereal d__1, d__2, d__3, d__4, d__5, d__6;
00037 doublecomplex z__1, z__2;
00038
00039
00040 double d_imag(doublecomplex *);
00041 void d_cnjg(doublecomplex *, doublecomplex *);
00042
00043
00044 integer i__, j;
00045 doublecomplex s;
00046 integer jw;
00047 doublereal foo;
00048 integer kln;
00049 doublecomplex tau;
00050 integer knt;
00051 doublereal ulp;
00052 integer lwk1, lwk2, lwk3;
00053 doublecomplex beta;
00054 integer kcol, info, nmin, ifst, ilst, ltop, krow;
00055 extern int zlarf_(char *, integer *, integer *,
00056 doublecomplex *, integer *, doublecomplex *, doublecomplex *,
00057 integer *, doublecomplex *);
00058 integer infqr;
00059 extern int zgemm_(char *, char *, integer *, integer *,
00060 integer *, doublecomplex *, doublecomplex *, integer *,
00061 doublecomplex *, integer *, doublecomplex *, doublecomplex *,
00062 integer *);
00063 integer kwtop;
00064 extern int zcopy_(integer *, doublecomplex *, integer *,
00065 doublecomplex *, integer *), dlabad_(doublereal *, doublereal *),
00066 zlaqr4_(logical *, logical *, integer *, integer *, integer *,
00067 doublecomplex *, integer *, doublecomplex *, integer *, integer *,
00068 doublecomplex *, integer *, doublecomplex *, integer *, integer *
00069 );
00070 extern doublereal dlamch_(char *);
00071 doublereal safmin;
00072 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00073 integer *, integer *);
00074 doublereal safmax;
00075 extern int zgehrd_(integer *, integer *, integer *,
00076 doublecomplex *, integer *, doublecomplex *, doublecomplex *,
00077 integer *, integer *), zlarfg_(integer *, doublecomplex *,
00078 doublecomplex *, integer *, doublecomplex *), zlahqr_(logical *,
00079 logical *, integer *, integer *, integer *, doublecomplex *,
00080 integer *, doublecomplex *, integer *, integer *, doublecomplex *,
00081 integer *, integer *), zlacpy_(char *, integer *, integer *,
00082 doublecomplex *, integer *, doublecomplex *, integer *),
00083 zlaset_(char *, integer *, integer *, doublecomplex *,
00084 doublecomplex *, doublecomplex *, integer *);
00085 doublereal smlnum;
00086 extern int ztrexc_(char *, integer *, doublecomplex *,
00087 integer *, doublecomplex *, integer *, integer *, integer *,
00088 integer *);
00089 integer lwkopt;
00090 extern int zunmhr_(char *, char *, integer *, integer *,
00091 integer *, integer *, doublecomplex *, integer *, doublecomplex *,
00092 doublecomplex *, integer *, doublecomplex *, integer *, integer *
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 h_dim1 = *ldh;
00258 h_offset = 1 + h_dim1;
00259 h__ -= h_offset;
00260 z_dim1 = *ldz;
00261 z_offset = 1 + z_dim1;
00262 z__ -= z_offset;
00263 --sh;
00264 v_dim1 = *ldv;
00265 v_offset = 1 + v_dim1;
00266 v -= v_offset;
00267 t_dim1 = *ldt;
00268 t_offset = 1 + t_dim1;
00269 t -= t_offset;
00270 wv_dim1 = *ldwv;
00271 wv_offset = 1 + wv_dim1;
00272 wv -= wv_offset;
00273 --work;
00274
00275
00276
00277 i__1 = *nw, i__2 = *kbot - *ktop + 1;
00278 jw = min(i__1,i__2);
00279 if (jw <= 2) {
00280 lwkopt = 1;
00281 } else {
00282
00283
00284
00285 i__1 = jw - 1;
00286 zgehrd_(&jw, &c__1, &i__1, &t[t_offset], ldt, &work[1], &work[1], &
00287 c_n1, &info);
00288 lwk1 = (integer) work[1].r;
00289
00290
00291
00292 i__1 = jw - 1;
00293 zunmhr_("R", "N", &jw, &jw, &c__1, &i__1, &t[t_offset], ldt, &work[1],
00294 &v[v_offset], ldv, &work[1], &c_n1, &info);
00295 lwk2 = (integer) work[1].r;
00296
00297
00298
00299 zlaqr4_(&c_true, &c_true, &jw, &c__1, &jw, &t[t_offset], ldt, &sh[1],
00300 &c__1, &jw, &v[v_offset], ldv, &work[1], &c_n1, &infqr);
00301 lwk3 = (integer) work[1].r;
00302
00303
00304
00305
00306 i__1 = jw + max(lwk1,lwk2);
00307 lwkopt = max(i__1,lwk3);
00308 }
00309
00310
00311
00312 if (*lwork == -1) {
00313 d__1 = (doublereal) lwkopt;
00314 z__1.r = d__1, z__1.i = 0.;
00315 work[1].r = z__1.r, work[1].i = z__1.i;
00316 return 0;
00317 }
00318
00319
00320
00321 *ns = 0;
00322 *nd = 0;
00323 work[1].r = 1., work[1].i = 0.;
00324 if (*ktop > *kbot) {
00325 return 0;
00326 }
00327
00328 if (*nw < 1) {
00329 return 0;
00330 }
00331
00332
00333
00334 safmin = dlamch_("SAFE MINIMUM");
00335 safmax = 1. / safmin;
00336 dlabad_(&safmin, &safmax);
00337 ulp = dlamch_("PRECISION");
00338 smlnum = safmin * ((doublereal) (*n) / ulp);
00339
00340
00341
00342
00343 i__1 = *nw, i__2 = *kbot - *ktop + 1;
00344 jw = min(i__1,i__2);
00345 kwtop = *kbot - jw + 1;
00346 if (kwtop == *ktop) {
00347 s.r = 0., s.i = 0.;
00348 } else {
00349 i__1 = kwtop + (kwtop - 1) * h_dim1;
00350 s.r = h__[i__1].r, s.i = h__[i__1].i;
00351 }
00352
00353 if (*kbot == kwtop) {
00354
00355
00356
00357 i__1 = kwtop;
00358 i__2 = kwtop + kwtop * h_dim1;
00359 sh[i__1].r = h__[i__2].r, sh[i__1].i = h__[i__2].i;
00360 *ns = 1;
00361 *nd = 0;
00362
00363 i__1 = kwtop + kwtop * h_dim1;
00364 d__5 = smlnum, d__6 = ulp * ((d__1 = h__[i__1].r, abs(d__1)) + (d__2 =
00365 d_imag(&h__[kwtop + kwtop * h_dim1]), abs(d__2)));
00366 if ((d__3 = s.r, abs(d__3)) + (d__4 = d_imag(&s), abs(d__4)) <= max(
00367 d__5,d__6)) {
00368 *ns = 0;
00369 *nd = 1;
00370 if (kwtop > *ktop) {
00371 i__1 = kwtop + (kwtop - 1) * h_dim1;
00372 h__[i__1].r = 0., h__[i__1].i = 0.;
00373 }
00374 }
00375 work[1].r = 1., work[1].i = 0.;
00376 return 0;
00377 }
00378
00379
00380
00381
00382
00383
00384
00385 zlacpy_("U", &jw, &jw, &h__[kwtop + kwtop * h_dim1], ldh, &t[t_offset],
00386 ldt);
00387 i__1 = jw - 1;
00388 i__2 = *ldh + 1;
00389 i__3 = *ldt + 1;
00390 zcopy_(&i__1, &h__[kwtop + 1 + kwtop * h_dim1], &i__2, &t[t_dim1 + 2], &
00391 i__3);
00392
00393 zlaset_("A", &jw, &jw, &c_b1, &c_b2, &v[v_offset], ldv);
00394 nmin = ilaenv_(&c__12, "ZLAQR3", "SV", &jw, &c__1, &jw, lwork);
00395 if (jw > nmin) {
00396 zlaqr4_(&c_true, &c_true, &jw, &c__1, &jw, &t[t_offset], ldt, &sh[
00397 kwtop], &c__1, &jw, &v[v_offset], ldv, &work[1], lwork, &
00398 infqr);
00399 } else {
00400 zlahqr_(&c_true, &c_true, &jw, &c__1, &jw, &t[t_offset], ldt, &sh[
00401 kwtop], &c__1, &jw, &v[v_offset], ldv, &infqr);
00402 }
00403
00404
00405
00406 *ns = jw;
00407 ilst = infqr + 1;
00408 i__1 = jw;
00409 for (knt = infqr + 1; knt <= i__1; ++knt) {
00410
00411
00412
00413 i__2 = *ns + *ns * t_dim1;
00414 foo = (d__1 = t[i__2].r, abs(d__1)) + (d__2 = d_imag(&t[*ns + *ns *
00415 t_dim1]), abs(d__2));
00416 if (foo == 0.) {
00417 foo = (d__1 = s.r, abs(d__1)) + (d__2 = d_imag(&s), abs(d__2));
00418 }
00419 i__2 = *ns * v_dim1 + 1;
00420
00421 d__5 = smlnum, d__6 = ulp * foo;
00422 if (((d__1 = s.r, abs(d__1)) + (d__2 = d_imag(&s), abs(d__2))) * ((
00423 d__3 = v[i__2].r, abs(d__3)) + (d__4 = d_imag(&v[*ns * v_dim1
00424 + 1]), abs(d__4))) <= max(d__5,d__6)) {
00425
00426
00427
00428 --(*ns);
00429 } else {
00430
00431
00432
00433
00434 ifst = *ns;
00435 ztrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst, &
00436 ilst, &info);
00437 ++ilst;
00438 }
00439
00440 }
00441
00442
00443
00444 if (*ns == 0) {
00445 s.r = 0., s.i = 0.;
00446 }
00447
00448 if (*ns < jw) {
00449
00450
00451
00452
00453 i__1 = *ns;
00454 for (i__ = infqr + 1; i__ <= i__1; ++i__) {
00455 ifst = i__;
00456 i__2 = *ns;
00457 for (j = i__ + 1; j <= i__2; ++j) {
00458 i__3 = j + j * t_dim1;
00459 i__4 = ifst + ifst * t_dim1;
00460 if ((d__1 = t[i__3].r, abs(d__1)) + (d__2 = d_imag(&t[j + j *
00461 t_dim1]), abs(d__2)) > (d__3 = t[i__4].r, abs(d__3))
00462 + (d__4 = d_imag(&t[ifst + ifst * t_dim1]), abs(d__4))
00463 ) {
00464 ifst = j;
00465 }
00466
00467 }
00468 ilst = i__;
00469 if (ifst != ilst) {
00470 ztrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst,
00471 &ilst, &info);
00472 }
00473
00474 }
00475 }
00476
00477
00478
00479 i__1 = jw;
00480 for (i__ = infqr + 1; i__ <= i__1; ++i__) {
00481 i__2 = kwtop + i__ - 1;
00482 i__3 = i__ + i__ * t_dim1;
00483 sh[i__2].r = t[i__3].r, sh[i__2].i = t[i__3].i;
00484
00485 }
00486
00487
00488 if (*ns < jw || s.r == 0. && s.i == 0.) {
00489 if (*ns > 1 && (s.r != 0. || s.i != 0.)) {
00490
00491
00492
00493 zcopy_(ns, &v[v_offset], ldv, &work[1], &c__1);
00494 i__1 = *ns;
00495 for (i__ = 1; i__ <= i__1; ++i__) {
00496 i__2 = i__;
00497 d_cnjg(&z__1, &work[i__]);
00498 work[i__2].r = z__1.r, work[i__2].i = z__1.i;
00499
00500 }
00501 beta.r = work[1].r, beta.i = work[1].i;
00502 zlarfg_(ns, &beta, &work[2], &c__1, &tau);
00503 work[1].r = 1., work[1].i = 0.;
00504
00505 i__1 = jw - 2;
00506 i__2 = jw - 2;
00507 zlaset_("L", &i__1, &i__2, &c_b1, &c_b1, &t[t_dim1 + 3], ldt);
00508
00509 d_cnjg(&z__1, &tau);
00510 zlarf_("L", ns, &jw, &work[1], &c__1, &z__1, &t[t_offset], ldt, &
00511 work[jw + 1]);
00512 zlarf_("R", ns, ns, &work[1], &c__1, &tau, &t[t_offset], ldt, &
00513 work[jw + 1]);
00514 zlarf_("R", &jw, ns, &work[1], &c__1, &tau, &v[v_offset], ldv, &
00515 work[jw + 1]);
00516
00517 i__1 = *lwork - jw;
00518 zgehrd_(&jw, &c__1, ns, &t[t_offset], ldt, &work[1], &work[jw + 1]
00519 , &i__1, &info);
00520 }
00521
00522
00523
00524 if (kwtop > 1) {
00525 i__1 = kwtop + (kwtop - 1) * h_dim1;
00526 d_cnjg(&z__2, &v[v_dim1 + 1]);
00527 z__1.r = s.r * z__2.r - s.i * z__2.i, z__1.i = s.r * z__2.i + s.i
00528 * z__2.r;
00529 h__[i__1].r = z__1.r, h__[i__1].i = z__1.i;
00530 }
00531 zlacpy_("U", &jw, &jw, &t[t_offset], ldt, &h__[kwtop + kwtop * h_dim1]
00532 , ldh);
00533 i__1 = jw - 1;
00534 i__2 = *ldt + 1;
00535 i__3 = *ldh + 1;
00536 zcopy_(&i__1, &t[t_dim1 + 2], &i__2, &h__[kwtop + 1 + kwtop * h_dim1],
00537 &i__3);
00538
00539
00540
00541
00542 if (*ns > 1 && (s.r != 0. || s.i != 0.)) {
00543 i__1 = *lwork - jw;
00544 zunmhr_("R", "N", &jw, ns, &c__1, ns, &t[t_offset], ldt, &work[1],
00545 &v[v_offset], ldv, &work[jw + 1], &i__1, &info);
00546 }
00547
00548
00549
00550 if (*wantt) {
00551 ltop = 1;
00552 } else {
00553 ltop = *ktop;
00554 }
00555 i__1 = kwtop - 1;
00556 i__2 = *nv;
00557 for (krow = ltop; i__2 < 0 ? krow >= i__1 : krow <= i__1; krow +=
00558 i__2) {
00559
00560 i__3 = *nv, i__4 = kwtop - krow;
00561 kln = min(i__3,i__4);
00562 zgemm_("N", "N", &kln, &jw, &jw, &c_b2, &h__[krow + kwtop *
00563 h_dim1], ldh, &v[v_offset], ldv, &c_b1, &wv[wv_offset],
00564 ldwv);
00565 zlacpy_("A", &kln, &jw, &wv[wv_offset], ldwv, &h__[krow + kwtop *
00566 h_dim1], ldh);
00567
00568 }
00569
00570
00571
00572 if (*wantt) {
00573 i__2 = *n;
00574 i__1 = *nh;
00575 for (kcol = *kbot + 1; i__1 < 0 ? kcol >= i__2 : kcol <= i__2;
00576 kcol += i__1) {
00577
00578 i__3 = *nh, i__4 = *n - kcol + 1;
00579 kln = min(i__3,i__4);
00580 zgemm_("C", "N", &jw, &kln, &jw, &c_b2, &v[v_offset], ldv, &
00581 h__[kwtop + kcol * h_dim1], ldh, &c_b1, &t[t_offset],
00582 ldt);
00583 zlacpy_("A", &jw, &kln, &t[t_offset], ldt, &h__[kwtop + kcol *
00584 h_dim1], ldh);
00585
00586 }
00587 }
00588
00589
00590
00591 if (*wantz) {
00592 i__1 = *ihiz;
00593 i__2 = *nv;
00594 for (krow = *iloz; i__2 < 0 ? krow >= i__1 : krow <= i__1; krow +=
00595 i__2) {
00596
00597 i__3 = *nv, i__4 = *ihiz - krow + 1;
00598 kln = min(i__3,i__4);
00599 zgemm_("N", "N", &kln, &jw, &jw, &c_b2, &z__[krow + kwtop *
00600 z_dim1], ldz, &v[v_offset], ldv, &c_b1, &wv[wv_offset]
00601 , ldwv);
00602 zlacpy_("A", &kln, &jw, &wv[wv_offset], ldwv, &z__[krow +
00603 kwtop * z_dim1], ldz);
00604
00605 }
00606 }
00607 }
00608
00609
00610
00611 *nd = jw - *ns;
00612
00613
00614
00615
00616
00617
00618
00619 *ns -= infqr;
00620
00621
00622
00623 d__1 = (doublereal) lwkopt;
00624 z__1.r = d__1, z__1.i = 0.;
00625 work[1].r = z__1.r, work[1].i = z__1.i;
00626
00627
00628
00629 return 0;
00630 }