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 integer c__3 = 3;
00021 static integer c__2 = 2;
00022
00023 int sgeqrf_(integer *m, integer *n, real *a, integer *lda,
00024 real *tau, real *work, integer *lwork, integer *info)
00025 {
00026
00027 integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
00028 real r__1;
00029
00030
00031 integer i__, j, k, ib, nb, nt, nx, iws;
00032 extern doublereal sceil_(real *);
00033 integer nbmin, iinfo;
00034 extern int sgeqr2_(integer *, integer *, real *, integer
00035 *, real *, real *, integer *), slarfb_(char *, char *, char *,
00036 char *, integer *, integer *, integer *, real *, integer *, real *
00037 , integer *, real *, integer *, real *, integer *), xerbla_(char *, integer *);
00038 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00039 integer *, integer *);
00040 extern int slarft_(char *, char *, integer *, integer *,
00041 real *, integer *, real *, real *, integer *);
00042 integer lbwork, llwork, lwkopt;
00043 logical lquery;
00044
00045
00046
00047
00048
00049
00050
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 a_dim1 = *lda;
00145 a_offset = 1 + a_dim1;
00146 a -= a_offset;
00147 --tau;
00148 --work;
00149
00150
00151 *info = 0;
00152 nbmin = 2;
00153 nx = 0;
00154 iws = *n;
00155 k = min(*m,*n);
00156 nb = ilaenv_(&c__1, "SGEQRF", " ", m, n, &c_n1, &c_n1);
00157 if (nb > 1 && nb < k) {
00158
00159
00160
00161
00162 i__1 = 0, i__2 = ilaenv_(&c__3, "SGEQRF", " ", m, n, &c_n1, &c_n1);
00163 nx = max(i__1,i__2);
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 r__1 = (real) (k - nx) / (real) nb;
00177 nt = k - sceil_(&r__1) * nb;
00178
00179
00180
00181
00182
00183 i__3 = (*n - *m) * k, i__4 = (*n - *m) * nb;
00184
00185 i__5 = k * nb, i__6 = nb * nb;
00186 i__1 = max(i__3,i__4), i__2 = max(i__5,i__6);
00187 llwork = max(i__1,i__2);
00188 r__1 = (real) llwork / (real) nb;
00189 llwork = sceil_(&r__1);
00190 if (nt > nb) {
00191 lbwork = k - nt;
00192
00193
00194
00195 lwkopt = (lbwork + llwork) * nb;
00196 work[1] = (real) (lwkopt + nt * nt);
00197 } else {
00198 r__1 = (real) k / (real) nb;
00199 lbwork = sceil_(&r__1) * nb;
00200 lwkopt = (lbwork + llwork - nb) * nb;
00201 work[1] = (real) lwkopt;
00202 }
00203
00204
00205
00206 lquery = *lwork == -1;
00207 if (*m < 0) {
00208 *info = -1;
00209 } else if (*n < 0) {
00210 *info = -2;
00211 } else if (*lda < max(1,*m)) {
00212 *info = -4;
00213 } else if (*lwork < max(1,*n) && ! lquery) {
00214 *info = -7;
00215 }
00216 if (*info != 0) {
00217 i__1 = -(*info);
00218 xerbla_("SGEQRF", &i__1);
00219 return 0;
00220 } else if (lquery) {
00221 return 0;
00222 }
00223
00224
00225
00226 if (k == 0) {
00227 work[1] = 1.f;
00228 return 0;
00229 }
00230
00231 if (nb > 1 && nb < k) {
00232 if (nx < k) {
00233
00234
00235
00236 if (nt <= nb) {
00237 iws = (lbwork + llwork - nb) * nb;
00238 } else {
00239 iws = (lbwork + llwork) * nb + nt * nt;
00240 }
00241 if (*lwork < iws) {
00242
00243
00244
00245
00246 if (nt <= nb) {
00247 nb = *lwork / (llwork + (lbwork - nb));
00248 } else {
00249 nb = (*lwork - nt * nt) / (lbwork + llwork);
00250 }
00251
00252 i__1 = 2, i__2 = ilaenv_(&c__2, "SGEQRF", " ", m, n, &c_n1, &
00253 c_n1);
00254 nbmin = max(i__1,i__2);
00255 }
00256 }
00257 }
00258
00259 if (nb >= nbmin && nb < k && nx < k) {
00260
00261
00262
00263 i__1 = k - nx;
00264 i__2 = nb;
00265 for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
00266
00267 i__3 = k - i__ + 1;
00268 ib = min(i__3,nb);
00269
00270
00271
00272 i__3 = i__ - nb;
00273 i__4 = nb;
00274 for (j = 1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) {
00275
00276
00277
00278 i__5 = *m - j + 1;
00279 slarfb_("Left", "Transpose", "Forward", "Columnwise", &i__5, &
00280 ib, &nb, &a[j + j * a_dim1], lda, &work[j], &lbwork, &
00281 a[j + i__ * a_dim1], lda, &work[lbwork * nb + nt * nt
00282 + 1], &ib);
00283
00284 }
00285
00286
00287
00288
00289 i__4 = *m - i__ + 1;
00290 sgeqr2_(&i__4, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[
00291 lbwork * nb + nt * nt + 1], &iinfo);
00292 if (i__ + ib <= *n) {
00293
00294
00295
00296
00297 i__4 = *m - i__ + 1;
00298 slarft_("Forward", "Columnwise", &i__4, &ib, &a[i__ + i__ *
00299 a_dim1], lda, &tau[i__], &work[i__], &lbwork);
00300
00301 }
00302
00303 }
00304 } else {
00305 i__ = 1;
00306 }
00307
00308
00309
00310 if (i__ <= k) {
00311 if (i__ != 1) {
00312 i__2 = i__ - nb;
00313 i__1 = nb;
00314 for (j = 1; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
00315
00316
00317
00318 i__4 = *m - j + 1;
00319 i__3 = k - i__ + 1;
00320 i__5 = k - i__ + 1;
00321 slarfb_("Left", "Transpose", "Forward", "Columnwise", &i__4, &
00322 i__3, &nb, &a[j + j * a_dim1], lda, &work[j], &lbwork,
00323 &a[j + i__ * a_dim1], lda, &work[lbwork * nb + nt *
00324 nt + 1], &i__5);
00325
00326 }
00327 i__1 = *m - i__ + 1;
00328 i__2 = k - i__ + 1;
00329 sgeqr2_(&i__1, &i__2, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
00330 work[lbwork * nb + nt * nt + 1], &iinfo);
00331 } else {
00332
00333
00334
00335 i__1 = *m - i__ + 1;
00336 i__2 = *n - i__ + 1;
00337 sgeqr2_(&i__1, &i__2, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
00338 work[1], &iinfo);
00339 }
00340 }
00341
00342
00343
00344 if (*m < *n && i__ != 1) {
00345
00346
00347
00348
00349 if (nt <= nb) {
00350 i__1 = *m - i__ + 1;
00351 i__2 = k - i__ + 1;
00352 slarft_("Forward", "Columnwise", &i__1, &i__2, &a[i__ + i__ *
00353 a_dim1], lda, &tau[i__], &work[i__], &lbwork);
00354 } else {
00355 i__1 = *m - i__ + 1;
00356 i__2 = k - i__ + 1;
00357 slarft_("Forward", "Columnwise", &i__1, &i__2, &a[i__ + i__ *
00358 a_dim1], lda, &tau[i__], &work[lbwork * nb + 1], &nt);
00359 }
00360
00361
00362
00363 i__1 = k - nx;
00364 i__2 = nb;
00365 for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00366
00367 i__4 = k - j + 1;
00368 ib = min(i__4,nb);
00369 i__4 = *m - j + 1;
00370 i__3 = *n - *m;
00371 i__5 = *n - *m;
00372 slarfb_("Left", "Transpose", "Forward", "Columnwise", &i__4, &
00373 i__3, &ib, &a[j + j * a_dim1], lda, &work[j], &lbwork, &a[
00374 j + (*m + 1) * a_dim1], lda, &work[lbwork * nb + nt * nt
00375 + 1], &i__5);
00376
00377 }
00378 if (nt <= nb) {
00379 i__2 = *m - j + 1;
00380 i__1 = *n - *m;
00381 i__4 = k - j + 1;
00382 i__3 = *n - *m;
00383 slarfb_("Left", "Transpose", "Forward", "Columnwise", &i__2, &
00384 i__1, &i__4, &a[j + j * a_dim1], lda, &work[j], &lbwork, &
00385 a[j + (*m + 1) * a_dim1], lda, &work[lbwork * nb + nt *
00386 nt + 1], &i__3);
00387 } else {
00388 i__2 = *m - j + 1;
00389 i__1 = *n - *m;
00390 i__4 = k - j + 1;
00391 i__3 = *n - *m;
00392 slarfb_("Left", "Transpose", "Forward", "Columnwise", &i__2, &
00393 i__1, &i__4, &a[j + j * a_dim1], lda, &work[lbwork * nb +
00394 1], &nt, &a[j + (*m + 1) * a_dim1], lda, &work[lbwork *
00395 nb + nt * nt + 1], &i__3);
00396 }
00397 }
00398 work[1] = (real) iws;
00399 return 0;
00400
00401
00402
00403 }