dlatrs.c
Go to the documentation of this file.
00001 /* dlatrs.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 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     /* System generated locals */
00026     integer a_dim1, a_offset, i__1, i__2, i__3;
00027     doublereal d__1, d__2, d__3;
00028 
00029     /* Local variables */
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 /* Subroutine */ 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 /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *, 
00045             integer *, doublereal *, integer *);
00046     logical upper;
00047     extern /* Subroutine */ 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 /* 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 /*  DLATRS solves one of the triangular systems */
00072 
00073 /*     A *x = s*b  or  A'*x = s*b */
00074 
00075 /*  with scaling to prevent overflow.  Here A is an upper or lower */
00076 /*  triangular matrix, A' denotes the transpose of A, x and b are */
00077 /*  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 DTRSV 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 /*  A       (input) DOUBLE PRECISION array, dimension (LDA,N) */
00113 /*          The triangular matrix A.  If UPLO = 'U', the leading n by n */
00114 /*          upper triangular part of the array A contains the upper */
00115 /*          triangular matrix, and the strictly lower triangular part of */
00116 /*          A is not referenced.  If UPLO = 'L', the leading n by n lower */
00117 /*          triangular part of the array A contains the lower triangular */
00118 /*          matrix, and the strictly upper triangular part of A is not */
00119 /*          referenced.  If DIAG = 'U', the diagonal elements of A are */
00120 /*          also not referenced and are assumed to be 1. */
00121 
00122 /*  LDA     (input) INTEGER */
00123 /*          The leading dimension of the array A.  LDA >= max (1,N). */
00124 
00125 /*  X       (input/output) DOUBLE PRECISION array, dimension (N) */
00126 /*          On entry, the right hand side b of the triangular system. */
00127 /*          On exit, X is overwritten by the solution vector x. */
00128 
00129 /*  SCALE   (output) DOUBLE PRECISION */
00130 /*          The scaling factor s for the triangular system */
00131 /*             A * x = s*b  or  A'* x = s*b. */
00132 /*          If SCALE = 0, the matrix A is singular or badly scaled, and */
00133 /*          the vector x is an exact or approximate solution to A*x = 0. */
00134 
00135 /*  CNORM   (input or output) DOUBLE PRECISION array, dimension (N) */
00136 
00137 /*          If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
00138 /*          contains the norm of the off-diagonal part of the j-th column */
00139 /*          of A.  If TRANS = 'N', CNORM(j) must be greater than or equal */
00140 /*          to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
00141 /*          must be greater than or equal to the 1-norm. */
00142 
00143 /*          If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
00144 /*          returns the 1-norm of the offdiagonal part of the j-th column */
00145 /*          of A. */
00146 
00147 /*  INFO    (output) INTEGER */
00148 /*          = 0:  successful exit */
00149 /*          < 0:  if INFO = -k, the k-th argument had an illegal value */
00150 
00151 /*  Further Details */
00152 /*  ======= ======= */
00153 
00154 /*  A rough bound on x is computed; if that is less than overflow, DTRSV */
00155 /*  is called, otherwise, specific code is used which checks for possible */
00156 /*  overflow or divide-by-zero at every operation. */
00157 
00158 /*  A columnwise scheme is used for solving A*x = b.  The basic algorithm */
00159 /*  if A is lower triangular is */
00160 
00161 /*       x[1:n] := b[1:n] */
00162 /*       for j = 1, ..., n */
00163 /*            x(j) := x(j) / A(j,j) */
00164 /*            x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
00165 /*       end */
00166 
00167 /*  Define bounds on the components of x after j iterations of the loop: */
00168 /*     M(j) = bound on x[1:j] */
00169 /*     G(j) = bound on x[j+1:n] */
00170 /*  Initially, let M(0) = 0 and G(0) = max{x(i), i=1,...,n}. */
00171 
00172 /*  Then for iteration j+1 we have */
00173 /*     M(j+1) <= G(j) / | A(j+1,j+1) | */
00174 /*     G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
00175 /*            <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
00176 
00177 /*  where CNORM(j+1) is greater than or equal to the infinity-norm of */
00178 /*  column j+1 of A, not counting the diagonal.  Hence */
00179 
00180 /*     G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
00181 /*                  1<=i<=j */
00182 /*  and */
00183 
00184 /*     |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
00185 /*                                   1<=i< j */
00186 
00187 /*  Since |x(j)| <= M(j), we use the Level 2 BLAS routine DTRSV if the */
00188 /*  reciprocal of the largest M(j), j=1,..,n, is larger than */
00189 /*  max(underflow, 1/overflow). */
00190 
00191 /*  The bound on x(j) is also used to determine when a step in the */
00192 /*  columnwise method can be performed without fear of overflow.  If */
00193 /*  the computed bound is greater than a large constant, x is scaled to */
00194 /*  prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
00195 /*  1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
00196 
00197 /*  Similarly, a row-wise scheme is used to solve A'*x = b.  The basic */
00198 /*  algorithm for A upper triangular is */
00199 
00200 /*       for j = 1, ..., n */
00201 /*            x(j) := ( b(j) - A[1:j-1,j]' * x[1:j-1] ) / A(j,j) */
00202 /*       end */
00203 
00204 /*  We simultaneously compute two bounds */
00205 /*       G(j) = bound on ( b(i) - A[1:i-1,i]' * x[1:i-1] ), 1<=i<=j */
00206 /*       M(j) = bound on x(i), 1<=i<=j */
00207 
00208 /*  The initial values are G(0) = 0, M(0) = max{b(i), i=1,..,n}, and we */
00209 /*  add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
00210 /*  Then the bound on x(j) is */
00211 
00212 /*       M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
00213 
00214 /*            <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
00215 /*                      1<=i<=j */
00216 
00217 /*  and we can safely call DTRSV if 1/M(n) and 1/G(n) are both greater */
00218 /*  than max(underflow, 1/overflow). */
00219 
00220 /*  ===================================================================== */
00221 
00222 /*     .. Parameters .. */
00223 /*     .. */
00224 /*     .. Local Scalars .. */
00225 /*     .. */
00226 /*     .. External Functions .. */
00227 /*     .. */
00228 /*     .. External Subroutines .. */
00229 /*     .. */
00230 /*     .. Intrinsic Functions .. */
00231 /*     .. */
00232 /*     .. Executable Statements .. */
00233 
00234     /* Parameter adjustments */
00235     a_dim1 = *lda;
00236     a_offset = 1 + a_dim1;
00237     a -= a_offset;
00238     --x;
00239     --cnorm;
00240 
00241     /* Function Body */
00242     *info = 0;
00243     upper = lsame_(uplo, "U");
00244     notran = lsame_(trans, "N");
00245     nounit = lsame_(diag, "N");
00246 
00247 /*     Test the input parameters. */
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 /*     Quick return if possible */
00271 
00272     if (*n == 0) {
00273         return 0;
00274     }
00275 
00276 /*     Determine machine dependent parameters to control overflow. */
00277 
00278     smlnum = dlamch_("Safe minimum") / dlamch_("Precision");
00279     bignum = 1. / smlnum;
00280     *scale = 1.;
00281 
00282     if (lsame_(normin, "N")) {
00283 
00284 /*        Compute the 1-norm of each column, not including the diagonal. */
00285 
00286         if (upper) {
00287 
00288 /*           A is upper triangular. */
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 /* L10: */
00295             }
00296         } else {
00297 
00298 /*           A is lower triangular. */
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 /* L20: */
00305             }
00306             cnorm[*n] = 0.;
00307         }
00308     }
00309 
00310 /*     Scale the column norms by TSCAL if the maximum element in CNORM is */
00311 /*     greater than BIGNUM. */
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 /*     Compute a bound on the computed solution vector to see if the */
00323 /*     Level 2 BLAS routine DTRSV can be used. */
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 /*        Compute the growth in A * x = b. */
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 /*           A is non-unit triangular. */
00350 
00351 /*           Compute GROW = 1/G(j) and XBND = 1/M(j). */
00352 /*           Initially, G(0) = max{x(i), i=1,...,n}. */
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 /*              Exit the loop if the growth factor is too small. */
00361 
00362                 if (grow <= smlnum) {
00363                     goto L50;
00364                 }
00365 
00366 /*              M(j) = G(j-1) / abs(A(j,j)) */
00367 
00368                 tjj = (d__1 = a[j + j * a_dim1], abs(d__1));
00369 /* Computing MIN */
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 /*                 G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
00375 
00376                     grow *= tjj / (tjj + cnorm[j]);
00377                 } else {
00378 
00379 /*                 G(j) could overflow, set GROW to 0. */
00380 
00381                     grow = 0.;
00382                 }
00383 /* L30: */
00384             }
00385             grow = xbnd;
00386         } else {
00387 
00388 /*           A is unit triangular. */
00389 
00390 /*           Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */
00391 
00392 /* Computing MIN */
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 /*              Exit the loop if the growth factor is too small. */
00400 
00401                 if (grow <= smlnum) {
00402                     goto L50;
00403                 }
00404 
00405 /*              G(j) = G(j-1)*( 1 + CNORM(j) ) */
00406 
00407                 grow *= 1. / (cnorm[j] + 1.);
00408 /* L40: */
00409             }
00410         }
00411 L50:
00412 
00413         ;
00414     } else {
00415 
00416 /*        Compute the growth in A' * x = b. */
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 /*           A is non-unit triangular. */
00436 
00437 /*           Compute GROW = 1/G(j) and XBND = 1/M(j). */
00438 /*           Initially, M(0) = max{x(i), i=1,...,n}. */
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 /*              Exit the loop if the growth factor is too small. */
00447 
00448                 if (grow <= smlnum) {
00449                     goto L80;
00450                 }
00451 
00452 /*              G(j) = max( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
00453 
00454                 xj = cnorm[j] + 1.;
00455 /* Computing MIN */
00456                 d__1 = grow, d__2 = xbnd / xj;
00457                 grow = min(d__1,d__2);
00458 
00459 /*              M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
00460 
00461                 tjj = (d__1 = a[j + j * a_dim1], abs(d__1));
00462                 if (xj > tjj) {
00463                     xbnd *= tjj / xj;
00464                 }
00465 /* L60: */
00466             }
00467             grow = min(grow,xbnd);
00468         } else {
00469 
00470 /*           A is unit triangular. */
00471 
00472 /*           Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */
00473 
00474 /* Computing MIN */
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 /*              Exit the loop if the growth factor is too small. */
00482 
00483                 if (grow <= smlnum) {
00484                     goto L80;
00485                 }
00486 
00487 /*              G(j) = ( 1 + CNORM(j) )*G(j-1) */
00488 
00489                 xj = cnorm[j] + 1.;
00490                 grow /= xj;
00491 /* L70: */
00492             }
00493         }
00494 L80:
00495         ;
00496     }
00497 
00498     if (grow * tscal > smlnum) {
00499 
00500 /*        Use the Level 2 BLAS solve if the reciprocal of the bound on */
00501 /*        elements of X is not too small. */
00502 
00503         dtrsv_(uplo, trans, diag, n, &a[a_offset], lda, &x[1], &c__1);
00504     } else {
00505 
00506 /*        Use a Level 1 BLAS solve, scaling intermediate results. */
00507 
00508         if (xmax > bignum) {
00509 
00510 /*           Scale X so that its components are less than or equal to */
00511 /*           BIGNUM in absolute value. */
00512 
00513             *scale = bignum / xmax;
00514             dscal_(n, scale, &x[1], &c__1);
00515             xmax = bignum;
00516         }
00517 
00518         if (notran) {
00519 
00520 /*           Solve A * x = b */
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 /*              Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
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 /*                    abs(A(j,j)) > SMLNUM: */
00541 
00542                     if (tjj < 1.) {
00543                         if (xj > tjj * bignum) {
00544 
00545 /*                          Scale x by 1/b(j). */
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 /*                    0 < abs(A(j,j)) <= SMLNUM: */
00558 
00559                     if (xj > tjj * bignum) {
00560 
00561 /*                       Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
00562 /*                       to avoid overflow when dividing by A(j,j). */
00563 
00564                         rec = tjj * bignum / xj;
00565                         if (cnorm[j] > 1.) {
00566 
00567 /*                          Scale by 1/CNORM(j) to avoid overflow when */
00568 /*                          multiplying x(j) times column j. */
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 /*                    A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
00581 /*                    scale = 0, and compute a solution to A*x = 0. */
00582 
00583                     i__3 = *n;
00584                     for (i__ = 1; i__ <= i__3; ++i__) {
00585                         x[i__] = 0.;
00586 /* L90: */
00587                     }
00588                     x[j] = 1.;
00589                     xj = 1.;
00590                     *scale = 0.;
00591                     xmax = 0.;
00592                 }
00593 L100:
00594 
00595 /*              Scale x if necessary to avoid overflow when adding a */
00596 /*              multiple of column j of A. */
00597 
00598                 if (xj > 1.) {
00599                     rec = 1. / xj;
00600                     if (cnorm[j] > (bignum - xmax) * rec) {
00601 
00602 /*                    Scale x by 1/(2*abs(x(j))). */
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 /*                 Scale x by 1/2. */
00611 
00612                     dscal_(n, &c_b36, &x[1], &c__1);
00613                     *scale *= .5;
00614                 }
00615 
00616                 if (upper) {
00617                     if (j > 1) {
00618 
00619 /*                    Compute the update */
00620 /*                       x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j) */
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 /*                    Compute the update */
00634 /*                       x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j) */
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 /* L110: */
00646             }
00647 
00648         } else {
00649 
00650 /*           Solve A' * x = b */
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 /*              Compute x(j) = b(j) - sum A(k,j)*x(k). */
00657 /*                                    k<>j */
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 /*                 If x(j) could overflow, scale x by 1/(2*XMAX). */
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 /*                       Divide by A(j,j) when scaling x if A(j,j) > 1. */
00676 
00677 /* Computing MIN */
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 /*                 If the scaling needed for A in the dot product is 1, */
00693 /*                 call DDOT to perform the dot product. */
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 /*                 Otherwise, use in-line code for the dot product. */
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 /* L120: */
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 /* L130: */
00719                         }
00720                     }
00721                 }
00722 
00723                 if (uscal == tscal) {
00724 
00725 /*                 Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */
00726 /*                 was not used to scale the dotproduct. */
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 /*                    Compute x(j) = x(j) / A(j,j), scaling if necessary. */
00740 
00741                     tjj = abs(tjjs);
00742                     if (tjj > smlnum) {
00743 
00744 /*                       abs(A(j,j)) > SMLNUM: */
00745 
00746                         if (tjj < 1.) {
00747                             if (xj > tjj * bignum) {
00748 
00749 /*                             Scale X by 1/abs(x(j)). */
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 /*                       0 < abs(A(j,j)) <= SMLNUM: */
00761 
00762                         if (xj > tjj * bignum) {
00763 
00764 /*                          Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
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 /*                       A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
00775 /*                       scale = 0, and compute a solution to A'*x = 0. */
00776 
00777                         i__3 = *n;
00778                         for (i__ = 1; i__ <= i__3; ++i__) {
00779                             x[i__] = 0.;
00780 /* L140: */
00781                         }
00782                         x[j] = 1.;
00783                         *scale = 0.;
00784                         xmax = 0.;
00785                     }
00786 L150:
00787                     ;
00788                 } else {
00789 
00790 /*                 Compute x(j) := x(j) / A(j,j)  - sumj if the dot */
00791 /*                 product has already been divided by 1/A(j,j). */
00792 
00793                     x[j] = x[j] / tjjs - sumj;
00794                 }
00795 /* Computing MAX */
00796                 d__2 = xmax, d__3 = (d__1 = x[j], abs(d__1));
00797                 xmax = max(d__2,d__3);
00798 /* L160: */
00799             }
00800         }
00801         *scale /= tscal;
00802     }
00803 
00804 /*     Scale the column norms by 1/TSCAL for return. */
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 /*     End of DLATRS */
00814 
00815 } /* dlatrs_ */


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