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