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