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