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