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
00021 int cggsvp_(char *jobu, char *jobv, char *jobq, integer *m,
00022 integer *p, integer *n, complex *a, integer *lda, complex *b, integer
00023 *ldb, real *tola, real *tolb, integer *k, integer *l, complex *u,
00024 integer *ldu, complex *v, integer *ldv, complex *q, integer *ldq,
00025 integer *iwork, real *rwork, complex *tau, complex *work, integer *
00026 info)
00027 {
00028
00029 integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, u_dim1,
00030 u_offset, v_dim1, v_offset, i__1, i__2, i__3;
00031 real r__1, r__2;
00032
00033
00034 double r_imag(complex *);
00035
00036
00037 integer i__, j;
00038 extern logical lsame_(char *, char *);
00039 logical wantq, wantu, wantv;
00040 extern int cgeqr2_(integer *, integer *, complex *,
00041 integer *, complex *, complex *, integer *), cgerq2_(integer *,
00042 integer *, complex *, integer *, complex *, complex *, integer *),
00043 cung2r_(integer *, integer *, integer *, complex *, integer *,
00044 complex *, complex *, integer *), cunm2r_(char *, char *, integer
00045 *, integer *, integer *, complex *, integer *, complex *, complex
00046 *, integer *, complex *, integer *), cunmr2_(char
00047 *, char *, integer *, integer *, integer *, complex *, integer *,
00048 complex *, complex *, integer *, complex *, integer *), cgeqpf_(integer *, integer *, complex *, integer *,
00049 integer *, complex *, complex *, real *, integer *), clacpy_(char
00050 *, integer *, integer *, complex *, integer *, complex *, integer
00051 *), claset_(char *, integer *, integer *, complex *,
00052 complex *, complex *, integer *), xerbla_(char *, integer
00053 *), clapmt_(logical *, integer *, integer *, complex *,
00054 integer *, integer *);
00055 logical forwrd;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
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 a_dim1 = *lda;
00216 a_offset = 1 + a_dim1;
00217 a -= a_offset;
00218 b_dim1 = *ldb;
00219 b_offset = 1 + b_dim1;
00220 b -= b_offset;
00221 u_dim1 = *ldu;
00222 u_offset = 1 + u_dim1;
00223 u -= u_offset;
00224 v_dim1 = *ldv;
00225 v_offset = 1 + v_dim1;
00226 v -= v_offset;
00227 q_dim1 = *ldq;
00228 q_offset = 1 + q_dim1;
00229 q -= q_offset;
00230 --iwork;
00231 --rwork;
00232 --tau;
00233 --work;
00234
00235
00236 wantu = lsame_(jobu, "U");
00237 wantv = lsame_(jobv, "V");
00238 wantq = lsame_(jobq, "Q");
00239 forwrd = TRUE_;
00240
00241 *info = 0;
00242 if (! (wantu || lsame_(jobu, "N"))) {
00243 *info = -1;
00244 } else if (! (wantv || lsame_(jobv, "N"))) {
00245 *info = -2;
00246 } else if (! (wantq || lsame_(jobq, "N"))) {
00247 *info = -3;
00248 } else if (*m < 0) {
00249 *info = -4;
00250 } else if (*p < 0) {
00251 *info = -5;
00252 } else if (*n < 0) {
00253 *info = -6;
00254 } else if (*lda < max(1,*m)) {
00255 *info = -8;
00256 } else if (*ldb < max(1,*p)) {
00257 *info = -10;
00258 } else if (*ldu < 1 || wantu && *ldu < *m) {
00259 *info = -16;
00260 } else if (*ldv < 1 || wantv && *ldv < *p) {
00261 *info = -18;
00262 } else if (*ldq < 1 || wantq && *ldq < *n) {
00263 *info = -20;
00264 }
00265 if (*info != 0) {
00266 i__1 = -(*info);
00267 xerbla_("CGGSVP", &i__1);
00268 return 0;
00269 }
00270
00271
00272
00273
00274 i__1 = *n;
00275 for (i__ = 1; i__ <= i__1; ++i__) {
00276 iwork[i__] = 0;
00277
00278 }
00279 cgeqpf_(p, n, &b[b_offset], ldb, &iwork[1], &tau[1], &work[1], &rwork[1],
00280 info);
00281
00282
00283
00284 clapmt_(&forwrd, m, n, &a[a_offset], lda, &iwork[1]);
00285
00286
00287
00288 *l = 0;
00289 i__1 = min(*p,*n);
00290 for (i__ = 1; i__ <= i__1; ++i__) {
00291 i__2 = i__ + i__ * b_dim1;
00292 if ((r__1 = b[i__2].r, dabs(r__1)) + (r__2 = r_imag(&b[i__ + i__ *
00293 b_dim1]), dabs(r__2)) > *tolb) {
00294 ++(*l);
00295 }
00296
00297 }
00298
00299 if (wantv) {
00300
00301
00302
00303 claset_("Full", p, p, &c_b1, &c_b1, &v[v_offset], ldv);
00304 if (*p > 1) {
00305 i__1 = *p - 1;
00306 clacpy_("Lower", &i__1, n, &b[b_dim1 + 2], ldb, &v[v_dim1 + 2],
00307 ldv);
00308 }
00309 i__1 = min(*p,*n);
00310 cung2r_(p, p, &i__1, &v[v_offset], ldv, &tau[1], &work[1], info);
00311 }
00312
00313
00314
00315 i__1 = *l - 1;
00316 for (j = 1; j <= i__1; ++j) {
00317 i__2 = *l;
00318 for (i__ = j + 1; i__ <= i__2; ++i__) {
00319 i__3 = i__ + j * b_dim1;
00320 b[i__3].r = 0.f, b[i__3].i = 0.f;
00321
00322 }
00323
00324 }
00325 if (*p > *l) {
00326 i__1 = *p - *l;
00327 claset_("Full", &i__1, n, &c_b1, &c_b1, &b[*l + 1 + b_dim1], ldb);
00328 }
00329
00330 if (wantq) {
00331
00332
00333
00334 claset_("Full", n, n, &c_b1, &c_b2, &q[q_offset], ldq);
00335 clapmt_(&forwrd, n, n, &q[q_offset], ldq, &iwork[1]);
00336 }
00337
00338 if (*p >= *l && *n != *l) {
00339
00340
00341
00342 cgerq2_(l, n, &b[b_offset], ldb, &tau[1], &work[1], info);
00343
00344
00345
00346 cunmr2_("Right", "Conjugate transpose", m, n, l, &b[b_offset], ldb, &
00347 tau[1], &a[a_offset], lda, &work[1], info);
00348 if (wantq) {
00349
00350
00351
00352 cunmr2_("Right", "Conjugate transpose", n, n, l, &b[b_offset],
00353 ldb, &tau[1], &q[q_offset], ldq, &work[1], info);
00354 }
00355
00356
00357
00358 i__1 = *n - *l;
00359 claset_("Full", l, &i__1, &c_b1, &c_b1, &b[b_offset], ldb);
00360 i__1 = *n;
00361 for (j = *n - *l + 1; j <= i__1; ++j) {
00362 i__2 = *l;
00363 for (i__ = j - *n + *l + 1; i__ <= i__2; ++i__) {
00364 i__3 = i__ + j * b_dim1;
00365 b[i__3].r = 0.f, b[i__3].i = 0.f;
00366
00367 }
00368
00369 }
00370
00371 }
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381 i__1 = *n - *l;
00382 for (i__ = 1; i__ <= i__1; ++i__) {
00383 iwork[i__] = 0;
00384
00385 }
00386 i__1 = *n - *l;
00387 cgeqpf_(m, &i__1, &a[a_offset], lda, &iwork[1], &tau[1], &work[1], &rwork[
00388 1], info);
00389
00390
00391
00392 *k = 0;
00393
00394 i__2 = *m, i__3 = *n - *l;
00395 i__1 = min(i__2,i__3);
00396 for (i__ = 1; i__ <= i__1; ++i__) {
00397 i__2 = i__ + i__ * a_dim1;
00398 if ((r__1 = a[i__2].r, dabs(r__1)) + (r__2 = r_imag(&a[i__ + i__ *
00399 a_dim1]), dabs(r__2)) > *tola) {
00400 ++(*k);
00401 }
00402
00403 }
00404
00405
00406
00407
00408 i__2 = *m, i__3 = *n - *l;
00409 i__1 = min(i__2,i__3);
00410 cunm2r_("Left", "Conjugate transpose", m, l, &i__1, &a[a_offset], lda, &
00411 tau[1], &a[(*n - *l + 1) * a_dim1 + 1], lda, &work[1], info);
00412
00413 if (wantu) {
00414
00415
00416
00417 claset_("Full", m, m, &c_b1, &c_b1, &u[u_offset], ldu);
00418 if (*m > 1) {
00419 i__1 = *m - 1;
00420 i__2 = *n - *l;
00421 clacpy_("Lower", &i__1, &i__2, &a[a_dim1 + 2], lda, &u[u_dim1 + 2]
00422 , ldu);
00423 }
00424
00425 i__2 = *m, i__3 = *n - *l;
00426 i__1 = min(i__2,i__3);
00427 cung2r_(m, m, &i__1, &u[u_offset], ldu, &tau[1], &work[1], info);
00428 }
00429
00430 if (wantq) {
00431
00432
00433
00434 i__1 = *n - *l;
00435 clapmt_(&forwrd, n, &i__1, &q[q_offset], ldq, &iwork[1]);
00436 }
00437
00438
00439
00440
00441 i__1 = *k - 1;
00442 for (j = 1; j <= i__1; ++j) {
00443 i__2 = *k;
00444 for (i__ = j + 1; i__ <= i__2; ++i__) {
00445 i__3 = i__ + j * a_dim1;
00446 a[i__3].r = 0.f, a[i__3].i = 0.f;
00447
00448 }
00449
00450 }
00451 if (*m > *k) {
00452 i__1 = *m - *k;
00453 i__2 = *n - *l;
00454 claset_("Full", &i__1, &i__2, &c_b1, &c_b1, &a[*k + 1 + a_dim1], lda);
00455 }
00456
00457 if (*n - *l > *k) {
00458
00459
00460
00461 i__1 = *n - *l;
00462 cgerq2_(k, &i__1, &a[a_offset], lda, &tau[1], &work[1], info);
00463
00464 if (wantq) {
00465
00466
00467
00468 i__1 = *n - *l;
00469 cunmr2_("Right", "Conjugate transpose", n, &i__1, k, &a[a_offset],
00470 lda, &tau[1], &q[q_offset], ldq, &work[1], info);
00471 }
00472
00473
00474
00475 i__1 = *n - *l - *k;
00476 claset_("Full", k, &i__1, &c_b1, &c_b1, &a[a_offset], lda);
00477 i__1 = *n - *l;
00478 for (j = *n - *l - *k + 1; j <= i__1; ++j) {
00479 i__2 = *k;
00480 for (i__ = j - *n + *l + *k + 1; i__ <= i__2; ++i__) {
00481 i__3 = i__ + j * a_dim1;
00482 a[i__3].r = 0.f, a[i__3].i = 0.f;
00483
00484 }
00485
00486 }
00487
00488 }
00489
00490 if (*m > *k) {
00491
00492
00493
00494 i__1 = *m - *k;
00495 cgeqr2_(&i__1, l, &a[*k + 1 + (*n - *l + 1) * a_dim1], lda, &tau[1], &
00496 work[1], info);
00497
00498 if (wantu) {
00499
00500
00501
00502 i__1 = *m - *k;
00503
00504 i__3 = *m - *k;
00505 i__2 = min(i__3,*l);
00506 cunm2r_("Right", "No transpose", m, &i__1, &i__2, &a[*k + 1 + (*n
00507 - *l + 1) * a_dim1], lda, &tau[1], &u[(*k + 1) * u_dim1 +
00508 1], ldu, &work[1], info);
00509 }
00510
00511
00512
00513 i__1 = *n;
00514 for (j = *n - *l + 1; j <= i__1; ++j) {
00515 i__2 = *m;
00516 for (i__ = j - *n + *k + *l + 1; i__ <= i__2; ++i__) {
00517 i__3 = i__ + j * a_dim1;
00518 a[i__3].r = 0.f, a[i__3].i = 0.f;
00519
00520 }
00521
00522 }
00523
00524 }
00525
00526 return 0;
00527
00528
00529
00530 }