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