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