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 real c_b16 = -1.f;
00020 static real c_b18 = 1.f;
00021
00022 int spstf2_(char *uplo, integer *n, real *a, integer *lda,
00023 integer *piv, integer *rank, real *tol, real *work, integer *info)
00024 {
00025
00026 integer a_dim1, a_offset, i__1, i__2, i__3;
00027 real r__1;
00028
00029
00030 double sqrt(doublereal);
00031
00032
00033 integer i__, j, maxlocval;
00034 real ajj;
00035 integer pvt;
00036 extern logical lsame_(char *, char *);
00037 extern int sscal_(integer *, real *, real *, integer *);
00038 integer itemp;
00039 extern int sgemv_(char *, integer *, integer *, real *,
00040 real *, integer *, real *, integer *, real *, real *, integer *);
00041 real stemp;
00042 logical upper;
00043 extern int sswap_(integer *, real *, integer *, real *,
00044 integer *);
00045 real sstop;
00046 extern doublereal slamch_(char *);
00047 extern int xerbla_(char *, integer *);
00048 extern logical sisnan_(real *);
00049 extern integer smaxloc_(real *, 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 --work;
00143 --piv;
00144 a_dim1 = *lda;
00145 a_offset = 1 + a_dim1;
00146 a -= a_offset;
00147
00148
00149 *info = 0;
00150 upper = lsame_(uplo, "U");
00151 if (! upper && ! lsame_(uplo, "L")) {
00152 *info = -1;
00153 } else if (*n < 0) {
00154 *info = -2;
00155 } else if (*lda < max(1,*n)) {
00156 *info = -4;
00157 }
00158 if (*info != 0) {
00159 i__1 = -(*info);
00160 xerbla_("SPSTF2", &i__1);
00161 return 0;
00162 }
00163
00164
00165
00166 if (*n == 0) {
00167 return 0;
00168 }
00169
00170
00171
00172 i__1 = *n;
00173 for (i__ = 1; i__ <= i__1; ++i__) {
00174 piv[i__] = i__;
00175
00176 }
00177
00178
00179
00180 pvt = 1;
00181 ajj = a[pvt + pvt * a_dim1];
00182 i__1 = *n;
00183 for (i__ = 2; i__ <= i__1; ++i__) {
00184 if (a[i__ + i__ * a_dim1] > ajj) {
00185 pvt = i__;
00186 ajj = a[pvt + pvt * a_dim1];
00187 }
00188 }
00189 if (ajj == 0.f || sisnan_(&ajj)) {
00190 *rank = 0;
00191 *info = 1;
00192 goto L170;
00193 }
00194
00195
00196
00197 if (*tol < 0.f) {
00198 sstop = *n * slamch_("Epsilon") * ajj;
00199 } else {
00200 sstop = *tol;
00201 }
00202
00203
00204
00205 i__1 = *n;
00206 for (i__ = 1; i__ <= i__1; ++i__) {
00207 work[i__] = 0.f;
00208
00209 }
00210
00211 if (upper) {
00212
00213
00214
00215 i__1 = *n;
00216 for (j = 1; j <= i__1; ++j) {
00217
00218
00219
00220
00221
00222 i__2 = *n;
00223 for (i__ = j; i__ <= i__2; ++i__) {
00224
00225 if (j > 1) {
00226
00227 r__1 = a[j - 1 + i__ * a_dim1];
00228 work[i__] += r__1 * r__1;
00229 }
00230 work[*n + i__] = a[i__ + i__ * a_dim1] - work[i__];
00231
00232
00233 }
00234
00235 if (j > 1) {
00236 maxlocval = (*n << 1) - (*n + j) + 1;
00237 itemp = smaxloc_(&work[*n + j], &maxlocval);
00238 pvt = itemp + j - 1;
00239 ajj = work[*n + pvt];
00240 if (ajj <= sstop || sisnan_(&ajj)) {
00241 a[j + j * a_dim1] = ajj;
00242 goto L160;
00243 }
00244 }
00245
00246 if (j != pvt) {
00247
00248
00249
00250 a[pvt + pvt * a_dim1] = a[j + j * a_dim1];
00251 i__2 = j - 1;
00252 sswap_(&i__2, &a[j * a_dim1 + 1], &c__1, &a[pvt * a_dim1 + 1],
00253 &c__1);
00254 if (pvt < *n) {
00255 i__2 = *n - pvt;
00256 sswap_(&i__2, &a[j + (pvt + 1) * a_dim1], lda, &a[pvt + (
00257 pvt + 1) * a_dim1], lda);
00258 }
00259 i__2 = pvt - j - 1;
00260 sswap_(&i__2, &a[j + (j + 1) * a_dim1], lda, &a[j + 1 + pvt *
00261 a_dim1], &c__1);
00262
00263
00264
00265 stemp = work[j];
00266 work[j] = work[pvt];
00267 work[pvt] = stemp;
00268 itemp = piv[pvt];
00269 piv[pvt] = piv[j];
00270 piv[j] = itemp;
00271 }
00272
00273 ajj = sqrt(ajj);
00274 a[j + j * a_dim1] = ajj;
00275
00276
00277
00278 if (j < *n) {
00279 i__2 = j - 1;
00280 i__3 = *n - j;
00281 sgemv_("Trans", &i__2, &i__3, &c_b16, &a[(j + 1) * a_dim1 + 1]
00282 , lda, &a[j * a_dim1 + 1], &c__1, &c_b18, &a[j + (j +
00283 1) * a_dim1], lda);
00284 i__2 = *n - j;
00285 r__1 = 1.f / ajj;
00286 sscal_(&i__2, &r__1, &a[j + (j + 1) * a_dim1], lda);
00287 }
00288
00289
00290 }
00291
00292 } else {
00293
00294
00295
00296 i__1 = *n;
00297 for (j = 1; j <= i__1; ++j) {
00298
00299
00300
00301
00302
00303 i__2 = *n;
00304 for (i__ = j; i__ <= i__2; ++i__) {
00305
00306 if (j > 1) {
00307
00308 r__1 = a[i__ + (j - 1) * a_dim1];
00309 work[i__] += r__1 * r__1;
00310 }
00311 work[*n + i__] = a[i__ + i__ * a_dim1] - work[i__];
00312
00313
00314 }
00315
00316 if (j > 1) {
00317 maxlocval = (*n << 1) - (*n + j) + 1;
00318 itemp = smaxloc_(&work[*n + j], &maxlocval);
00319 pvt = itemp + j - 1;
00320 ajj = work[*n + pvt];
00321 if (ajj <= sstop || sisnan_(&ajj)) {
00322 a[j + j * a_dim1] = ajj;
00323 goto L160;
00324 }
00325 }
00326
00327 if (j != pvt) {
00328
00329
00330
00331 a[pvt + pvt * a_dim1] = a[j + j * a_dim1];
00332 i__2 = j - 1;
00333 sswap_(&i__2, &a[j + a_dim1], lda, &a[pvt + a_dim1], lda);
00334 if (pvt < *n) {
00335 i__2 = *n - pvt;
00336 sswap_(&i__2, &a[pvt + 1 + j * a_dim1], &c__1, &a[pvt + 1
00337 + pvt * a_dim1], &c__1);
00338 }
00339 i__2 = pvt - j - 1;
00340 sswap_(&i__2, &a[j + 1 + j * a_dim1], &c__1, &a[pvt + (j + 1)
00341 * a_dim1], lda);
00342
00343
00344
00345 stemp = work[j];
00346 work[j] = work[pvt];
00347 work[pvt] = stemp;
00348 itemp = piv[pvt];
00349 piv[pvt] = piv[j];
00350 piv[j] = itemp;
00351 }
00352
00353 ajj = sqrt(ajj);
00354 a[j + j * a_dim1] = ajj;
00355
00356
00357
00358 if (j < *n) {
00359 i__2 = *n - j;
00360 i__3 = j - 1;
00361 sgemv_("No Trans", &i__2, &i__3, &c_b16, &a[j + 1 + a_dim1],
00362 lda, &a[j + a_dim1], lda, &c_b18, &a[j + 1 + j *
00363 a_dim1], &c__1);
00364 i__2 = *n - j;
00365 r__1 = 1.f / ajj;
00366 sscal_(&i__2, &r__1, &a[j + 1 + j * a_dim1], &c__1);
00367 }
00368
00369
00370 }
00371
00372 }
00373
00374
00375
00376 *rank = *n;
00377
00378 goto L170;
00379 L160:
00380
00381
00382
00383
00384 *rank = j - 1;
00385 *info = 1;
00386
00387 L170:
00388 return 0;
00389
00390
00391
00392 }