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 real c_b22 = -1.f;
00021 static real c_b24 = 1.f;
00022
00023 int spstrf_(char *uplo, integer *n, real *a, integer *lda,
00024 integer *piv, integer *rank, real *tol, real *work, integer *info)
00025 {
00026
00027 integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
00028 real r__1;
00029
00030
00031 double sqrt(doublereal);
00032
00033
00034 integer i__, j, k, maxlocval, jb, nb;
00035 real ajj;
00036 integer pvt;
00037 extern logical lsame_(char *, char *);
00038 extern int sscal_(integer *, real *, real *, integer *);
00039 integer itemp;
00040 extern int sgemv_(char *, integer *, integer *, real *,
00041 real *, integer *, real *, integer *, real *, real *, integer *);
00042 real stemp;
00043 logical upper;
00044 extern int sswap_(integer *, real *, integer *, real *,
00045 integer *);
00046 real sstop;
00047 extern int ssyrk_(char *, char *, integer *, integer *,
00048 real *, real *, integer *, real *, real *, integer *), spstf2_(char *, integer *, real *, integer *, integer *,
00049 integer *, real *, real *, integer *);
00050 extern doublereal slamch_(char *);
00051 extern int xerbla_(char *, integer *);
00052 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00053 integer *, integer *);
00054 extern logical sisnan_(real *);
00055 extern integer smaxloc_(real *, integer *);
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 --work;
00149 --piv;
00150 a_dim1 = *lda;
00151 a_offset = 1 + a_dim1;
00152 a -= a_offset;
00153
00154
00155 *info = 0;
00156 upper = lsame_(uplo, "U");
00157 if (! upper && ! lsame_(uplo, "L")) {
00158 *info = -1;
00159 } else if (*n < 0) {
00160 *info = -2;
00161 } else if (*lda < max(1,*n)) {
00162 *info = -4;
00163 }
00164 if (*info != 0) {
00165 i__1 = -(*info);
00166 xerbla_("SPSTRF", &i__1);
00167 return 0;
00168 }
00169
00170
00171
00172 if (*n == 0) {
00173 return 0;
00174 }
00175
00176
00177
00178 nb = ilaenv_(&c__1, "SPOTRF", uplo, n, &c_n1, &c_n1, &c_n1);
00179 if (nb <= 1 || nb >= *n) {
00180
00181
00182
00183 spstf2_(uplo, n, &a[a_dim1 + 1], lda, &piv[1], rank, tol, &work[1],
00184 info);
00185 goto L200;
00186
00187 } else {
00188
00189
00190
00191 i__1 = *n;
00192 for (i__ = 1; i__ <= i__1; ++i__) {
00193 piv[i__] = i__;
00194
00195 }
00196
00197
00198
00199 pvt = 1;
00200 ajj = a[pvt + pvt * a_dim1];
00201 i__1 = *n;
00202 for (i__ = 2; i__ <= i__1; ++i__) {
00203 if (a[i__ + i__ * a_dim1] > ajj) {
00204 pvt = i__;
00205 ajj = a[pvt + pvt * a_dim1];
00206 }
00207 }
00208 if (ajj == 0.f || sisnan_(&ajj)) {
00209 *rank = 0;
00210 *info = 1;
00211 goto L200;
00212 }
00213
00214
00215
00216 if (*tol < 0.f) {
00217 sstop = *n * slamch_("Epsilon") * ajj;
00218 } else {
00219 sstop = *tol;
00220 }
00221
00222
00223 if (upper) {
00224
00225
00226
00227 i__1 = *n;
00228 i__2 = nb;
00229 for (k = 1; i__2 < 0 ? k >= i__1 : k <= i__1; k += i__2) {
00230
00231
00232
00233
00234 i__3 = nb, i__4 = *n - k + 1;
00235 jb = min(i__3,i__4);
00236
00237
00238
00239
00240 i__3 = *n;
00241 for (i__ = k; i__ <= i__3; ++i__) {
00242 work[i__] = 0.f;
00243
00244 }
00245
00246 i__3 = k + jb - 1;
00247 for (j = k; j <= i__3; ++j) {
00248
00249
00250
00251
00252
00253 i__4 = *n;
00254 for (i__ = j; i__ <= i__4; ++i__) {
00255
00256 if (j > k) {
00257
00258 r__1 = a[j - 1 + i__ * a_dim1];
00259 work[i__] += r__1 * r__1;
00260 }
00261 work[*n + i__] = a[i__ + i__ * a_dim1] - work[i__];
00262
00263
00264 }
00265
00266 if (j > 1) {
00267 maxlocval = (*n << 1) - (*n + j) + 1;
00268 itemp = smaxloc_(&work[*n + j], &maxlocval);
00269 pvt = itemp + j - 1;
00270 ajj = work[*n + pvt];
00271 if (ajj <= sstop || sisnan_(&ajj)) {
00272 a[j + j * a_dim1] = ajj;
00273 goto L190;
00274 }
00275 }
00276
00277 if (j != pvt) {
00278
00279
00280
00281 a[pvt + pvt * a_dim1] = a[j + j * a_dim1];
00282 i__4 = j - 1;
00283 sswap_(&i__4, &a[j * a_dim1 + 1], &c__1, &a[pvt *
00284 a_dim1 + 1], &c__1);
00285 if (pvt < *n) {
00286 i__4 = *n - pvt;
00287 sswap_(&i__4, &a[j + (pvt + 1) * a_dim1], lda, &a[
00288 pvt + (pvt + 1) * a_dim1], lda);
00289 }
00290 i__4 = pvt - j - 1;
00291 sswap_(&i__4, &a[j + (j + 1) * a_dim1], lda, &a[j + 1
00292 + pvt * a_dim1], &c__1);
00293
00294
00295
00296 stemp = work[j];
00297 work[j] = work[pvt];
00298 work[pvt] = stemp;
00299 itemp = piv[pvt];
00300 piv[pvt] = piv[j];
00301 piv[j] = itemp;
00302 }
00303
00304 ajj = sqrt(ajj);
00305 a[j + j * a_dim1] = ajj;
00306
00307
00308
00309 if (j < *n) {
00310 i__4 = j - k;
00311 i__5 = *n - j;
00312 sgemv_("Trans", &i__4, &i__5, &c_b22, &a[k + (j + 1) *
00313 a_dim1], lda, &a[k + j * a_dim1], &c__1, &
00314 c_b24, &a[j + (j + 1) * a_dim1], lda);
00315 i__4 = *n - j;
00316 r__1 = 1.f / ajj;
00317 sscal_(&i__4, &r__1, &a[j + (j + 1) * a_dim1], lda);
00318 }
00319
00320
00321 }
00322
00323
00324
00325 if (k + jb <= *n) {
00326 i__3 = *n - j + 1;
00327 ssyrk_("Upper", "Trans", &i__3, &jb, &c_b22, &a[k + j *
00328 a_dim1], lda, &c_b24, &a[j + j * a_dim1], lda);
00329 }
00330
00331
00332 }
00333
00334 } else {
00335
00336
00337
00338 i__2 = *n;
00339 i__1 = nb;
00340 for (k = 1; i__1 < 0 ? k >= i__2 : k <= i__2; k += i__1) {
00341
00342
00343
00344
00345 i__3 = nb, i__4 = *n - k + 1;
00346 jb = min(i__3,i__4);
00347
00348
00349
00350
00351 i__3 = *n;
00352 for (i__ = k; i__ <= i__3; ++i__) {
00353 work[i__] = 0.f;
00354
00355 }
00356
00357 i__3 = k + jb - 1;
00358 for (j = k; j <= i__3; ++j) {
00359
00360
00361
00362
00363
00364 i__4 = *n;
00365 for (i__ = j; i__ <= i__4; ++i__) {
00366
00367 if (j > k) {
00368
00369 r__1 = a[i__ + (j - 1) * a_dim1];
00370 work[i__] += r__1 * r__1;
00371 }
00372 work[*n + i__] = a[i__ + i__ * a_dim1] - work[i__];
00373
00374
00375 }
00376
00377 if (j > 1) {
00378 maxlocval = (*n << 1) - (*n + j) + 1;
00379 itemp = smaxloc_(&work[*n + j], &maxlocval);
00380 pvt = itemp + j - 1;
00381 ajj = work[*n + pvt];
00382 if (ajj <= sstop || sisnan_(&ajj)) {
00383 a[j + j * a_dim1] = ajj;
00384 goto L190;
00385 }
00386 }
00387
00388 if (j != pvt) {
00389
00390
00391
00392 a[pvt + pvt * a_dim1] = a[j + j * a_dim1];
00393 i__4 = j - 1;
00394 sswap_(&i__4, &a[j + a_dim1], lda, &a[pvt + a_dim1],
00395 lda);
00396 if (pvt < *n) {
00397 i__4 = *n - pvt;
00398 sswap_(&i__4, &a[pvt + 1 + j * a_dim1], &c__1, &a[
00399 pvt + 1 + pvt * a_dim1], &c__1);
00400 }
00401 i__4 = pvt - j - 1;
00402 sswap_(&i__4, &a[j + 1 + j * a_dim1], &c__1, &a[pvt +
00403 (j + 1) * a_dim1], lda);
00404
00405
00406
00407 stemp = work[j];
00408 work[j] = work[pvt];
00409 work[pvt] = stemp;
00410 itemp = piv[pvt];
00411 piv[pvt] = piv[j];
00412 piv[j] = itemp;
00413 }
00414
00415 ajj = sqrt(ajj);
00416 a[j + j * a_dim1] = ajj;
00417
00418
00419
00420 if (j < *n) {
00421 i__4 = *n - j;
00422 i__5 = j - k;
00423 sgemv_("No Trans", &i__4, &i__5, &c_b22, &a[j + 1 + k
00424 * a_dim1], lda, &a[j + k * a_dim1], lda, &
00425 c_b24, &a[j + 1 + j * a_dim1], &c__1);
00426 i__4 = *n - j;
00427 r__1 = 1.f / ajj;
00428 sscal_(&i__4, &r__1, &a[j + 1 + j * a_dim1], &c__1);
00429 }
00430
00431
00432 }
00433
00434
00435
00436 if (k + jb <= *n) {
00437 i__3 = *n - j + 1;
00438 ssyrk_("Lower", "No Trans", &i__3, &jb, &c_b22, &a[j + k *
00439 a_dim1], lda, &c_b24, &a[j + j * a_dim1], lda);
00440 }
00441
00442
00443 }
00444
00445 }
00446 }
00447
00448
00449
00450 *rank = *n;
00451
00452 goto L200;
00453 L190:
00454
00455
00456
00457
00458 *rank = j - 1;
00459 *info = 1;
00460
00461 L200:
00462 return 0;
00463
00464
00465
00466 }