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