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_b31 = -1.f;
00021 static real c_b33 = 1.f;
00022
00023 int sgglse_(integer *m, integer *n, integer *p, real *a,
00024 integer *lda, real *b, integer *ldb, real *c__, real *d__, real *x,
00025 real *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 nb, mn, nr, nb1, nb2, nb3, nb4, lopt;
00032 extern int sgemv_(char *, integer *, integer *, real *,
00033 real *, integer *, real *, integer *, real *, real *, integer *), scopy_(integer *, real *, integer *, real *, integer *),
00034 saxpy_(integer *, real *, real *, integer *, real *, integer *),
00035 strmv_(char *, char *, char *, integer *, real *, integer *, real
00036 *, integer *), xerbla_(char *, integer *);
00037 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00038 integer *, integer *);
00039 extern int sggrqf_(integer *, integer *, integer *, real
00040 *, integer *, real *, real *, integer *, real *, real *, integer *
00041 , integer *);
00042 integer lwkmin, lwkopt;
00043 logical lquery;
00044 extern int sormqr_(char *, char *, integer *, integer *,
00045 integer *, real *, integer *, real *, real *, integer *, real *,
00046 integer *, integer *), sormrq_(char *, char *,
00047 integer *, integer *, integer *, real *, integer *, real *, real *
00048 , integer *, real *, integer *, integer *),
00049 strtrs_(char *, char *, char *, integer *, integer *, real *,
00050 integer *, real *, integer *, integer *);
00051
00052
00053
00054
00055
00056
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 a_dim1 = *lda;
00172 a_offset = 1 + a_dim1;
00173 a -= a_offset;
00174 b_dim1 = *ldb;
00175 b_offset = 1 + b_dim1;
00176 b -= b_offset;
00177 --c__;
00178 --d__;
00179 --x;
00180 --work;
00181
00182
00183 *info = 0;
00184 mn = min(*m,*n);
00185 lquery = *lwork == -1;
00186 if (*m < 0) {
00187 *info = -1;
00188 } else if (*n < 0) {
00189 *info = -2;
00190 } else if (*p < 0 || *p > *n || *p < *n - *m) {
00191 *info = -3;
00192 } else if (*lda < max(1,*m)) {
00193 *info = -5;
00194 } else if (*ldb < max(1,*p)) {
00195 *info = -7;
00196 }
00197
00198
00199
00200 if (*info == 0) {
00201 if (*n == 0) {
00202 lwkmin = 1;
00203 lwkopt = 1;
00204 } else {
00205 nb1 = ilaenv_(&c__1, "SGEQRF", " ", m, n, &c_n1, &c_n1);
00206 nb2 = ilaenv_(&c__1, "SGERQF", " ", m, n, &c_n1, &c_n1);
00207 nb3 = ilaenv_(&c__1, "SORMQR", " ", m, n, p, &c_n1);
00208 nb4 = ilaenv_(&c__1, "SORMRQ", " ", m, n, p, &c_n1);
00209
00210 i__1 = max(nb1,nb2), i__1 = max(i__1,nb3);
00211 nb = max(i__1,nb4);
00212 lwkmin = *m + *n + *p;
00213 lwkopt = *p + mn + max(*m,*n) * nb;
00214 }
00215 work[1] = (real) lwkopt;
00216
00217 if (*lwork < lwkmin && ! lquery) {
00218 *info = -12;
00219 }
00220 }
00221
00222 if (*info != 0) {
00223 i__1 = -(*info);
00224 xerbla_("SGGLSE", &i__1);
00225 return 0;
00226 } else if (lquery) {
00227 return 0;
00228 }
00229
00230
00231
00232 if (*n == 0) {
00233 return 0;
00234 }
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 i__1 = *lwork - *p - mn;
00246 sggrqf_(p, m, n, &b[b_offset], ldb, &work[1], &a[a_offset], lda, &work[*p
00247 + 1], &work[*p + mn + 1], &i__1, info);
00248 lopt = work[*p + mn + 1];
00249
00250
00251
00252
00253 i__1 = max(1,*m);
00254 i__2 = *lwork - *p - mn;
00255 sormqr_("Left", "Transpose", m, &c__1, &mn, &a[a_offset], lda, &work[*p +
00256 1], &c__[1], &i__1, &work[*p + mn + 1], &i__2, info);
00257
00258 i__1 = lopt, i__2 = (integer) work[*p + mn + 1];
00259 lopt = max(i__1,i__2);
00260
00261
00262
00263 if (*p > 0) {
00264 strtrs_("Upper", "No transpose", "Non-unit", p, &c__1, &b[(*n - *p +
00265 1) * b_dim1 + 1], ldb, &d__[1], p, info);
00266
00267 if (*info > 0) {
00268 *info = 1;
00269 return 0;
00270 }
00271
00272
00273
00274 scopy_(p, &d__[1], &c__1, &x[*n - *p + 1], &c__1);
00275
00276
00277
00278 i__1 = *n - *p;
00279 sgemv_("No transpose", &i__1, p, &c_b31, &a[(*n - *p + 1) * a_dim1 +
00280 1], lda, &d__[1], &c__1, &c_b33, &c__[1], &c__1);
00281 }
00282
00283
00284
00285 if (*n > *p) {
00286 i__1 = *n - *p;
00287 i__2 = *n - *p;
00288 strtrs_("Upper", "No transpose", "Non-unit", &i__1, &c__1, &a[
00289 a_offset], lda, &c__[1], &i__2, info);
00290
00291 if (*info > 0) {
00292 *info = 2;
00293 return 0;
00294 }
00295
00296
00297
00298 i__1 = *n - *p;
00299 scopy_(&i__1, &c__[1], &c__1, &x[1], &c__1);
00300 }
00301
00302
00303
00304 if (*m < *n) {
00305 nr = *m + *p - *n;
00306 if (nr > 0) {
00307 i__1 = *n - *m;
00308 sgemv_("No transpose", &nr, &i__1, &c_b31, &a[*n - *p + 1 + (*m +
00309 1) * a_dim1], lda, &d__[nr + 1], &c__1, &c_b33, &c__[*n -
00310 *p + 1], &c__1);
00311 }
00312 } else {
00313 nr = *p;
00314 }
00315 if (nr > 0) {
00316 strmv_("Upper", "No transpose", "Non unit", &nr, &a[*n - *p + 1 + (*n
00317 - *p + 1) * a_dim1], lda, &d__[1], &c__1);
00318 saxpy_(&nr, &c_b31, &d__[1], &c__1, &c__[*n - *p + 1], &c__1);
00319 }
00320
00321
00322
00323 i__1 = *lwork - *p - mn;
00324 sormrq_("Left", "Transpose", n, &c__1, p, &b[b_offset], ldb, &work[1], &x[
00325 1], n, &work[*p + mn + 1], &i__1, info);
00326
00327 i__1 = lopt, i__2 = (integer) work[*p + mn + 1];
00328 work[1] = (real) (*p + mn + max(i__1,i__2));
00329
00330 return 0;
00331
00332
00333
00334 }