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 zgeqp3_(integer *m, integer *n, doublecomplex *a,
00024 integer *lda, integer *jpvt, doublecomplex *tau, doublecomplex *work,
00025 integer *lwork, doublereal *rwork, integer *info)
00026 {
00027
00028 integer a_dim1, a_offset, i__1, i__2, i__3;
00029
00030
00031 integer j, jb, na, nb, sm, sn, nx, fjb, iws, nfxd, nbmin, minmn, minws;
00032 extern int zswap_(integer *, doublecomplex *, integer *,
00033 doublecomplex *, integer *), zlaqp2_(integer *, integer *,
00034 integer *, doublecomplex *, integer *, integer *, doublecomplex *,
00035 doublereal *, doublereal *, doublecomplex *);
00036 extern doublereal dznrm2_(integer *, doublecomplex *, integer *);
00037 extern int xerbla_(char *, integer *);
00038 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00039 integer *, integer *);
00040 extern int zgeqrf_(integer *, integer *, doublecomplex *,
00041 integer *, doublecomplex *, doublecomplex *, integer *, integer *
00042 );
00043 integer topbmn, sminmn;
00044 extern int zlaqps_(integer *, integer *, integer *,
00045 integer *, integer *, doublecomplex *, integer *, integer *,
00046 doublecomplex *, doublereal *, doublereal *, doublecomplex *,
00047 doublecomplex *, integer *);
00048 integer lwkopt;
00049 logical lquery;
00050 extern int zunmqr_(char *, char *, integer *, integer *,
00051 integer *, doublecomplex *, integer *, doublecomplex *,
00052 doublecomplex *, integer *, doublecomplex *, integer *, integer *);
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 a_dim1 = *lda;
00157 a_offset = 1 + a_dim1;
00158 a -= a_offset;
00159 --jpvt;
00160 --tau;
00161 --work;
00162 --rwork;
00163
00164
00165 *info = 0;
00166 lquery = *lwork == -1;
00167 if (*m < 0) {
00168 *info = -1;
00169 } else if (*n < 0) {
00170 *info = -2;
00171 } else if (*lda < max(1,*m)) {
00172 *info = -4;
00173 }
00174
00175 if (*info == 0) {
00176 minmn = min(*m,*n);
00177 if (minmn == 0) {
00178 iws = 1;
00179 lwkopt = 1;
00180 } else {
00181 iws = *n + 1;
00182 nb = ilaenv_(&c__1, "ZGEQRF", " ", m, n, &c_n1, &c_n1);
00183 lwkopt = (*n + 1) * nb;
00184 }
00185 work[1].r = (doublereal) lwkopt, work[1].i = 0.;
00186
00187 if (*lwork < iws && ! lquery) {
00188 *info = -8;
00189 }
00190 }
00191
00192 if (*info != 0) {
00193 i__1 = -(*info);
00194 xerbla_("ZGEQP3", &i__1);
00195 return 0;
00196 } else if (lquery) {
00197 return 0;
00198 }
00199
00200
00201
00202 if (minmn == 0) {
00203 return 0;
00204 }
00205
00206
00207
00208 nfxd = 1;
00209 i__1 = *n;
00210 for (j = 1; j <= i__1; ++j) {
00211 if (jpvt[j] != 0) {
00212 if (j != nfxd) {
00213 zswap_(m, &a[j * a_dim1 + 1], &c__1, &a[nfxd * a_dim1 + 1], &
00214 c__1);
00215 jpvt[j] = jpvt[nfxd];
00216 jpvt[nfxd] = j;
00217 } else {
00218 jpvt[j] = j;
00219 }
00220 ++nfxd;
00221 } else {
00222 jpvt[j] = j;
00223 }
00224
00225 }
00226 --nfxd;
00227
00228
00229
00230
00231
00232
00233
00234 if (nfxd > 0) {
00235 na = min(*m,nfxd);
00236
00237 zgeqrf_(m, &na, &a[a_offset], lda, &tau[1], &work[1], lwork, info);
00238
00239 i__1 = iws, i__2 = (integer) work[1].r;
00240 iws = max(i__1,i__2);
00241 if (na < *n) {
00242
00243
00244
00245 i__1 = *n - na;
00246 zunmqr_("Left", "Conjugate Transpose", m, &i__1, &na, &a[a_offset]
00247 , lda, &tau[1], &a[(na + 1) * a_dim1 + 1], lda, &work[1],
00248 lwork, info);
00249
00250 i__1 = iws, i__2 = (integer) work[1].r;
00251 iws = max(i__1,i__2);
00252 }
00253 }
00254
00255
00256
00257
00258 if (nfxd < minmn) {
00259
00260 sm = *m - nfxd;
00261 sn = *n - nfxd;
00262 sminmn = minmn - nfxd;
00263
00264
00265
00266 nb = ilaenv_(&c__1, "ZGEQRF", " ", &sm, &sn, &c_n1, &c_n1);
00267 nbmin = 2;
00268 nx = 0;
00269
00270 if (nb > 1 && nb < sminmn) {
00271
00272
00273
00274
00275 i__1 = 0, i__2 = ilaenv_(&c__3, "ZGEQRF", " ", &sm, &sn, &c_n1, &
00276 c_n1);
00277 nx = max(i__1,i__2);
00278
00279
00280 if (nx < sminmn) {
00281
00282
00283
00284 minws = (sn + 1) * nb;
00285 iws = max(iws,minws);
00286 if (*lwork < minws) {
00287
00288
00289
00290
00291 nb = *lwork / (sn + 1);
00292
00293 i__1 = 2, i__2 = ilaenv_(&c__2, "ZGEQRF", " ", &sm, &sn, &
00294 c_n1, &c_n1);
00295 nbmin = max(i__1,i__2);
00296
00297
00298 }
00299 }
00300 }
00301
00302
00303
00304
00305 i__1 = *n;
00306 for (j = nfxd + 1; j <= i__1; ++j) {
00307 rwork[j] = dznrm2_(&sm, &a[nfxd + 1 + j * a_dim1], &c__1);
00308 rwork[*n + j] = rwork[j];
00309
00310 }
00311
00312 if (nb >= nbmin && nb < sminmn && nx < sminmn) {
00313
00314
00315
00316 j = nfxd + 1;
00317
00318
00319
00320
00321 topbmn = minmn - nx;
00322 L30:
00323 if (j <= topbmn) {
00324
00325 i__1 = nb, i__2 = topbmn - j + 1;
00326 jb = min(i__1,i__2);
00327
00328
00329
00330 i__1 = *n - j + 1;
00331 i__2 = j - 1;
00332 i__3 = *n - j + 1;
00333 zlaqps_(m, &i__1, &i__2, &jb, &fjb, &a[j * a_dim1 + 1], lda, &
00334 jpvt[j], &tau[j], &rwork[j], &rwork[*n + j], &work[1],
00335 &work[jb + 1], &i__3);
00336
00337 j += fjb;
00338 goto L30;
00339 }
00340 } else {
00341 j = nfxd + 1;
00342 }
00343
00344
00345
00346
00347 if (j <= minmn) {
00348 i__1 = *n - j + 1;
00349 i__2 = j - 1;
00350 zlaqp2_(m, &i__1, &i__2, &a[j * a_dim1 + 1], lda, &jpvt[j], &tau[
00351 j], &rwork[j], &rwork[*n + j], &work[1]);
00352 }
00353
00354 }
00355
00356 work[1].r = (doublereal) iws, work[1].i = 0.;
00357 return 0;
00358
00359
00360
00361 }