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 integer c__0 = 0;
00023 static integer c__2 = 2;
00024
00025 int zgelsy_(integer *m, integer *n, integer *nrhs,
00026 doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb,
00027 integer *jpvt, doublereal *rcond, integer *rank, doublecomplex *work,
00028 integer *lwork, doublereal *rwork, integer *info)
00029 {
00030
00031 integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3, i__4;
00032 doublereal d__1, d__2;
00033 doublecomplex z__1;
00034
00035
00036 double z_abs(doublecomplex *);
00037
00038
00039 integer i__, j;
00040 doublecomplex c1, c2, s1, s2;
00041 integer nb, mn, nb1, nb2, nb3, nb4;
00042 doublereal anrm, bnrm, smin, smax;
00043 integer iascl, ibscl, ismin, ismax;
00044 doublereal wsize;
00045 extern int zcopy_(integer *, doublecomplex *, integer *,
00046 doublecomplex *, integer *), ztrsm_(char *, char *, char *, char *
00047 , integer *, integer *, doublecomplex *, doublecomplex *, integer
00048 *, doublecomplex *, integer *),
00049 zlaic1_(integer *, integer *, doublecomplex *, doublereal *,
00050 doublecomplex *, doublecomplex *, doublereal *, doublecomplex *,
00051 doublecomplex *), dlabad_(doublereal *, doublereal *), zgeqp3_(
00052 integer *, integer *, doublecomplex *, integer *, integer *,
00053 doublecomplex *, doublecomplex *, integer *, doublereal *,
00054 integer *);
00055 extern doublereal dlamch_(char *);
00056 extern int xerbla_(char *, integer *);
00057 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00058 integer *, integer *);
00059 extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
00060 integer *, doublereal *);
00061 doublereal bignum;
00062 extern int zlascl_(char *, integer *, integer *,
00063 doublereal *, doublereal *, integer *, integer *, doublecomplex *,
00064 integer *, integer *), zlaset_(char *, integer *,
00065 integer *, doublecomplex *, doublecomplex *, doublecomplex *,
00066 integer *);
00067 doublereal sminpr, smaxpr, smlnum;
00068 integer lwkopt;
00069 logical lquery;
00070 extern int zunmqr_(char *, char *, integer *, integer *,
00071 integer *, doublecomplex *, integer *, doublecomplex *,
00072 doublecomplex *, integer *, doublecomplex *, integer *, integer *), zunmrz_(char *, char *, integer *, integer *,
00073 integer *, integer *, doublecomplex *, integer *, doublecomplex *,
00074 doublecomplex *, integer *, doublecomplex *, integer *, integer *
00075 ), ztzrzf_(integer *, integer *, doublecomplex *,
00076 integer *, doublecomplex *, doublecomplex *, integer *, integer *)
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 a_dim1 = *lda;
00223 a_offset = 1 + a_dim1;
00224 a -= a_offset;
00225 b_dim1 = *ldb;
00226 b_offset = 1 + b_dim1;
00227 b -= b_offset;
00228 --jpvt;
00229 --work;
00230 --rwork;
00231
00232
00233 mn = min(*m,*n);
00234 ismin = mn + 1;
00235 ismax = (mn << 1) + 1;
00236
00237
00238
00239 *info = 0;
00240 nb1 = ilaenv_(&c__1, "ZGEQRF", " ", m, n, &c_n1, &c_n1);
00241 nb2 = ilaenv_(&c__1, "ZGERQF", " ", m, n, &c_n1, &c_n1);
00242 nb3 = ilaenv_(&c__1, "ZUNMQR", " ", m, n, nrhs, &c_n1);
00243 nb4 = ilaenv_(&c__1, "ZUNMRQ", " ", m, n, nrhs, &c_n1);
00244
00245 i__1 = max(nb1,nb2), i__1 = max(i__1,nb3);
00246 nb = max(i__1,nb4);
00247
00248 i__1 = 1, i__2 = mn + (*n << 1) + nb * (*n + 1), i__1 = max(i__1,i__2),
00249 i__2 = (mn << 1) + nb * *nrhs;
00250 lwkopt = max(i__1,i__2);
00251 z__1.r = (doublereal) lwkopt, z__1.i = 0.;
00252 work[1].r = z__1.r, work[1].i = z__1.i;
00253 lquery = *lwork == -1;
00254 if (*m < 0) {
00255 *info = -1;
00256 } else if (*n < 0) {
00257 *info = -2;
00258 } else if (*nrhs < 0) {
00259 *info = -3;
00260 } else if (*lda < max(1,*m)) {
00261 *info = -5;
00262 } else {
00263
00264 i__1 = max(1,*m);
00265 if (*ldb < max(i__1,*n)) {
00266 *info = -7;
00267 } else {
00268
00269 i__1 = mn << 1, i__2 = *n + 1, i__1 = max(i__1,i__2), i__2 = mn +
00270 *nrhs;
00271 if (*lwork < mn + max(i__1,i__2) && ! lquery) {
00272 *info = -12;
00273 }
00274 }
00275 }
00276
00277 if (*info != 0) {
00278 i__1 = -(*info);
00279 xerbla_("ZGELSY", &i__1);
00280 return 0;
00281 } else if (lquery) {
00282 return 0;
00283 }
00284
00285
00286
00287
00288 i__1 = min(*m,*n);
00289 if (min(i__1,*nrhs) == 0) {
00290 *rank = 0;
00291 return 0;
00292 }
00293
00294
00295
00296 smlnum = dlamch_("S") / dlamch_("P");
00297 bignum = 1. / smlnum;
00298 dlabad_(&smlnum, &bignum);
00299
00300
00301
00302 anrm = zlange_("M", m, n, &a[a_offset], lda, &rwork[1]);
00303 iascl = 0;
00304 if (anrm > 0. && anrm < smlnum) {
00305
00306
00307
00308 zlascl_("G", &c__0, &c__0, &anrm, &smlnum, m, n, &a[a_offset], lda,
00309 info);
00310 iascl = 1;
00311 } else if (anrm > bignum) {
00312
00313
00314
00315 zlascl_("G", &c__0, &c__0, &anrm, &bignum, m, n, &a[a_offset], lda,
00316 info);
00317 iascl = 2;
00318 } else if (anrm == 0.) {
00319
00320
00321
00322 i__1 = max(*m,*n);
00323 zlaset_("F", &i__1, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
00324 *rank = 0;
00325 goto L70;
00326 }
00327
00328 bnrm = zlange_("M", m, nrhs, &b[b_offset], ldb, &rwork[1]);
00329 ibscl = 0;
00330 if (bnrm > 0. && bnrm < smlnum) {
00331
00332
00333
00334 zlascl_("G", &c__0, &c__0, &bnrm, &smlnum, m, nrhs, &b[b_offset], ldb,
00335 info);
00336 ibscl = 1;
00337 } else if (bnrm > bignum) {
00338
00339
00340
00341 zlascl_("G", &c__0, &c__0, &bnrm, &bignum, m, nrhs, &b[b_offset], ldb,
00342 info);
00343 ibscl = 2;
00344 }
00345
00346
00347
00348
00349 i__1 = *lwork - mn;
00350 zgeqp3_(m, n, &a[a_offset], lda, &jpvt[1], &work[1], &work[mn + 1], &i__1,
00351 &rwork[1], info);
00352 i__1 = mn + 1;
00353 wsize = mn + work[i__1].r;
00354
00355
00356
00357
00358
00359
00360 i__1 = ismin;
00361 work[i__1].r = 1., work[i__1].i = 0.;
00362 i__1 = ismax;
00363 work[i__1].r = 1., work[i__1].i = 0.;
00364 smax = z_abs(&a[a_dim1 + 1]);
00365 smin = smax;
00366 if (z_abs(&a[a_dim1 + 1]) == 0.) {
00367 *rank = 0;
00368 i__1 = max(*m,*n);
00369 zlaset_("F", &i__1, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
00370 goto L70;
00371 } else {
00372 *rank = 1;
00373 }
00374
00375 L10:
00376 if (*rank < mn) {
00377 i__ = *rank + 1;
00378 zlaic1_(&c__2, rank, &work[ismin], &smin, &a[i__ * a_dim1 + 1], &a[
00379 i__ + i__ * a_dim1], &sminpr, &s1, &c1);
00380 zlaic1_(&c__1, rank, &work[ismax], &smax, &a[i__ * a_dim1 + 1], &a[
00381 i__ + i__ * a_dim1], &smaxpr, &s2, &c2);
00382
00383 if (smaxpr * *rcond <= sminpr) {
00384 i__1 = *rank;
00385 for (i__ = 1; i__ <= i__1; ++i__) {
00386 i__2 = ismin + i__ - 1;
00387 i__3 = ismin + i__ - 1;
00388 z__1.r = s1.r * work[i__3].r - s1.i * work[i__3].i, z__1.i =
00389 s1.r * work[i__3].i + s1.i * work[i__3].r;
00390 work[i__2].r = z__1.r, work[i__2].i = z__1.i;
00391 i__2 = ismax + i__ - 1;
00392 i__3 = ismax + i__ - 1;
00393 z__1.r = s2.r * work[i__3].r - s2.i * work[i__3].i, z__1.i =
00394 s2.r * work[i__3].i + s2.i * work[i__3].r;
00395 work[i__2].r = z__1.r, work[i__2].i = z__1.i;
00396
00397 }
00398 i__1 = ismin + *rank;
00399 work[i__1].r = c1.r, work[i__1].i = c1.i;
00400 i__1 = ismax + *rank;
00401 work[i__1].r = c2.r, work[i__1].i = c2.i;
00402 smin = sminpr;
00403 smax = smaxpr;
00404 ++(*rank);
00405 goto L10;
00406 }
00407 }
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417 if (*rank < *n) {
00418 i__1 = *lwork - (mn << 1);
00419 ztzrzf_(rank, n, &a[a_offset], lda, &work[mn + 1], &work[(mn << 1) +
00420 1], &i__1, info);
00421 }
00422
00423
00424
00425
00426
00427
00428 i__1 = *lwork - (mn << 1);
00429 zunmqr_("Left", "Conjugate transpose", m, nrhs, &mn, &a[a_offset], lda, &
00430 work[1], &b[b_offset], ldb, &work[(mn << 1) + 1], &i__1, info);
00431
00432 i__1 = (mn << 1) + 1;
00433 d__1 = wsize, d__2 = (mn << 1) + work[i__1].r;
00434 wsize = max(d__1,d__2);
00435
00436
00437
00438
00439
00440 ztrsm_("Left", "Upper", "No transpose", "Non-unit", rank, nrhs, &c_b2, &a[
00441 a_offset], lda, &b[b_offset], ldb);
00442
00443 i__1 = *nrhs;
00444 for (j = 1; j <= i__1; ++j) {
00445 i__2 = *n;
00446 for (i__ = *rank + 1; i__ <= i__2; ++i__) {
00447 i__3 = i__ + j * b_dim1;
00448 b[i__3].r = 0., b[i__3].i = 0.;
00449
00450 }
00451
00452 }
00453
00454
00455
00456 if (*rank < *n) {
00457 i__1 = *n - *rank;
00458 i__2 = *lwork - (mn << 1);
00459 zunmrz_("Left", "Conjugate transpose", n, nrhs, rank, &i__1, &a[
00460 a_offset], lda, &work[mn + 1], &b[b_offset], ldb, &work[(mn <<
00461 1) + 1], &i__2, info);
00462 }
00463
00464
00465
00466
00467
00468 i__1 = *nrhs;
00469 for (j = 1; j <= i__1; ++j) {
00470 i__2 = *n;
00471 for (i__ = 1; i__ <= i__2; ++i__) {
00472 i__3 = jpvt[i__];
00473 i__4 = i__ + j * b_dim1;
00474 work[i__3].r = b[i__4].r, work[i__3].i = b[i__4].i;
00475
00476 }
00477 zcopy_(n, &work[1], &c__1, &b[j * b_dim1 + 1], &c__1);
00478
00479 }
00480
00481
00482
00483
00484
00485 if (iascl == 1) {
00486 zlascl_("G", &c__0, &c__0, &anrm, &smlnum, n, nrhs, &b[b_offset], ldb,
00487 info);
00488 zlascl_("U", &c__0, &c__0, &smlnum, &anrm, rank, rank, &a[a_offset],
00489 lda, info);
00490 } else if (iascl == 2) {
00491 zlascl_("G", &c__0, &c__0, &anrm, &bignum, n, nrhs, &b[b_offset], ldb,
00492 info);
00493 zlascl_("U", &c__0, &c__0, &bignum, &anrm, rank, rank, &a[a_offset],
00494 lda, info);
00495 }
00496 if (ibscl == 1) {
00497 zlascl_("G", &c__0, &c__0, &smlnum, &bnrm, n, nrhs, &b[b_offset], ldb,
00498 info);
00499 } else if (ibscl == 2) {
00500 zlascl_("G", &c__0, &c__0, &bignum, &bnrm, n, nrhs, &b[b_offset], ldb,
00501 info);
00502 }
00503
00504 L70:
00505 z__1.r = (doublereal) lwkopt, z__1.i = 0.;
00506 work[1].r = z__1.r, work[1].i = z__1.i;
00507
00508 return 0;
00509
00510
00511
00512 }