dlatps.c
Go to the documentation of this file.
00001 /* dlatps.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 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     /* System generated locals */
00026     integer i__1, i__2, i__3;
00027     doublereal d__1, d__2, d__3;
00028 
00029     /* Local variables */
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 /* 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 dtpsv_(char *, char *, char *, integer *, 
00048             doublereal *, 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 /*  DLATPS 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 matrix stored in packed form.  Here A' denotes the */
00077 /*  transpose of A, x and b are n-element vectors, and s is a scaling */
00078 /*  factor, usually less than or equal to 1, chosen so that the */
00079 /*  components of x will be less than the overflow threshold.  If the */
00080 /*  unscaled problem will not cause overflow, the Level 2 BLAS routine */
00081 /*  DTPSV is called. If the matrix A is singular (A(j,j) = 0 for some j), */
00082 /*  then s is set to 0 and a 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 /*  AP      (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
00113 /*          The upper or lower triangular matrix A, packed columnwise in */
00114 /*          a linear array.  The j-th column of A is stored in the array */
00115 /*          AP as follows: */
00116 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00117 /*          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
00118 
00119 /*  X       (input/output) DOUBLE PRECISION array, dimension (N) */
00120 /*          On entry, the right hand side b of the triangular system. */
00121 /*          On exit, X is overwritten by the solution vector x. */
00122 
00123 /*  SCALE   (output) DOUBLE PRECISION */
00124 /*          The scaling factor s for the triangular system */
00125 /*             A * x = s*b  or  A'* x = s*b. */
00126 /*          If SCALE = 0, the matrix A is singular or badly scaled, and */
00127 /*          the vector x is an exact or approximate solution to A*x = 0. */
00128 
00129 /*  CNORM   (input or output) DOUBLE PRECISION array, dimension (N) */
00130 
00131 /*          If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
00132 /*          contains the norm of the off-diagonal part of the j-th column */
00133 /*          of A.  If TRANS = 'N', CNORM(j) must be greater than or equal */
00134 /*          to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
00135 /*          must be greater than or equal to the 1-norm. */
00136 
00137 /*          If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
00138 /*          returns the 1-norm of the offdiagonal part of the j-th column */
00139 /*          of A. */
00140 
00141 /*  INFO    (output) INTEGER */
00142 /*          = 0:  successful exit */
00143 /*          < 0:  if INFO = -k, the k-th argument had an illegal value */
00144 
00145 /*  Further Details */
00146 /*  ======= ======= */
00147 
00148 /*  A rough bound on x is computed; if that is less than overflow, DTPSV */
00149 /*  is called, otherwise, specific code is used which checks for possible */
00150 /*  overflow or divide-by-zero at every operation. */
00151 
00152 /*  A columnwise scheme is used for solving A*x = b.  The basic algorithm */
00153 /*  if A is lower triangular is */
00154 
00155 /*       x[1:n] := b[1:n] */
00156 /*       for j = 1, ..., n */
00157 /*            x(j) := x(j) / A(j,j) */
00158 /*            x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
00159 /*       end */
00160 
00161 /*  Define bounds on the components of x after j iterations of the loop: */
00162 /*     M(j) = bound on x[1:j] */
00163 /*     G(j) = bound on x[j+1:n] */
00164 /*  Initially, let M(0) = 0 and G(0) = max{x(i), i=1,...,n}. */
00165 
00166 /*  Then for iteration j+1 we have */
00167 /*     M(j+1) <= G(j) / | A(j+1,j+1) | */
00168 /*     G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
00169 /*            <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
00170 
00171 /*  where CNORM(j+1) is greater than or equal to the infinity-norm of */
00172 /*  column j+1 of A, not counting the diagonal.  Hence */
00173 
00174 /*     G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
00175 /*                  1<=i<=j */
00176 /*  and */
00177 
00178 /*     |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
00179 /*                                   1<=i< j */
00180 
00181 /*  Since |x(j)| <= M(j), we use the Level 2 BLAS routine DTPSV if the */
00182 /*  reciprocal of the largest M(j), j=1,..,n, is larger than */
00183 /*  max(underflow, 1/overflow). */
00184 
00185 /*  The bound on x(j) is also used to determine when a step in the */
00186 /*  columnwise method can be performed without fear of overflow.  If */
00187 /*  the computed bound is greater than a large constant, x is scaled to */
00188 /*  prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
00189 /*  1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
00190 
00191 /*  Similarly, a row-wise scheme is used to solve A'*x = b.  The basic */
00192 /*  algorithm for A upper triangular is */
00193 
00194 /*       for j = 1, ..., n */
00195 /*            x(j) := ( b(j) - A[1:j-1,j]' * x[1:j-1] ) / A(j,j) */
00196 /*       end */
00197 
00198 /*  We simultaneously compute two bounds */
00199 /*       G(j) = bound on ( b(i) - A[1:i-1,i]' * x[1:i-1] ), 1<=i<=j */
00200 /*       M(j) = bound on x(i), 1<=i<=j */
00201 
00202 /*  The initial values are G(0) = 0, M(0) = max{b(i), i=1,..,n}, and we */
00203 /*  add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
00204 /*  Then the bound on x(j) is */
00205 
00206 /*       M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
00207 
00208 /*            <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
00209 /*                      1<=i<=j */
00210 
00211 /*  and we can safely call DTPSV if 1/M(n) and 1/G(n) are both greater */
00212 /*  than max(underflow, 1/overflow). */
00213 
00214 /*  ===================================================================== */
00215 
00216 /*     .. Parameters .. */
00217 /*     .. */
00218 /*     .. Local Scalars .. */
00219 /*     .. */
00220 /*     .. External Functions .. */
00221 /*     .. */
00222 /*     .. External Subroutines .. */
00223 /*     .. */
00224 /*     .. Intrinsic Functions .. */
00225 /*     .. */
00226 /*     .. Executable Statements .. */
00227 
00228     /* Parameter adjustments */
00229     --cnorm;
00230     --x;
00231     --ap;
00232 
00233     /* Function Body */
00234     *info = 0;
00235     upper = lsame_(uplo, "U");
00236     notran = lsame_(trans, "N");
00237     nounit = lsame_(diag, "N");
00238 
00239 /*     Test the input parameters. */
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 /*     Quick return if possible */
00261 
00262     if (*n == 0) {
00263         return 0;
00264     }
00265 
00266 /*     Determine machine dependent parameters to control overflow. */
00267 
00268     smlnum = dlamch_("Safe minimum") / dlamch_("Precision");
00269     bignum = 1. / smlnum;
00270     *scale = 1.;
00271 
00272     if (lsame_(normin, "N")) {
00273 
00274 /*        Compute the 1-norm of each column, not including the diagonal. */
00275 
00276         if (upper) {
00277 
00278 /*           A is upper triangular. */
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 /* L10: */
00287             }
00288         } else {
00289 
00290 /*           A is lower triangular. */
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 /* L20: */
00299             }
00300             cnorm[*n] = 0.;
00301         }
00302     }
00303 
00304 /*     Scale the column norms by TSCAL if the maximum element in CNORM is */
00305 /*     greater than BIGNUM. */
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 /*     Compute a bound on the computed solution vector to see if the */
00317 /*     Level 2 BLAS routine DTPSV can be used. */
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 /*        Compute the growth in A * x = b. */
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 /*           A is non-unit triangular. */
00344 
00345 /*           Compute GROW = 1/G(j) and XBND = 1/M(j). */
00346 /*           Initially, G(0) = max{x(i), i=1,...,n}. */
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 /*              Exit the loop if the growth factor is too small. */
00357 
00358                 if (grow <= smlnum) {
00359                     goto L50;
00360                 }
00361 
00362 /*              M(j) = G(j-1) / abs(A(j,j)) */
00363 
00364                 tjj = (d__1 = ap[ip], abs(d__1));
00365 /* Computing MIN */
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 /*                 G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
00371 
00372                     grow *= tjj / (tjj + cnorm[j]);
00373                 } else {
00374 
00375 /*                 G(j) could overflow, set GROW to 0. */
00376 
00377                     grow = 0.;
00378                 }
00379                 ip += jinc * jlen;
00380                 --jlen;
00381 /* L30: */
00382             }
00383             grow = xbnd;
00384         } else {
00385 
00386 /*           A is unit triangular. */
00387 
00388 /*           Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */
00389 
00390 /* Computing MIN */
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 /*              Exit the loop if the growth factor is too small. */
00398 
00399                 if (grow <= smlnum) {
00400                     goto L50;
00401                 }
00402 
00403 /*              G(j) = G(j-1)*( 1 + CNORM(j) ) */
00404 
00405                 grow *= 1. / (cnorm[j] + 1.);
00406 /* L40: */
00407             }
00408         }
00409 L50:
00410 
00411         ;
00412     } else {
00413 
00414 /*        Compute the growth in A' * x = b. */
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 /*           A is non-unit triangular. */
00434 
00435 /*           Compute GROW = 1/G(j) and XBND = 1/M(j). */
00436 /*           Initially, M(0) = max{x(i), i=1,...,n}. */
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 /*              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 = ap[ip], abs(d__1));
00462                 if (xj > tjj) {
00463                     xbnd *= tjj / xj;
00464                 }
00465                 ++jlen;
00466                 ip += jinc * jlen;
00467 /* L60: */
00468             }
00469             grow = min(grow,xbnd);
00470         } else {
00471 
00472 /*           A is unit triangular. */
00473 
00474 /*           Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */
00475 
00476 /* Computing MIN */
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 /*              Exit the loop if the growth factor is too small. */
00484 
00485                 if (grow <= smlnum) {
00486                     goto L80;
00487                 }
00488 
00489 /*              G(j) = ( 1 + CNORM(j) )*G(j-1) */
00490 
00491                 xj = cnorm[j] + 1.;
00492                 grow /= xj;
00493 /* L70: */
00494             }
00495         }
00496 L80:
00497         ;
00498     }
00499 
00500     if (grow * tscal > smlnum) {
00501 
00502 /*        Use the Level 2 BLAS solve if the reciprocal of the bound on */
00503 /*        elements of X is not too small. */
00504 
00505         dtpsv_(uplo, trans, diag, n, &ap[1], &x[1], &c__1);
00506     } else {
00507 
00508 /*        Use a Level 1 BLAS solve, scaling intermediate results. */
00509 
00510         if (xmax > bignum) {
00511 
00512 /*           Scale X so that its components are less than or equal to */
00513 /*           BIGNUM in absolute value. */
00514 
00515             *scale = bignum / xmax;
00516             dscal_(n, scale, &x[1], &c__1);
00517             xmax = bignum;
00518         }
00519 
00520         if (notran) {
00521 
00522 /*           Solve A * x = b */
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 /*              Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
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 /*                    abs(A(j,j)) > SMLNUM: */
00544 
00545                     if (tjj < 1.) {
00546                         if (xj > tjj * bignum) {
00547 
00548 /*                          Scale x by 1/b(j). */
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 /*                    0 < abs(A(j,j)) <= SMLNUM: */
00561 
00562                     if (xj > tjj * bignum) {
00563 
00564 /*                       Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
00565 /*                       to avoid overflow when dividing by A(j,j). */
00566 
00567                         rec = tjj * bignum / xj;
00568                         if (cnorm[j] > 1.) {
00569 
00570 /*                          Scale by 1/CNORM(j) to avoid overflow when */
00571 /*                          multiplying x(j) times column j. */
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 /*                    A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
00584 /*                    scale = 0, and compute a solution to A*x = 0. */
00585 
00586                     i__3 = *n;
00587                     for (i__ = 1; i__ <= i__3; ++i__) {
00588                         x[i__] = 0.;
00589 /* L90: */
00590                     }
00591                     x[j] = 1.;
00592                     xj = 1.;
00593                     *scale = 0.;
00594                     xmax = 0.;
00595                 }
00596 L100:
00597 
00598 /*              Scale x if necessary to avoid overflow when adding a */
00599 /*              multiple of column j of A. */
00600 
00601                 if (xj > 1.) {
00602                     rec = 1. / xj;
00603                     if (cnorm[j] > (bignum - xmax) * rec) {
00604 
00605 /*                    Scale x by 1/(2*abs(x(j))). */
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 /*                 Scale x by 1/2. */
00614 
00615                     dscal_(n, &c_b36, &x[1], &c__1);
00616                     *scale *= .5;
00617                 }
00618 
00619                 if (upper) {
00620                     if (j > 1) {
00621 
00622 /*                    Compute the update */
00623 /*                       x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j) */
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 /*                    Compute the update */
00638 /*                       x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j) */
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 /* L110: */
00651             }
00652 
00653         } else {
00654 
00655 /*           Solve A' * x = b */
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 /*              Compute x(j) = b(j) - sum A(k,j)*x(k). */
00664 /*                                    k<>j */
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 /*                 If x(j) could overflow, scale x by 1/(2*XMAX). */
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 /*                       Divide by A(j,j) when scaling x if A(j,j) > 1. */
00683 
00684 /* Computing MIN */
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 /*                 If the scaling needed for A in the dot product is 1, */
00700 /*                 call DDOT to perform the dot product. */
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 /*                 Otherwise, use in-line code for the dot product. */
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 /* L120: */
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 /* L130: */
00726                         }
00727                     }
00728                 }
00729 
00730                 if (uscal == tscal) {
00731 
00732 /*                 Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */
00733 /*                 was not used to scale the dotproduct. */
00734 
00735                     x[j] -= sumj;
00736                     xj = (d__1 = x[j], abs(d__1));
00737                     if (nounit) {
00738 
00739 /*                    Compute x(j) = x(j) / A(j,j), scaling if necessary. */
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 /*                       abs(A(j,j)) > SMLNUM: */
00752 
00753                         if (tjj < 1.) {
00754                             if (xj > tjj * bignum) {
00755 
00756 /*                             Scale X by 1/abs(x(j)). */
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 /*                       0 < abs(A(j,j)) <= SMLNUM: */
00768 
00769                         if (xj > tjj * bignum) {
00770 
00771 /*                          Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
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 /*                       A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
00782 /*                       scale = 0, and compute a solution to A'*x = 0. */
00783 
00784                         i__3 = *n;
00785                         for (i__ = 1; i__ <= i__3; ++i__) {
00786                             x[i__] = 0.;
00787 /* L140: */
00788                         }
00789                         x[j] = 1.;
00790                         *scale = 0.;
00791                         xmax = 0.;
00792                     }
00793 L150:
00794                     ;
00795                 } else {
00796 
00797 /*                 Compute x(j) := x(j) / A(j,j)  - sumj if the dot */
00798 /*                 product has already been divided by 1/A(j,j). */
00799 
00800                     x[j] = x[j] / tjjs - sumj;
00801                 }
00802 /* Computing MAX */
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 /* L160: */
00808             }
00809         }
00810         *scale /= tscal;
00811     }
00812 
00813 /*     Scale the column norms by 1/TSCAL for return. */
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 /*     End of DLATPS */
00823 
00824 } /* dlatps_ */


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