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 integer c__1 = 1;
00020 static integer c_n1 = -1;
00021 static integer c__0 = 0;
00022
00023 int zgels_(char *trans, integer *m, integer *n, integer *
00024 nrhs, doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb,
00025 doublecomplex *work, integer *lwork, integer *info)
00026 {
00027
00028 integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3;
00029 doublereal d__1;
00030
00031
00032 integer i__, j, nb, mn;
00033 doublereal anrm, bnrm;
00034 integer brow;
00035 logical tpsd;
00036 integer iascl, ibscl;
00037 extern logical lsame_(char *, char *);
00038 integer wsize;
00039 doublereal rwork[1];
00040 extern int dlabad_(doublereal *, doublereal *);
00041 extern doublereal dlamch_(char *);
00042 extern int xerbla_(char *, integer *);
00043 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00044 integer *, integer *);
00045 integer scllen;
00046 doublereal bignum;
00047 extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
00048 integer *, doublereal *);
00049 extern int zgelqf_(integer *, integer *, doublecomplex *,
00050 integer *, doublecomplex *, doublecomplex *, integer *, integer *
00051 ), zlascl_(char *, integer *, integer *, doublereal *, doublereal
00052 *, integer *, integer *, doublecomplex *, integer *, integer *), zgeqrf_(integer *, integer *, doublecomplex *, integer *,
00053 doublecomplex *, doublecomplex *, integer *, integer *), zlaset_(
00054 char *, integer *, integer *, doublecomplex *, doublecomplex *,
00055 doublecomplex *, integer *);
00056 doublereal smlnum;
00057 logical lquery;
00058 extern int zunmlq_(char *, char *, integer *, integer *,
00059 integer *, doublecomplex *, integer *, doublecomplex *,
00060 doublecomplex *, integer *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *,
00061 integer *, doublecomplex *, integer *, doublecomplex *,
00062 doublecomplex *, integer *, doublecomplex *, integer *, integer *), ztrtrs_(char *, char *, char *, integer *,
00063 integer *, doublecomplex *, integer *, doublecomplex *, integer *,
00064 integer *);
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 a_dim1 = *lda;
00196 a_offset = 1 + a_dim1;
00197 a -= a_offset;
00198 b_dim1 = *ldb;
00199 b_offset = 1 + b_dim1;
00200 b -= b_offset;
00201 --work;
00202
00203
00204 *info = 0;
00205 mn = min(*m,*n);
00206 lquery = *lwork == -1;
00207 if (! (lsame_(trans, "N") || lsame_(trans, "C"))) {
00208 *info = -1;
00209 } else if (*m < 0) {
00210 *info = -2;
00211 } else if (*n < 0) {
00212 *info = -3;
00213 } else if (*nrhs < 0) {
00214 *info = -4;
00215 } else if (*lda < max(1,*m)) {
00216 *info = -6;
00217 } else {
00218
00219 i__1 = max(1,*m);
00220 if (*ldb < max(i__1,*n)) {
00221 *info = -8;
00222 } else {
00223
00224 i__1 = 1, i__2 = mn + max(mn,*nrhs);
00225 if (*lwork < max(i__1,i__2) && ! lquery) {
00226 *info = -10;
00227 }
00228 }
00229 }
00230
00231
00232
00233 if (*info == 0 || *info == -10) {
00234
00235 tpsd = TRUE_;
00236 if (lsame_(trans, "N")) {
00237 tpsd = FALSE_;
00238 }
00239
00240 if (*m >= *n) {
00241 nb = ilaenv_(&c__1, "ZGEQRF", " ", m, n, &c_n1, &c_n1);
00242 if (tpsd) {
00243
00244 i__1 = nb, i__2 = ilaenv_(&c__1, "ZUNMQR", "LN", m, nrhs, n, &
00245 c_n1);
00246 nb = max(i__1,i__2);
00247 } else {
00248
00249 i__1 = nb, i__2 = ilaenv_(&c__1, "ZUNMQR", "LC", m, nrhs, n, &
00250 c_n1);
00251 nb = max(i__1,i__2);
00252 }
00253 } else {
00254 nb = ilaenv_(&c__1, "ZGELQF", " ", m, n, &c_n1, &c_n1);
00255 if (tpsd) {
00256
00257 i__1 = nb, i__2 = ilaenv_(&c__1, "ZUNMLQ", "LC", n, nrhs, m, &
00258 c_n1);
00259 nb = max(i__1,i__2);
00260 } else {
00261
00262 i__1 = nb, i__2 = ilaenv_(&c__1, "ZUNMLQ", "LN", n, nrhs, m, &
00263 c_n1);
00264 nb = max(i__1,i__2);
00265 }
00266 }
00267
00268
00269 i__1 = 1, i__2 = mn + max(mn,*nrhs) * nb;
00270 wsize = max(i__1,i__2);
00271 d__1 = (doublereal) wsize;
00272 work[1].r = d__1, work[1].i = 0.;
00273
00274 }
00275
00276 if (*info != 0) {
00277 i__1 = -(*info);
00278 xerbla_("ZGELS ", &i__1);
00279 return 0;
00280 } else if (lquery) {
00281 return 0;
00282 }
00283
00284
00285
00286
00287 i__1 = min(*m,*n);
00288 if (min(i__1,*nrhs) == 0) {
00289 i__1 = max(*m,*n);
00290 zlaset_("Full", &i__1, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
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);
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 goto L50;
00325 }
00326
00327 brow = *m;
00328 if (tpsd) {
00329 brow = *n;
00330 }
00331 bnrm = zlange_("M", &brow, nrhs, &b[b_offset], ldb, rwork);
00332 ibscl = 0;
00333 if (bnrm > 0. && bnrm < smlnum) {
00334
00335
00336
00337 zlascl_("G", &c__0, &c__0, &bnrm, &smlnum, &brow, nrhs, &b[b_offset],
00338 ldb, info);
00339 ibscl = 1;
00340 } else if (bnrm > bignum) {
00341
00342
00343
00344 zlascl_("G", &c__0, &c__0, &bnrm, &bignum, &brow, nrhs, &b[b_offset],
00345 ldb, info);
00346 ibscl = 2;
00347 }
00348
00349 if (*m >= *n) {
00350
00351
00352
00353 i__1 = *lwork - mn;
00354 zgeqrf_(m, n, &a[a_offset], lda, &work[1], &work[mn + 1], &i__1, info)
00355 ;
00356
00357
00358
00359 if (! tpsd) {
00360
00361
00362
00363
00364
00365 i__1 = *lwork - mn;
00366 zunmqr_("Left", "Conjugate transpose", m, nrhs, n, &a[a_offset],
00367 lda, &work[1], &b[b_offset], ldb, &work[mn + 1], &i__1,
00368 info);
00369
00370
00371
00372
00373
00374 ztrtrs_("Upper", "No transpose", "Non-unit", n, nrhs, &a[a_offset]
00375 , lda, &b[b_offset], ldb, info);
00376
00377 if (*info > 0) {
00378 return 0;
00379 }
00380
00381 scllen = *n;
00382
00383 } else {
00384
00385
00386
00387
00388
00389 ztrtrs_("Upper", "Conjugate transpose", "Non-unit", n, nrhs, &a[
00390 a_offset], lda, &b[b_offset], ldb, info);
00391
00392 if (*info > 0) {
00393 return 0;
00394 }
00395
00396
00397
00398 i__1 = *nrhs;
00399 for (j = 1; j <= i__1; ++j) {
00400 i__2 = *m;
00401 for (i__ = *n + 1; i__ <= i__2; ++i__) {
00402 i__3 = i__ + j * b_dim1;
00403 b[i__3].r = 0., b[i__3].i = 0.;
00404
00405 }
00406
00407 }
00408
00409
00410
00411 i__1 = *lwork - mn;
00412 zunmqr_("Left", "No transpose", m, nrhs, n, &a[a_offset], lda, &
00413 work[1], &b[b_offset], ldb, &work[mn + 1], &i__1, info);
00414
00415
00416
00417 scllen = *m;
00418
00419 }
00420
00421 } else {
00422
00423
00424
00425 i__1 = *lwork - mn;
00426 zgelqf_(m, n, &a[a_offset], lda, &work[1], &work[mn + 1], &i__1, info)
00427 ;
00428
00429
00430
00431 if (! tpsd) {
00432
00433
00434
00435
00436
00437 ztrtrs_("Lower", "No transpose", "Non-unit", m, nrhs, &a[a_offset]
00438 , lda, &b[b_offset], ldb, info);
00439
00440 if (*info > 0) {
00441 return 0;
00442 }
00443
00444
00445
00446 i__1 = *nrhs;
00447 for (j = 1; j <= i__1; ++j) {
00448 i__2 = *n;
00449 for (i__ = *m + 1; i__ <= i__2; ++i__) {
00450 i__3 = i__ + j * b_dim1;
00451 b[i__3].r = 0., b[i__3].i = 0.;
00452
00453 }
00454
00455 }
00456
00457
00458
00459 i__1 = *lwork - mn;
00460 zunmlq_("Left", "Conjugate transpose", n, nrhs, m, &a[a_offset],
00461 lda, &work[1], &b[b_offset], ldb, &work[mn + 1], &i__1,
00462 info);
00463
00464
00465
00466 scllen = *n;
00467
00468 } else {
00469
00470
00471
00472
00473
00474 i__1 = *lwork - mn;
00475 zunmlq_("Left", "No transpose", n, nrhs, m, &a[a_offset], lda, &
00476 work[1], &b[b_offset], ldb, &work[mn + 1], &i__1, info);
00477
00478
00479
00480
00481
00482 ztrtrs_("Lower", "Conjugate transpose", "Non-unit", m, nrhs, &a[
00483 a_offset], lda, &b[b_offset], ldb, info);
00484
00485 if (*info > 0) {
00486 return 0;
00487 }
00488
00489 scllen = *m;
00490
00491 }
00492
00493 }
00494
00495
00496
00497 if (iascl == 1) {
00498 zlascl_("G", &c__0, &c__0, &anrm, &smlnum, &scllen, nrhs, &b[b_offset]
00499 , ldb, info);
00500 } else if (iascl == 2) {
00501 zlascl_("G", &c__0, &c__0, &anrm, &bignum, &scllen, nrhs, &b[b_offset]
00502 , ldb, info);
00503 }
00504 if (ibscl == 1) {
00505 zlascl_("G", &c__0, &c__0, &smlnum, &bnrm, &scllen, nrhs, &b[b_offset]
00506 , ldb, info);
00507 } else if (ibscl == 2) {
00508 zlascl_("G", &c__0, &c__0, &bignum, &bnrm, &scllen, nrhs, &b[b_offset]
00509 , ldb, info);
00510 }
00511
00512 L50:
00513 d__1 = (doublereal) wsize;
00514 work[1].r = d__1, work[1].i = 0.;
00515
00516 return 0;
00517
00518
00519
00520 }