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