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