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