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 complex c_b1 = {0.f,0.f};
00019 static complex c_b2 = {1.f,0.f};
00020 static integer c__1 = 1;
00021 static real c_b39 = -1.f;
00022 static real c_b42 = 1.f;
00023
00024 int ctgsja_(char *jobu, char *jobv, char *jobq, integer *m,
00025 integer *p, integer *n, integer *k, integer *l, complex *a, integer *
00026 lda, complex *b, integer *ldb, real *tola, real *tolb, real *alpha,
00027 real *beta, complex *u, integer *ldu, complex *v, integer *ldv,
00028 complex *q, integer *ldq, complex *work, integer *ncycle, integer *
00029 info)
00030 {
00031
00032 integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, u_dim1,
00033 u_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4;
00034 real r__1;
00035 complex q__1;
00036
00037
00038 void r_cnjg(complex *, complex *);
00039
00040
00041 integer i__, j;
00042 real a1, b1, a3, b3;
00043 complex a2, b2;
00044 real csq, csu, csv;
00045 complex snq;
00046 real rwk;
00047 complex snu, snv;
00048 extern int crot_(integer *, complex *, integer *,
00049 complex *, integer *, real *, complex *);
00050 real gamma;
00051 extern logical lsame_(char *, char *);
00052 extern int ccopy_(integer *, complex *, integer *,
00053 complex *, integer *);
00054 logical initq, initu, initv, wantq, upper;
00055 real error, ssmin;
00056 logical wantu, wantv;
00057 extern int clags2_(logical *, real *, complex *, real *,
00058 real *, complex *, real *, real *, complex *, real *, complex *,
00059 real *, complex *), clapll_(integer *, complex *, integer *,
00060 complex *, integer *, real *), csscal_(integer *, real *, complex
00061 *, integer *);
00062 integer kcycle;
00063 extern int claset_(char *, integer *, integer *, complex
00064 *, complex *, complex *, integer *), xerbla_(char *,
00065 integer *), slartg_(real *, real *, real *, real *, real *
00066 );
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
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
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 a_dim1 = *lda;
00335 a_offset = 1 + a_dim1;
00336 a -= a_offset;
00337 b_dim1 = *ldb;
00338 b_offset = 1 + b_dim1;
00339 b -= b_offset;
00340 --alpha;
00341 --beta;
00342 u_dim1 = *ldu;
00343 u_offset = 1 + u_dim1;
00344 u -= u_offset;
00345 v_dim1 = *ldv;
00346 v_offset = 1 + v_dim1;
00347 v -= v_offset;
00348 q_dim1 = *ldq;
00349 q_offset = 1 + q_dim1;
00350 q -= q_offset;
00351 --work;
00352
00353
00354 initu = lsame_(jobu, "I");
00355 wantu = initu || lsame_(jobu, "U");
00356
00357 initv = lsame_(jobv, "I");
00358 wantv = initv || lsame_(jobv, "V");
00359
00360 initq = lsame_(jobq, "I");
00361 wantq = initq || lsame_(jobq, "Q");
00362
00363 *info = 0;
00364 if (! (initu || wantu || lsame_(jobu, "N"))) {
00365 *info = -1;
00366 } else if (! (initv || wantv || lsame_(jobv, "N")))
00367 {
00368 *info = -2;
00369 } else if (! (initq || wantq || lsame_(jobq, "N")))
00370 {
00371 *info = -3;
00372 } else if (*m < 0) {
00373 *info = -4;
00374 } else if (*p < 0) {
00375 *info = -5;
00376 } else if (*n < 0) {
00377 *info = -6;
00378 } else if (*lda < max(1,*m)) {
00379 *info = -10;
00380 } else if (*ldb < max(1,*p)) {
00381 *info = -12;
00382 } else if (*ldu < 1 || wantu && *ldu < *m) {
00383 *info = -18;
00384 } else if (*ldv < 1 || wantv && *ldv < *p) {
00385 *info = -20;
00386 } else if (*ldq < 1 || wantq && *ldq < *n) {
00387 *info = -22;
00388 }
00389 if (*info != 0) {
00390 i__1 = -(*info);
00391 xerbla_("CTGSJA", &i__1);
00392 return 0;
00393 }
00394
00395
00396
00397 if (initu) {
00398 claset_("Full", m, m, &c_b1, &c_b2, &u[u_offset], ldu);
00399 }
00400 if (initv) {
00401 claset_("Full", p, p, &c_b1, &c_b2, &v[v_offset], ldv);
00402 }
00403 if (initq) {
00404 claset_("Full", n, n, &c_b1, &c_b2, &q[q_offset], ldq);
00405 }
00406
00407
00408
00409 upper = FALSE_;
00410 for (kcycle = 1; kcycle <= 40; ++kcycle) {
00411
00412 upper = ! upper;
00413
00414 i__1 = *l - 1;
00415 for (i__ = 1; i__ <= i__1; ++i__) {
00416 i__2 = *l;
00417 for (j = i__ + 1; j <= i__2; ++j) {
00418
00419 a1 = 0.f;
00420 a2.r = 0.f, a2.i = 0.f;
00421 a3 = 0.f;
00422 if (*k + i__ <= *m) {
00423 i__3 = *k + i__ + (*n - *l + i__) * a_dim1;
00424 a1 = a[i__3].r;
00425 }
00426 if (*k + j <= *m) {
00427 i__3 = *k + j + (*n - *l + j) * a_dim1;
00428 a3 = a[i__3].r;
00429 }
00430
00431 i__3 = i__ + (*n - *l + i__) * b_dim1;
00432 b1 = b[i__3].r;
00433 i__3 = j + (*n - *l + j) * b_dim1;
00434 b3 = b[i__3].r;
00435
00436 if (upper) {
00437 if (*k + i__ <= *m) {
00438 i__3 = *k + i__ + (*n - *l + j) * a_dim1;
00439 a2.r = a[i__3].r, a2.i = a[i__3].i;
00440 }
00441 i__3 = i__ + (*n - *l + j) * b_dim1;
00442 b2.r = b[i__3].r, b2.i = b[i__3].i;
00443 } else {
00444 if (*k + j <= *m) {
00445 i__3 = *k + j + (*n - *l + i__) * a_dim1;
00446 a2.r = a[i__3].r, a2.i = a[i__3].i;
00447 }
00448 i__3 = j + (*n - *l + i__) * b_dim1;
00449 b2.r = b[i__3].r, b2.i = b[i__3].i;
00450 }
00451
00452 clags2_(&upper, &a1, &a2, &a3, &b1, &b2, &b3, &csu, &snu, &
00453 csv, &snv, &csq, &snq);
00454
00455
00456
00457 if (*k + j <= *m) {
00458 r_cnjg(&q__1, &snu);
00459 crot_(l, &a[*k + j + (*n - *l + 1) * a_dim1], lda, &a[*k
00460 + i__ + (*n - *l + 1) * a_dim1], lda, &csu, &q__1)
00461 ;
00462 }
00463
00464
00465
00466 r_cnjg(&q__1, &snv);
00467 crot_(l, &b[j + (*n - *l + 1) * b_dim1], ldb, &b[i__ + (*n - *
00468 l + 1) * b_dim1], ldb, &csv, &q__1);
00469
00470
00471
00472
00473
00474 i__4 = *k + *l;
00475 i__3 = min(i__4,*m);
00476 crot_(&i__3, &a[(*n - *l + j) * a_dim1 + 1], &c__1, &a[(*n - *
00477 l + i__) * a_dim1 + 1], &c__1, &csq, &snq);
00478
00479 crot_(l, &b[(*n - *l + j) * b_dim1 + 1], &c__1, &b[(*n - *l +
00480 i__) * b_dim1 + 1], &c__1, &csq, &snq);
00481
00482 if (upper) {
00483 if (*k + i__ <= *m) {
00484 i__3 = *k + i__ + (*n - *l + j) * a_dim1;
00485 a[i__3].r = 0.f, a[i__3].i = 0.f;
00486 }
00487 i__3 = i__ + (*n - *l + j) * b_dim1;
00488 b[i__3].r = 0.f, b[i__3].i = 0.f;
00489 } else {
00490 if (*k + j <= *m) {
00491 i__3 = *k + j + (*n - *l + i__) * a_dim1;
00492 a[i__3].r = 0.f, a[i__3].i = 0.f;
00493 }
00494 i__3 = j + (*n - *l + i__) * b_dim1;
00495 b[i__3].r = 0.f, b[i__3].i = 0.f;
00496 }
00497
00498
00499
00500 if (*k + i__ <= *m) {
00501 i__3 = *k + i__ + (*n - *l + i__) * a_dim1;
00502 i__4 = *k + i__ + (*n - *l + i__) * a_dim1;
00503 r__1 = a[i__4].r;
00504 a[i__3].r = r__1, a[i__3].i = 0.f;
00505 }
00506 if (*k + j <= *m) {
00507 i__3 = *k + j + (*n - *l + j) * a_dim1;
00508 i__4 = *k + j + (*n - *l + j) * a_dim1;
00509 r__1 = a[i__4].r;
00510 a[i__3].r = r__1, a[i__3].i = 0.f;
00511 }
00512 i__3 = i__ + (*n - *l + i__) * b_dim1;
00513 i__4 = i__ + (*n - *l + i__) * b_dim1;
00514 r__1 = b[i__4].r;
00515 b[i__3].r = r__1, b[i__3].i = 0.f;
00516 i__3 = j + (*n - *l + j) * b_dim1;
00517 i__4 = j + (*n - *l + j) * b_dim1;
00518 r__1 = b[i__4].r;
00519 b[i__3].r = r__1, b[i__3].i = 0.f;
00520
00521
00522
00523 if (wantu && *k + j <= *m) {
00524 crot_(m, &u[(*k + j) * u_dim1 + 1], &c__1, &u[(*k + i__) *
00525 u_dim1 + 1], &c__1, &csu, &snu);
00526 }
00527
00528 if (wantv) {
00529 crot_(p, &v[j * v_dim1 + 1], &c__1, &v[i__ * v_dim1 + 1],
00530 &c__1, &csv, &snv);
00531 }
00532
00533 if (wantq) {
00534 crot_(n, &q[(*n - *l + j) * q_dim1 + 1], &c__1, &q[(*n - *
00535 l + i__) * q_dim1 + 1], &c__1, &csq, &snq);
00536 }
00537
00538
00539 }
00540
00541 }
00542
00543 if (! upper) {
00544
00545
00546
00547
00548
00549
00550
00551 error = 0.f;
00552
00553 i__2 = *l, i__3 = *m - *k;
00554 i__1 = min(i__2,i__3);
00555 for (i__ = 1; i__ <= i__1; ++i__) {
00556 i__2 = *l - i__ + 1;
00557 ccopy_(&i__2, &a[*k + i__ + (*n - *l + i__) * a_dim1], lda, &
00558 work[1], &c__1);
00559 i__2 = *l - i__ + 1;
00560 ccopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &work[*
00561 l + 1], &c__1);
00562 i__2 = *l - i__ + 1;
00563 clapll_(&i__2, &work[1], &c__1, &work[*l + 1], &c__1, &ssmin);
00564 error = dmax(error,ssmin);
00565
00566 }
00567
00568 if (dabs(error) <= dmin(*tola,*tolb)) {
00569 goto L50;
00570 }
00571 }
00572
00573
00574
00575
00576 }
00577
00578
00579
00580 *info = 1;
00581 goto L100;
00582
00583 L50:
00584
00585
00586
00587
00588
00589 i__1 = *k;
00590 for (i__ = 1; i__ <= i__1; ++i__) {
00591 alpha[i__] = 1.f;
00592 beta[i__] = 0.f;
00593
00594 }
00595
00596
00597 i__2 = *l, i__3 = *m - *k;
00598 i__1 = min(i__2,i__3);
00599 for (i__ = 1; i__ <= i__1; ++i__) {
00600
00601 i__2 = *k + i__ + (*n - *l + i__) * a_dim1;
00602 a1 = a[i__2].r;
00603 i__2 = i__ + (*n - *l + i__) * b_dim1;
00604 b1 = b[i__2].r;
00605
00606 if (a1 != 0.f) {
00607 gamma = b1 / a1;
00608
00609 if (gamma < 0.f) {
00610 i__2 = *l - i__ + 1;
00611 csscal_(&i__2, &c_b39, &b[i__ + (*n - *l + i__) * b_dim1],
00612 ldb);
00613 if (wantv) {
00614 csscal_(p, &c_b39, &v[i__ * v_dim1 + 1], &c__1);
00615 }
00616 }
00617
00618 r__1 = dabs(gamma);
00619 slartg_(&r__1, &c_b42, &beta[*k + i__], &alpha[*k + i__], &rwk);
00620
00621 if (alpha[*k + i__] >= beta[*k + i__]) {
00622 i__2 = *l - i__ + 1;
00623 r__1 = 1.f / alpha[*k + i__];
00624 csscal_(&i__2, &r__1, &a[*k + i__ + (*n - *l + i__) * a_dim1],
00625 lda);
00626 } else {
00627 i__2 = *l - i__ + 1;
00628 r__1 = 1.f / beta[*k + i__];
00629 csscal_(&i__2, &r__1, &b[i__ + (*n - *l + i__) * b_dim1], ldb)
00630 ;
00631 i__2 = *l - i__ + 1;
00632 ccopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k
00633 + i__ + (*n - *l + i__) * a_dim1], lda);
00634 }
00635
00636 } else {
00637 alpha[*k + i__] = 0.f;
00638 beta[*k + i__] = 1.f;
00639 i__2 = *l - i__ + 1;
00640 ccopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k +
00641 i__ + (*n - *l + i__) * a_dim1], lda);
00642 }
00643
00644 }
00645
00646
00647
00648 i__1 = *k + *l;
00649 for (i__ = *m + 1; i__ <= i__1; ++i__) {
00650 alpha[i__] = 0.f;
00651 beta[i__] = 1.f;
00652
00653 }
00654
00655 if (*k + *l < *n) {
00656 i__1 = *n;
00657 for (i__ = *k + *l + 1; i__ <= i__1; ++i__) {
00658 alpha[i__] = 0.f;
00659 beta[i__] = 0.f;
00660
00661 }
00662 }
00663
00664 L100:
00665 *ncycle = kcycle;
00666
00667 return 0;
00668
00669
00670
00671 }