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_b36 = .5f;
00020
00021 int slatps_(char *uplo, char *trans, char *diag, char *
00022 normin, integer *n, real *ap, real *x, real *scale, real *cnorm,
00023 integer *info)
00024 {
00025
00026 integer i__1, i__2, i__3;
00027 real r__1, r__2, r__3;
00028
00029
00030 integer i__, j, ip;
00031 real xj, rec, tjj;
00032 integer jinc, jlen;
00033 real xbnd;
00034 integer imax;
00035 real tmax, tjjs;
00036 extern doublereal sdot_(integer *, real *, integer *, real *, integer *);
00037 real xmax, grow, sumj;
00038 extern logical lsame_(char *, char *);
00039 extern int sscal_(integer *, real *, real *, integer *);
00040 real tscal, uscal;
00041 integer jlast;
00042 extern doublereal sasum_(integer *, real *, integer *);
00043 logical upper;
00044 extern int saxpy_(integer *, real *, real *, integer *,
00045 real *, integer *), stpsv_(char *, char *, char *, integer *,
00046 real *, real *, integer *);
00047 extern doublereal slamch_(char *);
00048 extern int xerbla_(char *, integer *);
00049 real bignum;
00050 extern integer isamax_(integer *, real *, integer *);
00051 logical notran;
00052 integer jfirst;
00053 real smlnum;
00054 logical nounit;
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
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 --cnorm;
00228 --x;
00229 --ap;
00230
00231
00232 *info = 0;
00233 upper = lsame_(uplo, "U");
00234 notran = lsame_(trans, "N");
00235 nounit = lsame_(diag, "N");
00236
00237
00238
00239 if (! upper && ! lsame_(uplo, "L")) {
00240 *info = -1;
00241 } else if (! notran && ! lsame_(trans, "T") && !
00242 lsame_(trans, "C")) {
00243 *info = -2;
00244 } else if (! nounit && ! lsame_(diag, "U")) {
00245 *info = -3;
00246 } else if (! lsame_(normin, "Y") && ! lsame_(normin,
00247 "N")) {
00248 *info = -4;
00249 } else if (*n < 0) {
00250 *info = -5;
00251 }
00252 if (*info != 0) {
00253 i__1 = -(*info);
00254 xerbla_("SLATPS", &i__1);
00255 return 0;
00256 }
00257
00258
00259
00260 if (*n == 0) {
00261 return 0;
00262 }
00263
00264
00265
00266 smlnum = slamch_("Safe minimum") / slamch_("Precision");
00267 bignum = 1.f / smlnum;
00268 *scale = 1.f;
00269
00270 if (lsame_(normin, "N")) {
00271
00272
00273
00274 if (upper) {
00275
00276
00277
00278 ip = 1;
00279 i__1 = *n;
00280 for (j = 1; j <= i__1; ++j) {
00281 i__2 = j - 1;
00282 cnorm[j] = sasum_(&i__2, &ap[ip], &c__1);
00283 ip += j;
00284
00285 }
00286 } else {
00287
00288
00289
00290 ip = 1;
00291 i__1 = *n - 1;
00292 for (j = 1; j <= i__1; ++j) {
00293 i__2 = *n - j;
00294 cnorm[j] = sasum_(&i__2, &ap[ip + 1], &c__1);
00295 ip = ip + *n - j + 1;
00296
00297 }
00298 cnorm[*n] = 0.f;
00299 }
00300 }
00301
00302
00303
00304
00305 imax = isamax_(n, &cnorm[1], &c__1);
00306 tmax = cnorm[imax];
00307 if (tmax <= bignum) {
00308 tscal = 1.f;
00309 } else {
00310 tscal = 1.f / (smlnum * tmax);
00311 sscal_(n, &tscal, &cnorm[1], &c__1);
00312 }
00313
00314
00315
00316
00317 j = isamax_(n, &x[1], &c__1);
00318 xmax = (r__1 = x[j], dabs(r__1));
00319 xbnd = xmax;
00320 if (notran) {
00321
00322
00323
00324 if (upper) {
00325 jfirst = *n;
00326 jlast = 1;
00327 jinc = -1;
00328 } else {
00329 jfirst = 1;
00330 jlast = *n;
00331 jinc = 1;
00332 }
00333
00334 if (tscal != 1.f) {
00335 grow = 0.f;
00336 goto L50;
00337 }
00338
00339 if (nounit) {
00340
00341
00342
00343
00344
00345
00346 grow = 1.f / dmax(xbnd,smlnum);
00347 xbnd = grow;
00348 ip = jfirst * (jfirst + 1) / 2;
00349 jlen = *n;
00350 i__1 = jlast;
00351 i__2 = jinc;
00352 for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00353
00354
00355
00356 if (grow <= smlnum) {
00357 goto L50;
00358 }
00359
00360
00361
00362 tjj = (r__1 = ap[ip], dabs(r__1));
00363
00364 r__1 = xbnd, r__2 = dmin(1.f,tjj) * grow;
00365 xbnd = dmin(r__1,r__2);
00366 if (tjj + cnorm[j] >= smlnum) {
00367
00368
00369
00370 grow *= tjj / (tjj + cnorm[j]);
00371 } else {
00372
00373
00374
00375 grow = 0.f;
00376 }
00377 ip += jinc * jlen;
00378 --jlen;
00379
00380 }
00381 grow = xbnd;
00382 } else {
00383
00384
00385
00386
00387
00388
00389 r__1 = 1.f, r__2 = 1.f / dmax(xbnd,smlnum);
00390 grow = dmin(r__1,r__2);
00391 i__2 = jlast;
00392 i__1 = jinc;
00393 for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
00394
00395
00396
00397 if (grow <= smlnum) {
00398 goto L50;
00399 }
00400
00401
00402
00403 grow *= 1.f / (cnorm[j] + 1.f);
00404
00405 }
00406 }
00407 L50:
00408
00409 ;
00410 } else {
00411
00412
00413
00414 if (upper) {
00415 jfirst = 1;
00416 jlast = *n;
00417 jinc = 1;
00418 } else {
00419 jfirst = *n;
00420 jlast = 1;
00421 jinc = -1;
00422 }
00423
00424 if (tscal != 1.f) {
00425 grow = 0.f;
00426 goto L80;
00427 }
00428
00429 if (nounit) {
00430
00431
00432
00433
00434
00435
00436 grow = 1.f / dmax(xbnd,smlnum);
00437 xbnd = grow;
00438 ip = jfirst * (jfirst + 1) / 2;
00439 jlen = 1;
00440 i__1 = jlast;
00441 i__2 = jinc;
00442 for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00443
00444
00445
00446 if (grow <= smlnum) {
00447 goto L80;
00448 }
00449
00450
00451
00452 xj = cnorm[j] + 1.f;
00453
00454 r__1 = grow, r__2 = xbnd / xj;
00455 grow = dmin(r__1,r__2);
00456
00457
00458
00459 tjj = (r__1 = ap[ip], dabs(r__1));
00460 if (xj > tjj) {
00461 xbnd *= tjj / xj;
00462 }
00463 ++jlen;
00464 ip += jinc * jlen;
00465
00466 }
00467 grow = dmin(grow,xbnd);
00468 } else {
00469
00470
00471
00472
00473
00474
00475 r__1 = 1.f, r__2 = 1.f / dmax(xbnd,smlnum);
00476 grow = dmin(r__1,r__2);
00477 i__2 = jlast;
00478 i__1 = jinc;
00479 for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
00480
00481
00482
00483 if (grow <= smlnum) {
00484 goto L80;
00485 }
00486
00487
00488
00489 xj = cnorm[j] + 1.f;
00490 grow /= xj;
00491
00492 }
00493 }
00494 L80:
00495 ;
00496 }
00497
00498 if (grow * tscal > smlnum) {
00499
00500
00501
00502
00503 stpsv_(uplo, trans, diag, n, &ap[1], &x[1], &c__1);
00504 } else {
00505
00506
00507
00508 if (xmax > bignum) {
00509
00510
00511
00512
00513 *scale = bignum / xmax;
00514 sscal_(n, scale, &x[1], &c__1);
00515 xmax = bignum;
00516 }
00517
00518 if (notran) {
00519
00520
00521
00522 ip = jfirst * (jfirst + 1) / 2;
00523 i__1 = jlast;
00524 i__2 = jinc;
00525 for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00526
00527
00528
00529 xj = (r__1 = x[j], dabs(r__1));
00530 if (nounit) {
00531 tjjs = ap[ip] * tscal;
00532 } else {
00533 tjjs = tscal;
00534 if (tscal == 1.f) {
00535 goto L95;
00536 }
00537 }
00538 tjj = dabs(tjjs);
00539 if (tjj > smlnum) {
00540
00541
00542
00543 if (tjj < 1.f) {
00544 if (xj > tjj * bignum) {
00545
00546
00547
00548 rec = 1.f / xj;
00549 sscal_(n, &rec, &x[1], &c__1);
00550 *scale *= rec;
00551 xmax *= rec;
00552 }
00553 }
00554 x[j] /= tjjs;
00555 xj = (r__1 = x[j], dabs(r__1));
00556 } else if (tjj > 0.f) {
00557
00558
00559
00560 if (xj > tjj * bignum) {
00561
00562
00563
00564
00565 rec = tjj * bignum / xj;
00566 if (cnorm[j] > 1.f) {
00567
00568
00569
00570
00571 rec /= cnorm[j];
00572 }
00573 sscal_(n, &rec, &x[1], &c__1);
00574 *scale *= rec;
00575 xmax *= rec;
00576 }
00577 x[j] /= tjjs;
00578 xj = (r__1 = x[j], dabs(r__1));
00579 } else {
00580
00581
00582
00583
00584 i__3 = *n;
00585 for (i__ = 1; i__ <= i__3; ++i__) {
00586 x[i__] = 0.f;
00587
00588 }
00589 x[j] = 1.f;
00590 xj = 1.f;
00591 *scale = 0.f;
00592 xmax = 0.f;
00593 }
00594 L95:
00595
00596
00597
00598
00599 if (xj > 1.f) {
00600 rec = 1.f / xj;
00601 if (cnorm[j] > (bignum - xmax) * rec) {
00602
00603
00604
00605 rec *= .5f;
00606 sscal_(n, &rec, &x[1], &c__1);
00607 *scale *= rec;
00608 }
00609 } else if (xj * cnorm[j] > bignum - xmax) {
00610
00611
00612
00613 sscal_(n, &c_b36, &x[1], &c__1);
00614 *scale *= .5f;
00615 }
00616
00617 if (upper) {
00618 if (j > 1) {
00619
00620
00621
00622
00623 i__3 = j - 1;
00624 r__1 = -x[j] * tscal;
00625 saxpy_(&i__3, &r__1, &ap[ip - j + 1], &c__1, &x[1], &
00626 c__1);
00627 i__3 = j - 1;
00628 i__ = isamax_(&i__3, &x[1], &c__1);
00629 xmax = (r__1 = x[i__], dabs(r__1));
00630 }
00631 ip -= j;
00632 } else {
00633 if (j < *n) {
00634
00635
00636
00637
00638 i__3 = *n - j;
00639 r__1 = -x[j] * tscal;
00640 saxpy_(&i__3, &r__1, &ap[ip + 1], &c__1, &x[j + 1], &
00641 c__1);
00642 i__3 = *n - j;
00643 i__ = j + isamax_(&i__3, &x[j + 1], &c__1);
00644 xmax = (r__1 = x[i__], dabs(r__1));
00645 }
00646 ip = ip + *n - j + 1;
00647 }
00648
00649 }
00650
00651 } else {
00652
00653
00654
00655 ip = jfirst * (jfirst + 1) / 2;
00656 jlen = 1;
00657 i__2 = jlast;
00658 i__1 = jinc;
00659 for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
00660
00661
00662
00663
00664 xj = (r__1 = x[j], dabs(r__1));
00665 uscal = tscal;
00666 rec = 1.f / dmax(xmax,1.f);
00667 if (cnorm[j] > (bignum - xj) * rec) {
00668
00669
00670
00671 rec *= .5f;
00672 if (nounit) {
00673 tjjs = ap[ip] * tscal;
00674 } else {
00675 tjjs = tscal;
00676 }
00677 tjj = dabs(tjjs);
00678 if (tjj > 1.f) {
00679
00680
00681
00682
00683 r__1 = 1.f, r__2 = rec * tjj;
00684 rec = dmin(r__1,r__2);
00685 uscal /= tjjs;
00686 }
00687 if (rec < 1.f) {
00688 sscal_(n, &rec, &x[1], &c__1);
00689 *scale *= rec;
00690 xmax *= rec;
00691 }
00692 }
00693
00694 sumj = 0.f;
00695 if (uscal == 1.f) {
00696
00697
00698
00699
00700 if (upper) {
00701 i__3 = j - 1;
00702 sumj = sdot_(&i__3, &ap[ip - j + 1], &c__1, &x[1], &
00703 c__1);
00704 } else if (j < *n) {
00705 i__3 = *n - j;
00706 sumj = sdot_(&i__3, &ap[ip + 1], &c__1, &x[j + 1], &
00707 c__1);
00708 }
00709 } else {
00710
00711
00712
00713 if (upper) {
00714 i__3 = j - 1;
00715 for (i__ = 1; i__ <= i__3; ++i__) {
00716 sumj += ap[ip - j + i__] * uscal * x[i__];
00717
00718 }
00719 } else if (j < *n) {
00720 i__3 = *n - j;
00721 for (i__ = 1; i__ <= i__3; ++i__) {
00722 sumj += ap[ip + i__] * uscal * x[j + i__];
00723
00724 }
00725 }
00726 }
00727
00728 if (uscal == tscal) {
00729
00730
00731
00732
00733 x[j] -= sumj;
00734 xj = (r__1 = x[j], dabs(r__1));
00735 if (nounit) {
00736
00737
00738
00739 tjjs = ap[ip] * tscal;
00740 } else {
00741 tjjs = tscal;
00742 if (tscal == 1.f) {
00743 goto L135;
00744 }
00745 }
00746 tjj = dabs(tjjs);
00747 if (tjj > smlnum) {
00748
00749
00750
00751 if (tjj < 1.f) {
00752 if (xj > tjj * bignum) {
00753
00754
00755
00756 rec = 1.f / xj;
00757 sscal_(n, &rec, &x[1], &c__1);
00758 *scale *= rec;
00759 xmax *= rec;
00760 }
00761 }
00762 x[j] /= tjjs;
00763 } else if (tjj > 0.f) {
00764
00765
00766
00767 if (xj > tjj * bignum) {
00768
00769
00770
00771 rec = tjj * bignum / xj;
00772 sscal_(n, &rec, &x[1], &c__1);
00773 *scale *= rec;
00774 xmax *= rec;
00775 }
00776 x[j] /= tjjs;
00777 } else {
00778
00779
00780
00781
00782 i__3 = *n;
00783 for (i__ = 1; i__ <= i__3; ++i__) {
00784 x[i__] = 0.f;
00785
00786 }
00787 x[j] = 1.f;
00788 *scale = 0.f;
00789 xmax = 0.f;
00790 }
00791 L135:
00792 ;
00793 } else {
00794
00795
00796
00797
00798 x[j] = x[j] / tjjs - sumj;
00799 }
00800
00801 r__2 = xmax, r__3 = (r__1 = x[j], dabs(r__1));
00802 xmax = dmax(r__2,r__3);
00803 ++jlen;
00804 ip += jinc * jlen;
00805
00806 }
00807 }
00808 *scale /= tscal;
00809 }
00810
00811
00812
00813 if (tscal != 1.f) {
00814 r__1 = 1.f / tscal;
00815 sscal_(n, &r__1, &cnorm[1], &c__1);
00816 }
00817
00818 return 0;
00819
00820
00821
00822 }