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