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 dsptrf_(char *uplo, integer *n, doublereal *ap, integer *
00021 ipiv, integer *info)
00022 {
00023
00024 integer i__1, i__2;
00025 doublereal d__1, d__2, d__3;
00026
00027
00028 double sqrt(doublereal);
00029
00030
00031 integer i__, j, k;
00032 doublereal t, r1, d11, d12, d21, d22;
00033 integer kc, kk, kp;
00034 doublereal wk;
00035 integer kx, knc, kpc, npp;
00036 doublereal wkm1, wkp1;
00037 integer imax, jmax;
00038 extern int dspr_(char *, integer *, doublereal *,
00039 doublereal *, integer *, doublereal *);
00040 doublereal alpha;
00041 extern int dscal_(integer *, doublereal *, doublereal *,
00042 integer *);
00043 extern logical lsame_(char *, char *);
00044 extern int dswap_(integer *, doublereal *, integer *,
00045 doublereal *, integer *);
00046 integer kstep;
00047 logical upper;
00048 doublereal absakk;
00049 extern integer idamax_(integer *, doublereal *, integer *);
00050 extern int xerbla_(char *, integer *);
00051 doublereal colmax, rowmax;
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
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 --ipiv;
00172 --ap;
00173
00174
00175 *info = 0;
00176 upper = lsame_(uplo, "U");
00177 if (! upper && ! lsame_(uplo, "L")) {
00178 *info = -1;
00179 } else if (*n < 0) {
00180 *info = -2;
00181 }
00182 if (*info != 0) {
00183 i__1 = -(*info);
00184 xerbla_("DSPTRF", &i__1);
00185 return 0;
00186 }
00187
00188
00189
00190 alpha = (sqrt(17.) + 1.) / 8.;
00191
00192 if (upper) {
00193
00194
00195
00196
00197
00198
00199 k = *n;
00200 kc = (*n - 1) * *n / 2 + 1;
00201 L10:
00202 knc = kc;
00203
00204
00205
00206 if (k < 1) {
00207 goto L110;
00208 }
00209 kstep = 1;
00210
00211
00212
00213
00214 absakk = (d__1 = ap[kc + k - 1], abs(d__1));
00215
00216
00217
00218
00219 if (k > 1) {
00220 i__1 = k - 1;
00221 imax = idamax_(&i__1, &ap[kc], &c__1);
00222 colmax = (d__1 = ap[kc + imax - 1], abs(d__1));
00223 } else {
00224 colmax = 0.;
00225 }
00226
00227 if (max(absakk,colmax) == 0.) {
00228
00229
00230
00231 if (*info == 0) {
00232 *info = k;
00233 }
00234 kp = k;
00235 } else {
00236 if (absakk >= alpha * colmax) {
00237
00238
00239
00240 kp = k;
00241 } else {
00242
00243
00244
00245
00246 rowmax = 0.;
00247 jmax = imax;
00248 kx = imax * (imax + 1) / 2 + imax;
00249 i__1 = k;
00250 for (j = imax + 1; j <= i__1; ++j) {
00251 if ((d__1 = ap[kx], abs(d__1)) > rowmax) {
00252 rowmax = (d__1 = ap[kx], abs(d__1));
00253 jmax = j;
00254 }
00255 kx += j;
00256
00257 }
00258 kpc = (imax - 1) * imax / 2 + 1;
00259 if (imax > 1) {
00260 i__1 = imax - 1;
00261 jmax = idamax_(&i__1, &ap[kpc], &c__1);
00262
00263 d__2 = rowmax, d__3 = (d__1 = ap[kpc + jmax - 1], abs(
00264 d__1));
00265 rowmax = max(d__2,d__3);
00266 }
00267
00268 if (absakk >= alpha * colmax * (colmax / rowmax)) {
00269
00270
00271
00272 kp = k;
00273 } else if ((d__1 = ap[kpc + imax - 1], abs(d__1)) >= alpha *
00274 rowmax) {
00275
00276
00277
00278
00279 kp = imax;
00280 } else {
00281
00282
00283
00284
00285 kp = imax;
00286 kstep = 2;
00287 }
00288 }
00289
00290 kk = k - kstep + 1;
00291 if (kstep == 2) {
00292 knc = knc - k + 1;
00293 }
00294 if (kp != kk) {
00295
00296
00297
00298
00299 i__1 = kp - 1;
00300 dswap_(&i__1, &ap[knc], &c__1, &ap[kpc], &c__1);
00301 kx = kpc + kp - 1;
00302 i__1 = kk - 1;
00303 for (j = kp + 1; j <= i__1; ++j) {
00304 kx = kx + j - 1;
00305 t = ap[knc + j - 1];
00306 ap[knc + j - 1] = ap[kx];
00307 ap[kx] = t;
00308
00309 }
00310 t = ap[knc + kk - 1];
00311 ap[knc + kk - 1] = ap[kpc + kp - 1];
00312 ap[kpc + kp - 1] = t;
00313 if (kstep == 2) {
00314 t = ap[kc + k - 2];
00315 ap[kc + k - 2] = ap[kc + kp - 1];
00316 ap[kc + kp - 1] = t;
00317 }
00318 }
00319
00320
00321
00322 if (kstep == 1) {
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 r1 = 1. / ap[kc + k - 1];
00335 i__1 = k - 1;
00336 d__1 = -r1;
00337 dspr_(uplo, &i__1, &d__1, &ap[kc], &c__1, &ap[1]);
00338
00339
00340
00341 i__1 = k - 1;
00342 dscal_(&i__1, &r1, &ap[kc], &c__1);
00343 } else {
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357 if (k > 2) {
00358
00359 d12 = ap[k - 1 + (k - 1) * k / 2];
00360 d22 = ap[k - 1 + (k - 2) * (k - 1) / 2] / d12;
00361 d11 = ap[k + (k - 1) * k / 2] / d12;
00362 t = 1. / (d11 * d22 - 1.);
00363 d12 = t / d12;
00364
00365 for (j = k - 2; j >= 1; --j) {
00366 wkm1 = d12 * (d11 * ap[j + (k - 2) * (k - 1) / 2] -
00367 ap[j + (k - 1) * k / 2]);
00368 wk = d12 * (d22 * ap[j + (k - 1) * k / 2] - ap[j + (k
00369 - 2) * (k - 1) / 2]);
00370 for (i__ = j; i__ >= 1; --i__) {
00371 ap[i__ + (j - 1) * j / 2] = ap[i__ + (j - 1) * j /
00372 2] - ap[i__ + (k - 1) * k / 2] * wk - ap[
00373 i__ + (k - 2) * (k - 1) / 2] * wkm1;
00374
00375 }
00376 ap[j + (k - 1) * k / 2] = wk;
00377 ap[j + (k - 2) * (k - 1) / 2] = wkm1;
00378
00379 }
00380
00381 }
00382
00383 }
00384 }
00385
00386
00387
00388 if (kstep == 1) {
00389 ipiv[k] = kp;
00390 } else {
00391 ipiv[k] = -kp;
00392 ipiv[k - 1] = -kp;
00393 }
00394
00395
00396
00397 k -= kstep;
00398 kc = knc - k;
00399 goto L10;
00400
00401 } else {
00402
00403
00404
00405
00406
00407
00408 k = 1;
00409 kc = 1;
00410 npp = *n * (*n + 1) / 2;
00411 L60:
00412 knc = kc;
00413
00414
00415
00416 if (k > *n) {
00417 goto L110;
00418 }
00419 kstep = 1;
00420
00421
00422
00423
00424 absakk = (d__1 = ap[kc], abs(d__1));
00425
00426
00427
00428
00429 if (k < *n) {
00430 i__1 = *n - k;
00431 imax = k + idamax_(&i__1, &ap[kc + 1], &c__1);
00432 colmax = (d__1 = ap[kc + imax - k], abs(d__1));
00433 } else {
00434 colmax = 0.;
00435 }
00436
00437 if (max(absakk,colmax) == 0.) {
00438
00439
00440
00441 if (*info == 0) {
00442 *info = k;
00443 }
00444 kp = k;
00445 } else {
00446 if (absakk >= alpha * colmax) {
00447
00448
00449
00450 kp = k;
00451 } else {
00452
00453
00454
00455
00456 rowmax = 0.;
00457 kx = kc + imax - k;
00458 i__1 = imax - 1;
00459 for (j = k; j <= i__1; ++j) {
00460 if ((d__1 = ap[kx], abs(d__1)) > rowmax) {
00461 rowmax = (d__1 = ap[kx], abs(d__1));
00462 jmax = j;
00463 }
00464 kx = kx + *n - j;
00465
00466 }
00467 kpc = npp - (*n - imax + 1) * (*n - imax + 2) / 2 + 1;
00468 if (imax < *n) {
00469 i__1 = *n - imax;
00470 jmax = imax + idamax_(&i__1, &ap[kpc + 1], &c__1);
00471
00472 d__2 = rowmax, d__3 = (d__1 = ap[kpc + jmax - imax], abs(
00473 d__1));
00474 rowmax = max(d__2,d__3);
00475 }
00476
00477 if (absakk >= alpha * colmax * (colmax / rowmax)) {
00478
00479
00480
00481 kp = k;
00482 } else if ((d__1 = ap[kpc], abs(d__1)) >= alpha * rowmax) {
00483
00484
00485
00486
00487 kp = imax;
00488 } else {
00489
00490
00491
00492
00493 kp = imax;
00494 kstep = 2;
00495 }
00496 }
00497
00498 kk = k + kstep - 1;
00499 if (kstep == 2) {
00500 knc = knc + *n - k + 1;
00501 }
00502 if (kp != kk) {
00503
00504
00505
00506
00507 if (kp < *n) {
00508 i__1 = *n - kp;
00509 dswap_(&i__1, &ap[knc + kp - kk + 1], &c__1, &ap[kpc + 1],
00510 &c__1);
00511 }
00512 kx = knc + kp - kk;
00513 i__1 = kp - 1;
00514 for (j = kk + 1; j <= i__1; ++j) {
00515 kx = kx + *n - j + 1;
00516 t = ap[knc + j - kk];
00517 ap[knc + j - kk] = ap[kx];
00518 ap[kx] = t;
00519
00520 }
00521 t = ap[knc];
00522 ap[knc] = ap[kpc];
00523 ap[kpc] = t;
00524 if (kstep == 2) {
00525 t = ap[kc + 1];
00526 ap[kc + 1] = ap[kc + kp - k];
00527 ap[kc + kp - k] = t;
00528 }
00529 }
00530
00531
00532
00533 if (kstep == 1) {
00534
00535
00536
00537
00538
00539
00540
00541 if (k < *n) {
00542
00543
00544
00545
00546
00547 r1 = 1. / ap[kc];
00548 i__1 = *n - k;
00549 d__1 = -r1;
00550 dspr_(uplo, &i__1, &d__1, &ap[kc + 1], &c__1, &ap[kc + *n
00551 - k + 1]);
00552
00553
00554
00555 i__1 = *n - k;
00556 dscal_(&i__1, &r1, &ap[kc + 1], &c__1);
00557 }
00558 } else {
00559
00560
00561
00562
00563
00564
00565
00566
00567 if (k < *n - 1) {
00568
00569
00570
00571
00572
00573
00574 d21 = ap[k + 1 + (k - 1) * ((*n << 1) - k) / 2];
00575 d11 = ap[k + 1 + k * ((*n << 1) - k - 1) / 2] / d21;
00576 d22 = ap[k + (k - 1) * ((*n << 1) - k) / 2] / d21;
00577 t = 1. / (d11 * d22 - 1.);
00578 d21 = t / d21;
00579
00580 i__1 = *n;
00581 for (j = k + 2; j <= i__1; ++j) {
00582 wk = d21 * (d11 * ap[j + (k - 1) * ((*n << 1) - k) /
00583 2] - ap[j + k * ((*n << 1) - k - 1) / 2]);
00584 wkp1 = d21 * (d22 * ap[j + k * ((*n << 1) - k - 1) /
00585 2] - ap[j + (k - 1) * ((*n << 1) - k) / 2]);
00586
00587 i__2 = *n;
00588 for (i__ = j; i__ <= i__2; ++i__) {
00589 ap[i__ + (j - 1) * ((*n << 1) - j) / 2] = ap[i__
00590 + (j - 1) * ((*n << 1) - j) / 2] - ap[i__
00591 + (k - 1) * ((*n << 1) - k) / 2] * wk -
00592 ap[i__ + k * ((*n << 1) - k - 1) / 2] *
00593 wkp1;
00594
00595 }
00596
00597 ap[j + (k - 1) * ((*n << 1) - k) / 2] = wk;
00598 ap[j + k * ((*n << 1) - k - 1) / 2] = wkp1;
00599
00600
00601 }
00602 }
00603 }
00604 }
00605
00606
00607
00608 if (kstep == 1) {
00609 ipiv[k] = kp;
00610 } else {
00611 ipiv[k] = -kp;
00612 ipiv[k + 1] = -kp;
00613 }
00614
00615
00616
00617 k += kstep;
00618 kc = knc + *n - k + 2;
00619 goto L60;
00620
00621 }
00622
00623 L110:
00624 return 0;
00625
00626
00627
00628 }