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