dlatbs.c
Go to the documentation of this file.
00001 /* dlatbs.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__1 = 1;
00019 static doublereal c_b36 = .5;
00020 
00021 /* Subroutine */ 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     /* System generated locals */
00026     integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4;
00027     doublereal d__1, d__2, d__3;
00028 
00029     /* Local variables */
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 /* Subroutine */ 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 /* Subroutine */ 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 /* Subroutine */ int xerbla_(char *, integer *);
00052     doublereal bignum;
00053     logical notran;
00054     integer jfirst;
00055     doublereal smlnum;
00056     logical nounit;
00057 
00058 
00059 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00060 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00061 /*     November 2006 */
00062 
00063 /*     .. Scalar Arguments .. */
00064 /*     .. */
00065 /*     .. Array Arguments .. */
00066 /*     .. */
00067 
00068 /*  Purpose */
00069 /*  ======= */
00070 
00071 /*  DLATBS solves one of the triangular systems */
00072 
00073 /*     A *x = s*b  or  A'*x = s*b */
00074 
00075 /*  with scaling to prevent overflow, where A is an upper or lower */
00076 /*  triangular band matrix.  Here A' denotes the transpose of A, x and b */
00077 /*  are n-element vectors, and s is a scaling factor, usually less than */
00078 /*  or equal to 1, chosen so that the components of x will be less than */
00079 /*  the overflow threshold.  If the unscaled problem will not cause */
00080 /*  overflow, the Level 2 BLAS routine DTBSV is called.  If the matrix A */
00081 /*  is singular (A(j,j) = 0 for some j), then s is set to 0 and a */
00082 /*  non-trivial solution to A*x = 0 is returned. */
00083 
00084 /*  Arguments */
00085 /*  ========= */
00086 
00087 /*  UPLO    (input) CHARACTER*1 */
00088 /*          Specifies whether the matrix A is upper or lower triangular. */
00089 /*          = 'U':  Upper triangular */
00090 /*          = 'L':  Lower triangular */
00091 
00092 /*  TRANS   (input) CHARACTER*1 */
00093 /*          Specifies the operation applied to A. */
00094 /*          = 'N':  Solve A * x = s*b  (No transpose) */
00095 /*          = 'T':  Solve A'* x = s*b  (Transpose) */
00096 /*          = 'C':  Solve A'* x = s*b  (Conjugate transpose = Transpose) */
00097 
00098 /*  DIAG    (input) CHARACTER*1 */
00099 /*          Specifies whether or not the matrix A is unit triangular. */
00100 /*          = 'N':  Non-unit triangular */
00101 /*          = 'U':  Unit triangular */
00102 
00103 /*  NORMIN  (input) CHARACTER*1 */
00104 /*          Specifies whether CNORM has been set or not. */
00105 /*          = 'Y':  CNORM contains the column norms on entry */
00106 /*          = 'N':  CNORM is not set on entry.  On exit, the norms will */
00107 /*                  be computed and stored in CNORM. */
00108 
00109 /*  N       (input) INTEGER */
00110 /*          The order of the matrix A.  N >= 0. */
00111 
00112 /*  KD      (input) INTEGER */
00113 /*          The number of subdiagonals or superdiagonals in the */
00114 /*          triangular matrix A.  KD >= 0. */
00115 
00116 /*  AB      (input) DOUBLE PRECISION array, dimension (LDAB,N) */
00117 /*          The upper or lower triangular band matrix A, stored in the */
00118 /*          first KD+1 rows of the array. The j-th column of A is stored */
00119 /*          in the j-th column of the array AB as follows: */
00120 /*          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
00121 /*          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd). */
00122 
00123 /*  LDAB    (input) INTEGER */
00124 /*          The leading dimension of the array AB.  LDAB >= KD+1. */
00125 
00126 /*  X       (input/output) DOUBLE PRECISION array, dimension (N) */
00127 /*          On entry, the right hand side b of the triangular system. */
00128 /*          On exit, X is overwritten by the solution vector x. */
00129 
00130 /*  SCALE   (output) DOUBLE PRECISION */
00131 /*          The scaling factor s for the triangular system */
00132 /*             A * x = s*b  or  A'* x = s*b. */
00133 /*          If SCALE = 0, the matrix A is singular or badly scaled, and */
00134 /*          the vector x is an exact or approximate solution to A*x = 0. */
00135 
00136 /*  CNORM   (input or output) DOUBLE PRECISION array, dimension (N) */
00137 
00138 /*          If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
00139 /*          contains the norm of the off-diagonal part of the j-th column */
00140 /*          of A.  If TRANS = 'N', CNORM(j) must be greater than or equal */
00141 /*          to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
00142 /*          must be greater than or equal to the 1-norm. */
00143 
00144 /*          If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
00145 /*          returns the 1-norm of the offdiagonal part of the j-th column */
00146 /*          of A. */
00147 
00148 /*  INFO    (output) INTEGER */
00149 /*          = 0:  successful exit */
00150 /*          < 0:  if INFO = -k, the k-th argument had an illegal value */
00151 
00152 /*  Further Details */
00153 /*  ======= ======= */
00154 
00155 /*  A rough bound on x is computed; if that is less than overflow, DTBSV */
00156 /*  is called, otherwise, specific code is used which checks for possible */
00157 /*  overflow or divide-by-zero at every operation. */
00158 
00159 /*  A columnwise scheme is used for solving A*x = b.  The basic algorithm */
00160 /*  if A is lower triangular is */
00161 
00162 /*       x[1:n] := b[1:n] */
00163 /*       for j = 1, ..., n */
00164 /*            x(j) := x(j) / A(j,j) */
00165 /*            x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
00166 /*       end */
00167 
00168 /*  Define bounds on the components of x after j iterations of the loop: */
00169 /*     M(j) = bound on x[1:j] */
00170 /*     G(j) = bound on x[j+1:n] */
00171 /*  Initially, let M(0) = 0 and G(0) = max{x(i), i=1,...,n}. */
00172 
00173 /*  Then for iteration j+1 we have */
00174 /*     M(j+1) <= G(j) / | A(j+1,j+1) | */
00175 /*     G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
00176 /*            <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
00177 
00178 /*  where CNORM(j+1) is greater than or equal to the infinity-norm of */
00179 /*  column j+1 of A, not counting the diagonal.  Hence */
00180 
00181 /*     G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
00182 /*                  1<=i<=j */
00183 /*  and */
00184 
00185 /*     |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
00186 /*                                   1<=i< j */
00187 
00188 /*  Since |x(j)| <= M(j), we use the Level 2 BLAS routine DTBSV if the */
00189 /*  reciprocal of the largest M(j), j=1,..,n, is larger than */
00190 /*  max(underflow, 1/overflow). */
00191 
00192 /*  The bound on x(j) is also used to determine when a step in the */
00193 /*  columnwise method can be performed without fear of overflow.  If */
00194 /*  the computed bound is greater than a large constant, x is scaled to */
00195 /*  prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
00196 /*  1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
00197 
00198 /*  Similarly, a row-wise scheme is used to solve A'*x = b.  The basic */
00199 /*  algorithm for A upper triangular is */
00200 
00201 /*       for j = 1, ..., n */
00202 /*            x(j) := ( b(j) - A[1:j-1,j]' * x[1:j-1] ) / A(j,j) */
00203 /*       end */
00204 
00205 /*  We simultaneously compute two bounds */
00206 /*       G(j) = bound on ( b(i) - A[1:i-1,i]' * x[1:i-1] ), 1<=i<=j */
00207 /*       M(j) = bound on x(i), 1<=i<=j */
00208 
00209 /*  The initial values are G(0) = 0, M(0) = max{b(i), i=1,..,n}, and we */
00210 /*  add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
00211 /*  Then the bound on x(j) is */
00212 
00213 /*       M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
00214 
00215 /*            <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
00216 /*                      1<=i<=j */
00217 
00218 /*  and we can safely call DTBSV if 1/M(n) and 1/G(n) are both greater */
00219 /*  than max(underflow, 1/overflow). */
00220 
00221 /*  ===================================================================== */
00222 
00223 /*     .. Parameters .. */
00224 /*     .. */
00225 /*     .. Local Scalars .. */
00226 /*     .. */
00227 /*     .. External Functions .. */
00228 /*     .. */
00229 /*     .. External Subroutines .. */
00230 /*     .. */
00231 /*     .. Intrinsic Functions .. */
00232 /*     .. */
00233 /*     .. Executable Statements .. */
00234 
00235     /* Parameter adjustments */
00236     ab_dim1 = *ldab;
00237     ab_offset = 1 + ab_dim1;
00238     ab -= ab_offset;
00239     --x;
00240     --cnorm;
00241 
00242     /* Function Body */
00243     *info = 0;
00244     upper = lsame_(uplo, "U");
00245     notran = lsame_(trans, "N");
00246     nounit = lsame_(diag, "N");
00247 
00248 /*     Test the input parameters. */
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 /*     Quick return if possible */
00274 
00275     if (*n == 0) {
00276         return 0;
00277     }
00278 
00279 /*     Determine machine dependent parameters to control overflow. */
00280 
00281     smlnum = dlamch_("Safe minimum") / dlamch_("Precision");
00282     bignum = 1. / smlnum;
00283     *scale = 1.;
00284 
00285     if (lsame_(normin, "N")) {
00286 
00287 /*        Compute the 1-norm of each column, not including the diagonal. */
00288 
00289         if (upper) {
00290 
00291 /*           A is upper triangular. */
00292 
00293             i__1 = *n;
00294             for (j = 1; j <= i__1; ++j) {
00295 /* Computing MIN */
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 /* L10: */
00301             }
00302         } else {
00303 
00304 /*           A is lower triangular. */
00305 
00306             i__1 = *n;
00307             for (j = 1; j <= i__1; ++j) {
00308 /* Computing MIN */
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 /* L20: */
00317             }
00318         }
00319     }
00320 
00321 /*     Scale the column norms by TSCAL if the maximum element in CNORM is */
00322 /*     greater than BIGNUM. */
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 /*     Compute a bound on the computed solution vector to see if the */
00334 /*     Level 2 BLAS routine DTBSV can be used. */
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 /*        Compute the growth in A * x = b. */
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 /*           A is non-unit triangular. */
00363 
00364 /*           Compute GROW = 1/G(j) and XBND = 1/M(j). */
00365 /*           Initially, G(0) = max{x(i), i=1,...,n}. */
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 /*              Exit the loop if the growth factor is too small. */
00374 
00375                 if (grow <= smlnum) {
00376                     goto L50;
00377                 }
00378 
00379 /*              M(j) = G(j-1) / abs(A(j,j)) */
00380 
00381                 tjj = (d__1 = ab[maind + j * ab_dim1], abs(d__1));
00382 /* Computing MIN */
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 /*                 G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
00388 
00389                     grow *= tjj / (tjj + cnorm[j]);
00390                 } else {
00391 
00392 /*                 G(j) could overflow, set GROW to 0. */
00393 
00394                     grow = 0.;
00395                 }
00396 /* L30: */
00397             }
00398             grow = xbnd;
00399         } else {
00400 
00401 /*           A is unit triangular. */
00402 
00403 /*           Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */
00404 
00405 /* Computing MIN */
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 /*              Exit the loop if the growth factor is too small. */
00413 
00414                 if (grow <= smlnum) {
00415                     goto L50;
00416                 }
00417 
00418 /*              G(j) = G(j-1)*( 1 + CNORM(j) ) */
00419 
00420                 grow *= 1. / (cnorm[j] + 1.);
00421 /* L40: */
00422             }
00423         }
00424 L50:
00425 
00426         ;
00427     } else {
00428 
00429 /*        Compute the growth in A' * x = b. */
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 /*           A is non-unit triangular. */
00451 
00452 /*           Compute GROW = 1/G(j) and XBND = 1/M(j). */
00453 /*           Initially, M(0) = max{x(i), i=1,...,n}. */
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 /*              Exit the loop if the growth factor is too small. */
00462 
00463                 if (grow <= smlnum) {
00464                     goto L80;
00465                 }
00466 
00467 /*              G(j) = max( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
00468 
00469                 xj = cnorm[j] + 1.;
00470 /* Computing MIN */
00471                 d__1 = grow, d__2 = xbnd / xj;
00472                 grow = min(d__1,d__2);
00473 
00474 /*              M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
00475 
00476                 tjj = (d__1 = ab[maind + j * ab_dim1], abs(d__1));
00477                 if (xj > tjj) {
00478                     xbnd *= tjj / xj;
00479                 }
00480 /* L60: */
00481             }
00482             grow = min(grow,xbnd);
00483         } else {
00484 
00485 /*           A is unit triangular. */
00486 
00487 /*           Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */
00488 
00489 /* Computing MIN */
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 /*              Exit the loop if the growth factor is too small. */
00497 
00498                 if (grow <= smlnum) {
00499                     goto L80;
00500                 }
00501 
00502 /*              G(j) = ( 1 + CNORM(j) )*G(j-1) */
00503 
00504                 xj = cnorm[j] + 1.;
00505                 grow /= xj;
00506 /* L70: */
00507             }
00508         }
00509 L80:
00510         ;
00511     }
00512 
00513     if (grow * tscal > smlnum) {
00514 
00515 /*        Use the Level 2 BLAS solve if the reciprocal of the bound on */
00516 /*        elements of X is not too small. */
00517 
00518         dtbsv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &x[1], &c__1);
00519     } else {
00520 
00521 /*        Use a Level 1 BLAS solve, scaling intermediate results. */
00522 
00523         if (xmax > bignum) {
00524 
00525 /*           Scale X so that its components are less than or equal to */
00526 /*           BIGNUM in absolute value. */
00527 
00528             *scale = bignum / xmax;
00529             dscal_(n, scale, &x[1], &c__1);
00530             xmax = bignum;
00531         }
00532 
00533         if (notran) {
00534 
00535 /*           Solve A * x = b */
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 /*              Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
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 /*                    abs(A(j,j)) > SMLNUM: */
00556 
00557                     if (tjj < 1.) {
00558                         if (xj > tjj * bignum) {
00559 
00560 /*                          Scale x by 1/b(j). */
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 /*                    0 < abs(A(j,j)) <= SMLNUM: */
00573 
00574                     if (xj > tjj * bignum) {
00575 
00576 /*                       Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
00577 /*                       to avoid overflow when dividing by A(j,j). */
00578 
00579                         rec = tjj * bignum / xj;
00580                         if (cnorm[j] > 1.) {
00581 
00582 /*                          Scale by 1/CNORM(j) to avoid overflow when */
00583 /*                          multiplying x(j) times column j. */
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 /*                    A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
00596 /*                    scale = 0, and compute a solution to A*x = 0. */
00597 
00598                     i__3 = *n;
00599                     for (i__ = 1; i__ <= i__3; ++i__) {
00600                         x[i__] = 0.;
00601 /* L90: */
00602                     }
00603                     x[j] = 1.;
00604                     xj = 1.;
00605                     *scale = 0.;
00606                     xmax = 0.;
00607                 }
00608 L100:
00609 
00610 /*              Scale x if necessary to avoid overflow when adding a */
00611 /*              multiple of column j of A. */
00612 
00613                 if (xj > 1.) {
00614                     rec = 1. / xj;
00615                     if (cnorm[j] > (bignum - xmax) * rec) {
00616 
00617 /*                    Scale x by 1/(2*abs(x(j))). */
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 /*                 Scale x by 1/2. */
00626 
00627                     dscal_(n, &c_b36, &x[1], &c__1);
00628                     *scale *= .5;
00629                 }
00630 
00631                 if (upper) {
00632                     if (j > 1) {
00633 
00634 /*                    Compute the update */
00635 /*                       x(max(1,j-kd):j-1) := x(max(1,j-kd):j-1) - */
00636 /*                                             x(j)* A(max(1,j-kd):j-1,j) */
00637 
00638 /* Computing MIN */
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 /*                 Compute the update */
00651 /*                    x(j+1:min(j+kd,n)) := x(j+1:min(j+kd,n)) - */
00652 /*                                          x(j) * A(j+1:min(j+kd,n),j) */
00653 
00654 /* Computing MIN */
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 /* L110: */
00667             }
00668 
00669         } else {
00670 
00671 /*           Solve A' * x = b */
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 /*              Compute x(j) = b(j) - sum A(k,j)*x(k). */
00678 /*                                    k<>j */
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 /*                 If x(j) could overflow, scale x by 1/(2*XMAX). */
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 /*                       Divide by A(j,j) when scaling x if A(j,j) > 1. */
00697 
00698 /* Computing MIN */
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 /*                 If the scaling needed for A in the dot product is 1, */
00714 /*                 call DDOT to perform the dot product. */
00715 
00716                     if (upper) {
00717 /* Computing MIN */
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 /* Computing MIN */
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 /*                 Otherwise, use in-line code for the dot product. */
00734 
00735                     if (upper) {
00736 /* Computing MIN */
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 /* L120: */
00744                         }
00745                     } else {
00746 /* Computing MIN */
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 /* L130: */
00754                         }
00755                     }
00756                 }
00757 
00758                 if (uscal == tscal) {
00759 
00760 /*                 Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */
00761 /*                 was not used to scale the dotproduct. */
00762 
00763                     x[j] -= sumj;
00764                     xj = (d__1 = x[j], abs(d__1));
00765                     if (nounit) {
00766 
00767 /*                    Compute x(j) = x(j) / A(j,j), scaling if necessary. */
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 /*                       abs(A(j,j)) > SMLNUM: */
00780 
00781                         if (tjj < 1.) {
00782                             if (xj > tjj * bignum) {
00783 
00784 /*                             Scale X by 1/abs(x(j)). */
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 /*                       0 < abs(A(j,j)) <= SMLNUM: */
00796 
00797                         if (xj > tjj * bignum) {
00798 
00799 /*                          Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
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 /*                       A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
00810 /*                       scale = 0, and compute a solution to A'*x = 0. */
00811 
00812                         i__3 = *n;
00813                         for (i__ = 1; i__ <= i__3; ++i__) {
00814                             x[i__] = 0.;
00815 /* L140: */
00816                         }
00817                         x[j] = 1.;
00818                         *scale = 0.;
00819                         xmax = 0.;
00820                     }
00821 L150:
00822                     ;
00823                 } else {
00824 
00825 /*                 Compute x(j) := x(j) / A(j,j) - sumj if the dot */
00826 /*                 product has already been divided by 1/A(j,j). */
00827 
00828                     x[j] = x[j] / tjjs - sumj;
00829                 }
00830 /* Computing MAX */
00831                 d__2 = xmax, d__3 = (d__1 = x[j], abs(d__1));
00832                 xmax = max(d__2,d__3);
00833 /* L160: */
00834             }
00835         }
00836         *scale /= tscal;
00837     }
00838 
00839 /*     Scale the column norms by 1/TSCAL for return. */
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 /*     End of DLATBS */
00849 
00850 } /* dlatbs_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:46