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