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__0 = 0;
00019 static real c_b13 = 0.f;
00020 static integer c__2 = 2;
00021 static integer c__1 = 1;
00022 static real c_b36 = 1.f;
00023
00024 int sgelsx_(integer *m, integer *n, integer *nrhs, real *a,
00025 integer *lda, real *b, integer *ldb, integer *jpvt, real *rcond,
00026 integer *rank, real *work, integer *info)
00027 {
00028
00029 integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2;
00030 real r__1;
00031
00032
00033 integer i__, j, k;
00034 real c1, c2, s1, s2, t1, t2;
00035 integer mn;
00036 real anrm, bnrm, smin, smax;
00037 integer iascl, ibscl, ismin, ismax;
00038 extern int strsm_(char *, char *, char *, char *,
00039 integer *, integer *, real *, real *, integer *, real *, integer *
00040 ), slaic1_(integer *, integer *,
00041 real *, real *, real *, real *, real *, real *, real *), sorm2r_(
00042 char *, char *, integer *, integer *, integer *, real *, integer *
00043 , real *, real *, integer *, real *, integer *),
00044 slabad_(real *, real *);
00045 extern doublereal slamch_(char *), slange_(char *, integer *,
00046 integer *, real *, integer *, real *);
00047 extern int xerbla_(char *, integer *);
00048 real bignum;
00049 extern int slascl_(char *, integer *, integer *, real *,
00050 real *, integer *, integer *, real *, integer *, integer *), sgeqpf_(integer *, integer *, real *, integer *, integer
00051 *, real *, real *, integer *), slaset_(char *, integer *, integer
00052 *, real *, real *, real *, integer *);
00053 real sminpr, smaxpr, smlnum;
00054 extern int slatzm_(char *, integer *, integer *, real *,
00055 integer *, real *, real *, real *, integer *, real *),
00056 stzrqf_(integer *, integer *, real *, integer *, real *, integer *
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 a_dim1 = *lda;
00177 a_offset = 1 + a_dim1;
00178 a -= a_offset;
00179 b_dim1 = *ldb;
00180 b_offset = 1 + b_dim1;
00181 b -= b_offset;
00182 --jpvt;
00183 --work;
00184
00185
00186 mn = min(*m,*n);
00187 ismin = mn + 1;
00188 ismax = (mn << 1) + 1;
00189
00190
00191
00192 *info = 0;
00193 if (*m < 0) {
00194 *info = -1;
00195 } else if (*n < 0) {
00196 *info = -2;
00197 } else if (*nrhs < 0) {
00198 *info = -3;
00199 } else if (*lda < max(1,*m)) {
00200 *info = -5;
00201 } else {
00202
00203 i__1 = max(1,*m);
00204 if (*ldb < max(i__1,*n)) {
00205 *info = -7;
00206 }
00207 }
00208
00209 if (*info != 0) {
00210 i__1 = -(*info);
00211 xerbla_("SGELSX", &i__1);
00212 return 0;
00213 }
00214
00215
00216
00217
00218 i__1 = min(*m,*n);
00219 if (min(i__1,*nrhs) == 0) {
00220 *rank = 0;
00221 return 0;
00222 }
00223
00224
00225
00226 smlnum = slamch_("S") / slamch_("P");
00227 bignum = 1.f / smlnum;
00228 slabad_(&smlnum, &bignum);
00229
00230
00231
00232 anrm = slange_("M", m, n, &a[a_offset], lda, &work[1]);
00233 iascl = 0;
00234 if (anrm > 0.f && anrm < smlnum) {
00235
00236
00237
00238 slascl_("G", &c__0, &c__0, &anrm, &smlnum, m, n, &a[a_offset], lda,
00239 info);
00240 iascl = 1;
00241 } else if (anrm > bignum) {
00242
00243
00244
00245 slascl_("G", &c__0, &c__0, &anrm, &bignum, m, n, &a[a_offset], lda,
00246 info);
00247 iascl = 2;
00248 } else if (anrm == 0.f) {
00249
00250
00251
00252 i__1 = max(*m,*n);
00253 slaset_("F", &i__1, nrhs, &c_b13, &c_b13, &b[b_offset], ldb);
00254 *rank = 0;
00255 goto L100;
00256 }
00257
00258 bnrm = slange_("M", m, nrhs, &b[b_offset], ldb, &work[1]);
00259 ibscl = 0;
00260 if (bnrm > 0.f && bnrm < smlnum) {
00261
00262
00263
00264 slascl_("G", &c__0, &c__0, &bnrm, &smlnum, m, nrhs, &b[b_offset], ldb,
00265 info);
00266 ibscl = 1;
00267 } else if (bnrm > bignum) {
00268
00269
00270
00271 slascl_("G", &c__0, &c__0, &bnrm, &bignum, m, nrhs, &b[b_offset], ldb,
00272 info);
00273 ibscl = 2;
00274 }
00275
00276
00277
00278
00279 sgeqpf_(m, n, &a[a_offset], lda, &jpvt[1], &work[1], &work[mn + 1], info);
00280
00281
00282
00283
00284
00285
00286 work[ismin] = 1.f;
00287 work[ismax] = 1.f;
00288 smax = (r__1 = a[a_dim1 + 1], dabs(r__1));
00289 smin = smax;
00290 if ((r__1 = a[a_dim1 + 1], dabs(r__1)) == 0.f) {
00291 *rank = 0;
00292 i__1 = max(*m,*n);
00293 slaset_("F", &i__1, nrhs, &c_b13, &c_b13, &b[b_offset], ldb);
00294 goto L100;
00295 } else {
00296 *rank = 1;
00297 }
00298
00299 L10:
00300 if (*rank < mn) {
00301 i__ = *rank + 1;
00302 slaic1_(&c__2, rank, &work[ismin], &smin, &a[i__ * a_dim1 + 1], &a[
00303 i__ + i__ * a_dim1], &sminpr, &s1, &c1);
00304 slaic1_(&c__1, rank, &work[ismax], &smax, &a[i__ * a_dim1 + 1], &a[
00305 i__ + i__ * a_dim1], &smaxpr, &s2, &c2);
00306
00307 if (smaxpr * *rcond <= sminpr) {
00308 i__1 = *rank;
00309 for (i__ = 1; i__ <= i__1; ++i__) {
00310 work[ismin + i__ - 1] = s1 * work[ismin + i__ - 1];
00311 work[ismax + i__ - 1] = s2 * work[ismax + i__ - 1];
00312
00313 }
00314 work[ismin + *rank] = c1;
00315 work[ismax + *rank] = c2;
00316 smin = sminpr;
00317 smax = smaxpr;
00318 ++(*rank);
00319 goto L10;
00320 }
00321 }
00322
00323
00324
00325
00326
00327
00328
00329 if (*rank < *n) {
00330 stzrqf_(rank, n, &a[a_offset], lda, &work[mn + 1], info);
00331 }
00332
00333
00334
00335
00336
00337 sorm2r_("Left", "Transpose", m, nrhs, &mn, &a[a_offset], lda, &work[1], &
00338 b[b_offset], ldb, &work[(mn << 1) + 1], info);
00339
00340
00341
00342
00343
00344 strsm_("Left", "Upper", "No transpose", "Non-unit", rank, nrhs, &c_b36, &
00345 a[a_offset], lda, &b[b_offset], ldb);
00346
00347 i__1 = *n;
00348 for (i__ = *rank + 1; i__ <= i__1; ++i__) {
00349 i__2 = *nrhs;
00350 for (j = 1; j <= i__2; ++j) {
00351 b[i__ + j * b_dim1] = 0.f;
00352
00353 }
00354
00355 }
00356
00357
00358
00359 if (*rank < *n) {
00360 i__1 = *rank;
00361 for (i__ = 1; i__ <= i__1; ++i__) {
00362 i__2 = *n - *rank + 1;
00363 slatzm_("Left", &i__2, nrhs, &a[i__ + (*rank + 1) * a_dim1], lda,
00364 &work[mn + i__], &b[i__ + b_dim1], &b[*rank + 1 + b_dim1],
00365 ldb, &work[(mn << 1) + 1]);
00366
00367 }
00368 }
00369
00370
00371
00372
00373
00374 i__1 = *nrhs;
00375 for (j = 1; j <= i__1; ++j) {
00376 i__2 = *n;
00377 for (i__ = 1; i__ <= i__2; ++i__) {
00378 work[(mn << 1) + i__] = 1.f;
00379
00380 }
00381 i__2 = *n;
00382 for (i__ = 1; i__ <= i__2; ++i__) {
00383 if (work[(mn << 1) + i__] == 1.f) {
00384 if (jpvt[i__] != i__) {
00385 k = i__;
00386 t1 = b[k + j * b_dim1];
00387 t2 = b[jpvt[k] + j * b_dim1];
00388 L70:
00389 b[jpvt[k] + j * b_dim1] = t1;
00390 work[(mn << 1) + k] = 0.f;
00391 t1 = t2;
00392 k = jpvt[k];
00393 t2 = b[jpvt[k] + j * b_dim1];
00394 if (jpvt[k] != i__) {
00395 goto L70;
00396 }
00397 b[i__ + j * b_dim1] = t1;
00398 work[(mn << 1) + k] = 0.f;
00399 }
00400 }
00401
00402 }
00403
00404 }
00405
00406
00407
00408 if (iascl == 1) {
00409 slascl_("G", &c__0, &c__0, &anrm, &smlnum, n, nrhs, &b[b_offset], ldb,
00410 info);
00411 slascl_("U", &c__0, &c__0, &smlnum, &anrm, rank, rank, &a[a_offset],
00412 lda, info);
00413 } else if (iascl == 2) {
00414 slascl_("G", &c__0, &c__0, &anrm, &bignum, n, nrhs, &b[b_offset], ldb,
00415 info);
00416 slascl_("U", &c__0, &c__0, &bignum, &anrm, rank, rank, &a[a_offset],
00417 lda, info);
00418 }
00419 if (ibscl == 1) {
00420 slascl_("G", &c__0, &c__0, &smlnum, &bnrm, n, nrhs, &b[b_offset], ldb,
00421 info);
00422 } else if (ibscl == 2) {
00423 slascl_("G", &c__0, &c__0, &bignum, &bnrm, n, nrhs, &b[b_offset], ldb,
00424 info);
00425 }
00426
00427 L100:
00428
00429 return 0;
00430
00431
00432
00433 }