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