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
00020 int zgeqpf_(integer *m, integer *n, doublecomplex *a,
00021 integer *lda, integer *jpvt, doublecomplex *tau, doublecomplex *work,
00022 doublereal *rwork, integer *info)
00023 {
00024
00025 integer a_dim1, a_offset, i__1, i__2, i__3;
00026 doublereal d__1, d__2;
00027 doublecomplex z__1;
00028
00029
00030 double sqrt(doublereal);
00031 void d_cnjg(doublecomplex *, doublecomplex *);
00032 double z_abs(doublecomplex *);
00033
00034
00035 integer i__, j, ma, mn;
00036 doublecomplex aii;
00037 integer pvt;
00038 doublereal temp, temp2, tol3z;
00039 integer itemp;
00040 extern int zlarf_(char *, integer *, integer *,
00041 doublecomplex *, integer *, doublecomplex *, doublecomplex *,
00042 integer *, doublecomplex *), zswap_(integer *,
00043 doublecomplex *, integer *, doublecomplex *, integer *), zgeqr2_(
00044 integer *, integer *, doublecomplex *, integer *, doublecomplex *,
00045 doublecomplex *, integer *);
00046 extern doublereal dznrm2_(integer *, doublecomplex *, integer *), dlamch_(
00047 char *);
00048 extern int zunm2r_(char *, char *, integer *, integer *,
00049 integer *, doublecomplex *, integer *, doublecomplex *,
00050 doublecomplex *, integer *, doublecomplex *, integer *);
00051 extern integer idamax_(integer *, doublereal *, integer *);
00052 extern int xerbla_(char *, integer *), zlarfp_(
00053 integer *, doublecomplex *, doublecomplex *, integer *,
00054 doublecomplex *);
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 a_dim1 = *lda;
00154 a_offset = 1 + a_dim1;
00155 a -= a_offset;
00156 --jpvt;
00157 --tau;
00158 --work;
00159 --rwork;
00160
00161
00162 *info = 0;
00163 if (*m < 0) {
00164 *info = -1;
00165 } else if (*n < 0) {
00166 *info = -2;
00167 } else if (*lda < max(1,*m)) {
00168 *info = -4;
00169 }
00170 if (*info != 0) {
00171 i__1 = -(*info);
00172 xerbla_("ZGEQPF", &i__1);
00173 return 0;
00174 }
00175
00176 mn = min(*m,*n);
00177 tol3z = sqrt(dlamch_("Epsilon"));
00178
00179
00180
00181 itemp = 1;
00182 i__1 = *n;
00183 for (i__ = 1; i__ <= i__1; ++i__) {
00184 if (jpvt[i__] != 0) {
00185 if (i__ != itemp) {
00186 zswap_(m, &a[i__ * a_dim1 + 1], &c__1, &a[itemp * a_dim1 + 1],
00187 &c__1);
00188 jpvt[i__] = jpvt[itemp];
00189 jpvt[itemp] = i__;
00190 } else {
00191 jpvt[i__] = i__;
00192 }
00193 ++itemp;
00194 } else {
00195 jpvt[i__] = i__;
00196 }
00197
00198 }
00199 --itemp;
00200
00201
00202
00203 if (itemp > 0) {
00204 ma = min(itemp,*m);
00205 zgeqr2_(m, &ma, &a[a_offset], lda, &tau[1], &work[1], info);
00206 if (ma < *n) {
00207 i__1 = *n - ma;
00208 zunm2r_("Left", "Conjugate transpose", m, &i__1, &ma, &a[a_offset]
00209 , lda, &tau[1], &a[(ma + 1) * a_dim1 + 1], lda, &work[1],
00210 info);
00211 }
00212 }
00213
00214 if (itemp < mn) {
00215
00216
00217
00218
00219 i__1 = *n;
00220 for (i__ = itemp + 1; i__ <= i__1; ++i__) {
00221 i__2 = *m - itemp;
00222 rwork[i__] = dznrm2_(&i__2, &a[itemp + 1 + i__ * a_dim1], &c__1);
00223 rwork[*n + i__] = rwork[i__];
00224
00225 }
00226
00227
00228
00229 i__1 = mn;
00230 for (i__ = itemp + 1; i__ <= i__1; ++i__) {
00231
00232
00233
00234 i__2 = *n - i__ + 1;
00235 pvt = i__ - 1 + idamax_(&i__2, &rwork[i__], &c__1);
00236
00237 if (pvt != i__) {
00238 zswap_(m, &a[pvt * a_dim1 + 1], &c__1, &a[i__ * a_dim1 + 1], &
00239 c__1);
00240 itemp = jpvt[pvt];
00241 jpvt[pvt] = jpvt[i__];
00242 jpvt[i__] = itemp;
00243 rwork[pvt] = rwork[i__];
00244 rwork[*n + pvt] = rwork[*n + i__];
00245 }
00246
00247
00248
00249 i__2 = i__ + i__ * a_dim1;
00250 aii.r = a[i__2].r, aii.i = a[i__2].i;
00251 i__2 = *m - i__ + 1;
00252
00253 i__3 = i__ + 1;
00254 zlarfp_(&i__2, &aii, &a[min(i__3, *m)+ i__ * a_dim1], &c__1, &tau[
00255 i__]);
00256 i__2 = i__ + i__ * a_dim1;
00257 a[i__2].r = aii.r, a[i__2].i = aii.i;
00258
00259 if (i__ < *n) {
00260
00261
00262
00263 i__2 = i__ + i__ * a_dim1;
00264 aii.r = a[i__2].r, aii.i = a[i__2].i;
00265 i__2 = i__ + i__ * a_dim1;
00266 a[i__2].r = 1., a[i__2].i = 0.;
00267 i__2 = *m - i__ + 1;
00268 i__3 = *n - i__;
00269 d_cnjg(&z__1, &tau[i__]);
00270 zlarf_("Left", &i__2, &i__3, &a[i__ + i__ * a_dim1], &c__1, &
00271 z__1, &a[i__ + (i__ + 1) * a_dim1], lda, &work[1]);
00272 i__2 = i__ + i__ * a_dim1;
00273 a[i__2].r = aii.r, a[i__2].i = aii.i;
00274 }
00275
00276
00277
00278 i__2 = *n;
00279 for (j = i__ + 1; j <= i__2; ++j) {
00280 if (rwork[j] != 0.) {
00281
00282
00283
00284
00285 temp = z_abs(&a[i__ + j * a_dim1]) / rwork[j];
00286
00287 d__1 = 0., d__2 = (temp + 1.) * (1. - temp);
00288 temp = max(d__1,d__2);
00289
00290 d__1 = rwork[j] / rwork[*n + j];
00291 temp2 = temp * (d__1 * d__1);
00292 if (temp2 <= tol3z) {
00293 if (*m - i__ > 0) {
00294 i__3 = *m - i__;
00295 rwork[j] = dznrm2_(&i__3, &a[i__ + 1 + j * a_dim1]
00296 , &c__1);
00297 rwork[*n + j] = rwork[j];
00298 } else {
00299 rwork[j] = 0.;
00300 rwork[*n + j] = 0.;
00301 }
00302 } else {
00303 rwork[j] *= sqrt(temp);
00304 }
00305 }
00306
00307 }
00308
00309
00310 }
00311 }
00312 return 0;
00313
00314
00315
00316 }