zlatps.c
Go to the documentation of this file.
00001 /* zlatps.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 zlatps_(char *uplo, char *trans, char *diag, char *
00022         normin, integer *n, doublecomplex *ap, doublecomplex *x, doublereal *
00023         scale, doublereal *cnorm, integer *info)
00024 {
00025     /* System generated locals */
00026     integer i__1, i__2, i__3, i__4, i__5;
00027     doublereal d__1, d__2, d__3, d__4;
00028     doublecomplex z__1, z__2, z__3, z__4;
00029 
00030     /* Builtin functions */
00031     double d_imag(doublecomplex *);
00032     void d_cnjg(doublecomplex *, doublecomplex *);
00033 
00034     /* Local variables */
00035     integer i__, j, ip;
00036     doublereal xj, rec, tjj;
00037     integer jinc, jlen;
00038     doublereal xbnd;
00039     integer imax;
00040     doublereal tmax;
00041     doublecomplex tjjs;
00042     doublereal xmax, grow;
00043     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00044             integer *);
00045     extern logical lsame_(char *, char *);
00046     doublereal tscal;
00047     doublecomplex uscal;
00048     integer jlast;
00049     doublecomplex csumj;
00050     extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *, 
00051             doublecomplex *, integer *, doublecomplex *, integer *);
00052     logical upper;
00053     extern /* Double Complex */ VOID zdotu_(doublecomplex *, integer *, 
00054             doublecomplex *, integer *, doublecomplex *, integer *);
00055     extern /* Subroutine */ int zaxpy_(integer *, doublecomplex *, 
00056             doublecomplex *, integer *, doublecomplex *, integer *), ztpsv_(
00057             char *, char *, char *, integer *, doublecomplex *, doublecomplex 
00058             *, integer *), dlabad_(doublereal *, 
00059             doublereal *);
00060     extern doublereal dlamch_(char *);
00061     extern integer idamax_(integer *, doublereal *, integer *);
00062     extern /* Subroutine */ int xerbla_(char *, integer *), zdscal_(
00063             integer *, doublereal *, doublecomplex *, integer *);
00064     doublereal bignum;
00065     extern integer izamax_(integer *, doublecomplex *, integer *);
00066     extern /* Double Complex */ VOID zladiv_(doublecomplex *, doublecomplex *, 
00067              doublecomplex *);
00068     logical notran;
00069     integer jfirst;
00070     extern doublereal dzasum_(integer *, doublecomplex *, integer *);
00071     doublereal smlnum;
00072     logical nounit;
00073 
00074 
00075 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00076 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00077 /*     November 2006 */
00078 
00079 /*     .. Scalar Arguments .. */
00080 /*     .. */
00081 /*     .. Array Arguments .. */
00082 /*     .. */
00083 
00084 /*  Purpose */
00085 /*  ======= */
00086 
00087 /*  ZLATPS solves one of the triangular systems */
00088 
00089 /*     A * x = s*b,  A**T * x = s*b,  or  A**H * x = s*b, */
00090 
00091 /*  with scaling to prevent overflow, where A is an upper or lower */
00092 /*  triangular matrix stored in packed form.  Here A**T denotes the */
00093 /*  transpose of A, A**H denotes the conjugate transpose of A, x and b */
00094 /*  are n-element vectors, and s is a scaling factor, usually less than */
00095 /*  or equal to 1, chosen so that the components of x will be less than */
00096 /*  the overflow threshold.  If the unscaled problem will not cause */
00097 /*  overflow, the Level 2 BLAS routine ZTPSV is called. If the matrix A */
00098 /*  is singular (A(j,j) = 0 for some j), then s is set to 0 and a */
00099 /*  non-trivial solution to A*x = 0 is returned. */
00100 
00101 /*  Arguments */
00102 /*  ========= */
00103 
00104 /*  UPLO    (input) CHARACTER*1 */
00105 /*          Specifies whether the matrix A is upper or lower triangular. */
00106 /*          = 'U':  Upper triangular */
00107 /*          = 'L':  Lower triangular */
00108 
00109 /*  TRANS   (input) CHARACTER*1 */
00110 /*          Specifies the operation applied to A. */
00111 /*          = 'N':  Solve A * x = s*b     (No transpose) */
00112 /*          = 'T':  Solve A**T * x = s*b  (Transpose) */
00113 /*          = 'C':  Solve A**H * x = s*b  (Conjugate transpose) */
00114 
00115 /*  DIAG    (input) CHARACTER*1 */
00116 /*          Specifies whether or not the matrix A is unit triangular. */
00117 /*          = 'N':  Non-unit triangular */
00118 /*          = 'U':  Unit triangular */
00119 
00120 /*  NORMIN  (input) CHARACTER*1 */
00121 /*          Specifies whether CNORM has been set or not. */
00122 /*          = 'Y':  CNORM contains the column norms on entry */
00123 /*          = 'N':  CNORM is not set on entry.  On exit, the norms will */
00124 /*                  be computed and stored in CNORM. */
00125 
00126 /*  N       (input) INTEGER */
00127 /*          The order of the matrix A.  N >= 0. */
00128 
00129 /*  AP      (input) COMPLEX*16 array, dimension (N*(N+1)/2) */
00130 /*          The upper or lower triangular matrix A, packed columnwise in */
00131 /*          a linear array.  The j-th column of A is stored in the array */
00132 /*          AP as follows: */
00133 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00134 /*          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
00135 
00136 /*  X       (input/output) COMPLEX*16 array, dimension (N) */
00137 /*          On entry, the right hand side b of the triangular system. */
00138 /*          On exit, X is overwritten by the solution vector x. */
00139 
00140 /*  SCALE   (output) DOUBLE PRECISION */
00141 /*          The scaling factor s for the triangular system */
00142 /*             A * x = s*b,  A**T * x = s*b,  or  A**H * x = s*b. */
00143 /*          If SCALE = 0, the matrix A is singular or badly scaled, and */
00144 /*          the vector x is an exact or approximate solution to A*x = 0. */
00145 
00146 /*  CNORM   (input or output) DOUBLE PRECISION array, dimension (N) */
00147 
00148 /*          If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
00149 /*          contains the norm of the off-diagonal part of the j-th column */
00150 /*          of A.  If TRANS = 'N', CNORM(j) must be greater than or equal */
00151 /*          to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
00152 /*          must be greater than or equal to the 1-norm. */
00153 
00154 /*          If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
00155 /*          returns the 1-norm of the offdiagonal part of the j-th column */
00156 /*          of A. */
00157 
00158 /*  INFO    (output) INTEGER */
00159 /*          = 0:  successful exit */
00160 /*          < 0:  if INFO = -k, the k-th argument had an illegal value */
00161 
00162 /*  Further Details */
00163 /*  ======= ======= */
00164 
00165 /*  A rough bound on x is computed; if that is less than overflow, ZTPSV */
00166 /*  is called, otherwise, specific code is used which checks for possible */
00167 /*  overflow or divide-by-zero at every operation. */
00168 
00169 /*  A columnwise scheme is used for solving A*x = b.  The basic algorithm */
00170 /*  if A is lower triangular is */
00171 
00172 /*       x[1:n] := b[1:n] */
00173 /*       for j = 1, ..., n */
00174 /*            x(j) := x(j) / A(j,j) */
00175 /*            x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
00176 /*       end */
00177 
00178 /*  Define bounds on the components of x after j iterations of the loop: */
00179 /*     M(j) = bound on x[1:j] */
00180 /*     G(j) = bound on x[j+1:n] */
00181 /*  Initially, let M(0) = 0 and G(0) = max{x(i), i=1,...,n}. */
00182 
00183 /*  Then for iteration j+1 we have */
00184 /*     M(j+1) <= G(j) / | A(j+1,j+1) | */
00185 /*     G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
00186 /*            <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
00187 
00188 /*  where CNORM(j+1) is greater than or equal to the infinity-norm of */
00189 /*  column j+1 of A, not counting the diagonal.  Hence */
00190 
00191 /*     G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
00192 /*                  1<=i<=j */
00193 /*  and */
00194 
00195 /*     |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
00196 /*                                   1<=i< j */
00197 
00198 /*  Since |x(j)| <= M(j), we use the Level 2 BLAS routine ZTPSV if the */
00199 /*  reciprocal of the largest M(j), j=1,..,n, is larger than */
00200 /*  max(underflow, 1/overflow). */
00201 
00202 /*  The bound on x(j) is also used to determine when a step in the */
00203 /*  columnwise method can be performed without fear of overflow.  If */
00204 /*  the computed bound is greater than a large constant, x is scaled to */
00205 /*  prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
00206 /*  1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
00207 
00208 /*  Similarly, a row-wise scheme is used to solve A**T *x = b  or */
00209 /*  A**H *x = b.  The basic algorithm for A upper triangular is */
00210 
00211 /*       for j = 1, ..., n */
00212 /*            x(j) := ( b(j) - A[1:j-1,j]' * x[1:j-1] ) / A(j,j) */
00213 /*       end */
00214 
00215 /*  We simultaneously compute two bounds */
00216 /*       G(j) = bound on ( b(i) - A[1:i-1,i]' * x[1:i-1] ), 1<=i<=j */
00217 /*       M(j) = bound on x(i), 1<=i<=j */
00218 
00219 /*  The initial values are G(0) = 0, M(0) = max{b(i), i=1,..,n}, and we */
00220 /*  add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
00221 /*  Then the bound on x(j) is */
00222 
00223 /*       M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
00224 
00225 /*            <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
00226 /*                      1<=i<=j */
00227 
00228 /*  and we can safely call ZTPSV if 1/M(n) and 1/G(n) are both greater */
00229 /*  than max(underflow, 1/overflow). */
00230 
00231 /*  ===================================================================== */
00232 
00233 /*     .. Parameters .. */
00234 /*     .. */
00235 /*     .. Local Scalars .. */
00236 /*     .. */
00237 /*     .. External Functions .. */
00238 /*     .. */
00239 /*     .. External Subroutines .. */
00240 /*     .. */
00241 /*     .. Intrinsic Functions .. */
00242 /*     .. */
00243 /*     .. Statement Functions .. */
00244 /*     .. */
00245 /*     .. Statement Function definitions .. */
00246 /*     .. */
00247 /*     .. Executable Statements .. */
00248 
00249     /* Parameter adjustments */
00250     --cnorm;
00251     --x;
00252     --ap;
00253 
00254     /* Function Body */
00255     *info = 0;
00256     upper = lsame_(uplo, "U");
00257     notran = lsame_(trans, "N");
00258     nounit = lsame_(diag, "N");
00259 
00260 /*     Test the input parameters. */
00261 
00262     if (! upper && ! lsame_(uplo, "L")) {
00263         *info = -1;
00264     } else if (! notran && ! lsame_(trans, "T") && ! 
00265             lsame_(trans, "C")) {
00266         *info = -2;
00267     } else if (! nounit && ! lsame_(diag, "U")) {
00268         *info = -3;
00269     } else if (! lsame_(normin, "Y") && ! lsame_(normin, 
00270              "N")) {
00271         *info = -4;
00272     } else if (*n < 0) {
00273         *info = -5;
00274     }
00275     if (*info != 0) {
00276         i__1 = -(*info);
00277         xerbla_("ZLATPS", &i__1);
00278         return 0;
00279     }
00280 
00281 /*     Quick return if possible */
00282 
00283     if (*n == 0) {
00284         return 0;
00285     }
00286 
00287 /*     Determine machine dependent parameters to control overflow. */
00288 
00289     smlnum = dlamch_("Safe minimum");
00290     bignum = 1. / smlnum;
00291     dlabad_(&smlnum, &bignum);
00292     smlnum /= dlamch_("Precision");
00293     bignum = 1. / smlnum;
00294     *scale = 1.;
00295 
00296     if (lsame_(normin, "N")) {
00297 
00298 /*        Compute the 1-norm of each column, not including the diagonal. */
00299 
00300         if (upper) {
00301 
00302 /*           A is upper triangular. */
00303 
00304             ip = 1;
00305             i__1 = *n;
00306             for (j = 1; j <= i__1; ++j) {
00307                 i__2 = j - 1;
00308                 cnorm[j] = dzasum_(&i__2, &ap[ip], &c__1);
00309                 ip += j;
00310 /* L10: */
00311             }
00312         } else {
00313 
00314 /*           A is lower triangular. */
00315 
00316             ip = 1;
00317             i__1 = *n - 1;
00318             for (j = 1; j <= i__1; ++j) {
00319                 i__2 = *n - j;
00320                 cnorm[j] = dzasum_(&i__2, &ap[ip + 1], &c__1);
00321                 ip = ip + *n - j + 1;
00322 /* L20: */
00323             }
00324             cnorm[*n] = 0.;
00325         }
00326     }
00327 
00328 /*     Scale the column norms by TSCAL if the maximum element in CNORM is */
00329 /*     greater than BIGNUM/2. */
00330 
00331     imax = idamax_(n, &cnorm[1], &c__1);
00332     tmax = cnorm[imax];
00333     if (tmax <= bignum * .5) {
00334         tscal = 1.;
00335     } else {
00336         tscal = .5 / (smlnum * tmax);
00337         dscal_(n, &tscal, &cnorm[1], &c__1);
00338     }
00339 
00340 /*     Compute a bound on the computed solution vector to see if the */
00341 /*     Level 2 BLAS routine ZTPSV can be used. */
00342 
00343     xmax = 0.;
00344     i__1 = *n;
00345     for (j = 1; j <= i__1; ++j) {
00346 /* Computing MAX */
00347         i__2 = j;
00348         d__3 = xmax, d__4 = (d__1 = x[i__2].r / 2., abs(d__1)) + (d__2 = 
00349                 d_imag(&x[j]) / 2., abs(d__2));
00350         xmax = max(d__3,d__4);
00351 /* L30: */
00352     }
00353     xbnd = xmax;
00354     if (notran) {
00355 
00356 /*        Compute the growth in A * x = b. */
00357 
00358         if (upper) {
00359             jfirst = *n;
00360             jlast = 1;
00361             jinc = -1;
00362         } else {
00363             jfirst = 1;
00364             jlast = *n;
00365             jinc = 1;
00366         }
00367 
00368         if (tscal != 1.) {
00369             grow = 0.;
00370             goto L60;
00371         }
00372 
00373         if (nounit) {
00374 
00375 /*           A is non-unit triangular. */
00376 
00377 /*           Compute GROW = 1/G(j) and XBND = 1/M(j). */
00378 /*           Initially, G(0) = max{x(i), i=1,...,n}. */
00379 
00380             grow = .5 / max(xbnd,smlnum);
00381             xbnd = grow;
00382             ip = jfirst * (jfirst + 1) / 2;
00383             jlen = *n;
00384             i__1 = jlast;
00385             i__2 = jinc;
00386             for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00387 
00388 /*              Exit the loop if the growth factor is too small. */
00389 
00390                 if (grow <= smlnum) {
00391                     goto L60;
00392                 }
00393 
00394                 i__3 = ip;
00395                 tjjs.r = ap[i__3].r, tjjs.i = ap[i__3].i;
00396                 tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), abs(
00397                         d__2));
00398 
00399                 if (tjj >= smlnum) {
00400 
00401 /*                 M(j) = G(j-1) / abs(A(j,j)) */
00402 
00403 /* Computing MIN */
00404                     d__1 = xbnd, d__2 = min(1.,tjj) * grow;
00405                     xbnd = min(d__1,d__2);
00406                 } else {
00407 
00408 /*                 M(j) could overflow, set XBND to 0. */
00409 
00410                     xbnd = 0.;
00411                 }
00412 
00413                 if (tjj + cnorm[j] >= smlnum) {
00414 
00415 /*                 G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
00416 
00417                     grow *= tjj / (tjj + cnorm[j]);
00418                 } else {
00419 
00420 /*                 G(j) could overflow, set GROW to 0. */
00421 
00422                     grow = 0.;
00423                 }
00424                 ip += jinc * jlen;
00425                 --jlen;
00426 /* L40: */
00427             }
00428             grow = xbnd;
00429         } else {
00430 
00431 /*           A is unit triangular. */
00432 
00433 /*           Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */
00434 
00435 /* Computing MIN */
00436             d__1 = 1., d__2 = .5 / max(xbnd,smlnum);
00437             grow = min(d__1,d__2);
00438             i__2 = jlast;
00439             i__1 = jinc;
00440             for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
00441 
00442 /*              Exit the loop if the growth factor is too small. */
00443 
00444                 if (grow <= smlnum) {
00445                     goto L60;
00446                 }
00447 
00448 /*              G(j) = G(j-1)*( 1 + CNORM(j) ) */
00449 
00450                 grow *= 1. / (cnorm[j] + 1.);
00451 /* L50: */
00452             }
00453         }
00454 L60:
00455 
00456         ;
00457     } else {
00458 
00459 /*        Compute the growth in A**T * x = b  or  A**H * x = b. */
00460 
00461         if (upper) {
00462             jfirst = 1;
00463             jlast = *n;
00464             jinc = 1;
00465         } else {
00466             jfirst = *n;
00467             jlast = 1;
00468             jinc = -1;
00469         }
00470 
00471         if (tscal != 1.) {
00472             grow = 0.;
00473             goto L90;
00474         }
00475 
00476         if (nounit) {
00477 
00478 /*           A is non-unit triangular. */
00479 
00480 /*           Compute GROW = 1/G(j) and XBND = 1/M(j). */
00481 /*           Initially, M(0) = max{x(i), i=1,...,n}. */
00482 
00483             grow = .5 / max(xbnd,smlnum);
00484             xbnd = grow;
00485             ip = jfirst * (jfirst + 1) / 2;
00486             jlen = 1;
00487             i__1 = jlast;
00488             i__2 = jinc;
00489             for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00490 
00491 /*              Exit the loop if the growth factor is too small. */
00492 
00493                 if (grow <= smlnum) {
00494                     goto L90;
00495                 }
00496 
00497 /*              G(j) = max( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
00498 
00499                 xj = cnorm[j] + 1.;
00500 /* Computing MIN */
00501                 d__1 = grow, d__2 = xbnd / xj;
00502                 grow = min(d__1,d__2);
00503 
00504                 i__3 = ip;
00505                 tjjs.r = ap[i__3].r, tjjs.i = ap[i__3].i;
00506                 tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), abs(
00507                         d__2));
00508 
00509                 if (tjj >= smlnum) {
00510 
00511 /*                 M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
00512 
00513                     if (xj > tjj) {
00514                         xbnd *= tjj / xj;
00515                     }
00516                 } else {
00517 
00518 /*                 M(j) could overflow, set XBND to 0. */
00519 
00520                     xbnd = 0.;
00521                 }
00522                 ++jlen;
00523                 ip += jinc * jlen;
00524 /* L70: */
00525             }
00526             grow = min(grow,xbnd);
00527         } else {
00528 
00529 /*           A is unit triangular. */
00530 
00531 /*           Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */
00532 
00533 /* Computing MIN */
00534             d__1 = 1., d__2 = .5 / max(xbnd,smlnum);
00535             grow = min(d__1,d__2);
00536             i__2 = jlast;
00537             i__1 = jinc;
00538             for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
00539 
00540 /*              Exit the loop if the growth factor is too small. */
00541 
00542                 if (grow <= smlnum) {
00543                     goto L90;
00544                 }
00545 
00546 /*              G(j) = ( 1 + CNORM(j) )*G(j-1) */
00547 
00548                 xj = cnorm[j] + 1.;
00549                 grow /= xj;
00550 /* L80: */
00551             }
00552         }
00553 L90:
00554         ;
00555     }
00556 
00557     if (grow * tscal > smlnum) {
00558 
00559 /*        Use the Level 2 BLAS solve if the reciprocal of the bound on */
00560 /*        elements of X is not too small. */
00561 
00562         ztpsv_(uplo, trans, diag, n, &ap[1], &x[1], &c__1);
00563     } else {
00564 
00565 /*        Use a Level 1 BLAS solve, scaling intermediate results. */
00566 
00567         if (xmax > bignum * .5) {
00568 
00569 /*           Scale X so that its components are less than or equal to */
00570 /*           BIGNUM in absolute value. */
00571 
00572             *scale = bignum * .5 / xmax;
00573             zdscal_(n, scale, &x[1], &c__1);
00574             xmax = bignum;
00575         } else {
00576             xmax *= 2.;
00577         }
00578 
00579         if (notran) {
00580 
00581 /*           Solve A * x = b */
00582 
00583             ip = jfirst * (jfirst + 1) / 2;
00584             i__1 = jlast;
00585             i__2 = jinc;
00586             for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00587 
00588 /*              Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
00589 
00590                 i__3 = j;
00591                 xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j]), 
00592                         abs(d__2));
00593                 if (nounit) {
00594                     i__3 = ip;
00595                     z__1.r = tscal * ap[i__3].r, z__1.i = tscal * ap[i__3].i;
00596                     tjjs.r = z__1.r, tjjs.i = z__1.i;
00597                 } else {
00598                     tjjs.r = tscal, tjjs.i = 0.;
00599                     if (tscal == 1.) {
00600                         goto L110;
00601                     }
00602                 }
00603                 tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), abs(
00604                         d__2));
00605                 if (tjj > smlnum) {
00606 
00607 /*                    abs(A(j,j)) > SMLNUM: */
00608 
00609                     if (tjj < 1.) {
00610                         if (xj > tjj * bignum) {
00611 
00612 /*                          Scale x by 1/b(j). */
00613 
00614                             rec = 1. / xj;
00615                             zdscal_(n, &rec, &x[1], &c__1);
00616                             *scale *= rec;
00617                             xmax *= rec;
00618                         }
00619                     }
00620                     i__3 = j;
00621                     zladiv_(&z__1, &x[j], &tjjs);
00622                     x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00623                     i__3 = j;
00624                     xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
00625                             , abs(d__2));
00626                 } else if (tjj > 0.) {
00627 
00628 /*                    0 < abs(A(j,j)) <= SMLNUM: */
00629 
00630                     if (xj > tjj * bignum) {
00631 
00632 /*                       Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
00633 /*                       to avoid overflow when dividing by A(j,j). */
00634 
00635                         rec = tjj * bignum / xj;
00636                         if (cnorm[j] > 1.) {
00637 
00638 /*                          Scale by 1/CNORM(j) to avoid overflow when */
00639 /*                          multiplying x(j) times column j. */
00640 
00641                             rec /= cnorm[j];
00642                         }
00643                         zdscal_(n, &rec, &x[1], &c__1);
00644                         *scale *= rec;
00645                         xmax *= rec;
00646                     }
00647                     i__3 = j;
00648                     zladiv_(&z__1, &x[j], &tjjs);
00649                     x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00650                     i__3 = j;
00651                     xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
00652                             , abs(d__2));
00653                 } else {
00654 
00655 /*                    A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
00656 /*                    scale = 0, and compute a solution to A*x = 0. */
00657 
00658                     i__3 = *n;
00659                     for (i__ = 1; i__ <= i__3; ++i__) {
00660                         i__4 = i__;
00661                         x[i__4].r = 0., x[i__4].i = 0.;
00662 /* L100: */
00663                     }
00664                     i__3 = j;
00665                     x[i__3].r = 1., x[i__3].i = 0.;
00666                     xj = 1.;
00667                     *scale = 0.;
00668                     xmax = 0.;
00669                 }
00670 L110:
00671 
00672 /*              Scale x if necessary to avoid overflow when adding a */
00673 /*              multiple of column j of A. */
00674 
00675                 if (xj > 1.) {
00676                     rec = 1. / xj;
00677                     if (cnorm[j] > (bignum - xmax) * rec) {
00678 
00679 /*                    Scale x by 1/(2*abs(x(j))). */
00680 
00681                         rec *= .5;
00682                         zdscal_(n, &rec, &x[1], &c__1);
00683                         *scale *= rec;
00684                     }
00685                 } else if (xj * cnorm[j] > bignum - xmax) {
00686 
00687 /*                 Scale x by 1/2. */
00688 
00689                     zdscal_(n, &c_b36, &x[1], &c__1);
00690                     *scale *= .5;
00691                 }
00692 
00693                 if (upper) {
00694                     if (j > 1) {
00695 
00696 /*                    Compute the update */
00697 /*                       x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j) */
00698 
00699                         i__3 = j - 1;
00700                         i__4 = j;
00701                         z__2.r = -x[i__4].r, z__2.i = -x[i__4].i;
00702                         z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
00703                         zaxpy_(&i__3, &z__1, &ap[ip - j + 1], &c__1, &x[1], &
00704                                 c__1);
00705                         i__3 = j - 1;
00706                         i__ = izamax_(&i__3, &x[1], &c__1);
00707                         i__3 = i__;
00708                         xmax = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(
00709                                 &x[i__]), abs(d__2));
00710                     }
00711                     ip -= j;
00712                 } else {
00713                     if (j < *n) {
00714 
00715 /*                    Compute the update */
00716 /*                       x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j) */
00717 
00718                         i__3 = *n - j;
00719                         i__4 = j;
00720                         z__2.r = -x[i__4].r, z__2.i = -x[i__4].i;
00721                         z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
00722                         zaxpy_(&i__3, &z__1, &ap[ip + 1], &c__1, &x[j + 1], &
00723                                 c__1);
00724                         i__3 = *n - j;
00725                         i__ = j + izamax_(&i__3, &x[j + 1], &c__1);
00726                         i__3 = i__;
00727                         xmax = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(
00728                                 &x[i__]), abs(d__2));
00729                     }
00730                     ip = ip + *n - j + 1;
00731                 }
00732 /* L120: */
00733             }
00734 
00735         } else if (lsame_(trans, "T")) {
00736 
00737 /*           Solve A**T * x = b */
00738 
00739             ip = jfirst * (jfirst + 1) / 2;
00740             jlen = 1;
00741             i__2 = jlast;
00742             i__1 = jinc;
00743             for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
00744 
00745 /*              Compute x(j) = b(j) - sum A(k,j)*x(k). */
00746 /*                                    k<>j */
00747 
00748                 i__3 = j;
00749                 xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j]), 
00750                         abs(d__2));
00751                 uscal.r = tscal, uscal.i = 0.;
00752                 rec = 1. / max(xmax,1.);
00753                 if (cnorm[j] > (bignum - xj) * rec) {
00754 
00755 /*                 If x(j) could overflow, scale x by 1/(2*XMAX). */
00756 
00757                     rec *= .5;
00758                     if (nounit) {
00759                         i__3 = ip;
00760                         z__1.r = tscal * ap[i__3].r, z__1.i = tscal * ap[i__3]
00761                                 .i;
00762                         tjjs.r = z__1.r, tjjs.i = z__1.i;
00763                     } else {
00764                         tjjs.r = tscal, tjjs.i = 0.;
00765                     }
00766                     tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), 
00767                             abs(d__2));
00768                     if (tjj > 1.) {
00769 
00770 /*                       Divide by A(j,j) when scaling x if A(j,j) > 1. */
00771 
00772 /* Computing MIN */
00773                         d__1 = 1., d__2 = rec * tjj;
00774                         rec = min(d__1,d__2);
00775                         zladiv_(&z__1, &uscal, &tjjs);
00776                         uscal.r = z__1.r, uscal.i = z__1.i;
00777                     }
00778                     if (rec < 1.) {
00779                         zdscal_(n, &rec, &x[1], &c__1);
00780                         *scale *= rec;
00781                         xmax *= rec;
00782                     }
00783                 }
00784 
00785                 csumj.r = 0., csumj.i = 0.;
00786                 if (uscal.r == 1. && uscal.i == 0.) {
00787 
00788 /*                 If the scaling needed for A in the dot product is 1, */
00789 /*                 call ZDOTU to perform the dot product. */
00790 
00791                     if (upper) {
00792                         i__3 = j - 1;
00793                         zdotu_(&z__1, &i__3, &ap[ip - j + 1], &c__1, &x[1], &
00794                                 c__1);
00795                         csumj.r = z__1.r, csumj.i = z__1.i;
00796                     } else if (j < *n) {
00797                         i__3 = *n - j;
00798                         zdotu_(&z__1, &i__3, &ap[ip + 1], &c__1, &x[j + 1], &
00799                                 c__1);
00800                         csumj.r = z__1.r, csumj.i = z__1.i;
00801                     }
00802                 } else {
00803 
00804 /*                 Otherwise, use in-line code for the dot product. */
00805 
00806                     if (upper) {
00807                         i__3 = j - 1;
00808                         for (i__ = 1; i__ <= i__3; ++i__) {
00809                             i__4 = ip - j + i__;
00810                             z__3.r = ap[i__4].r * uscal.r - ap[i__4].i * 
00811                                     uscal.i, z__3.i = ap[i__4].r * uscal.i + 
00812                                     ap[i__4].i * uscal.r;
00813                             i__5 = i__;
00814                             z__2.r = z__3.r * x[i__5].r - z__3.i * x[i__5].i, 
00815                                     z__2.i = z__3.r * x[i__5].i + z__3.i * x[
00816                                     i__5].r;
00817                             z__1.r = csumj.r + z__2.r, z__1.i = csumj.i + 
00818                                     z__2.i;
00819                             csumj.r = z__1.r, csumj.i = z__1.i;
00820 /* L130: */
00821                         }
00822                     } else if (j < *n) {
00823                         i__3 = *n - j;
00824                         for (i__ = 1; i__ <= i__3; ++i__) {
00825                             i__4 = ip + i__;
00826                             z__3.r = ap[i__4].r * uscal.r - ap[i__4].i * 
00827                                     uscal.i, z__3.i = ap[i__4].r * uscal.i + 
00828                                     ap[i__4].i * uscal.r;
00829                             i__5 = j + i__;
00830                             z__2.r = z__3.r * x[i__5].r - z__3.i * x[i__5].i, 
00831                                     z__2.i = z__3.r * x[i__5].i + z__3.i * x[
00832                                     i__5].r;
00833                             z__1.r = csumj.r + z__2.r, z__1.i = csumj.i + 
00834                                     z__2.i;
00835                             csumj.r = z__1.r, csumj.i = z__1.i;
00836 /* L140: */
00837                         }
00838                     }
00839                 }
00840 
00841                 z__1.r = tscal, z__1.i = 0.;
00842                 if (uscal.r == z__1.r && uscal.i == z__1.i) {
00843 
00844 /*                 Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j) */
00845 /*                 was not used to scale the dotproduct. */
00846 
00847                     i__3 = j;
00848                     i__4 = j;
00849                     z__1.r = x[i__4].r - csumj.r, z__1.i = x[i__4].i - 
00850                             csumj.i;
00851                     x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00852                     i__3 = j;
00853                     xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
00854                             , abs(d__2));
00855                     if (nounit) {
00856 
00857 /*                    Compute x(j) = x(j) / A(j,j), scaling if necessary. */
00858 
00859                         i__3 = ip;
00860                         z__1.r = tscal * ap[i__3].r, z__1.i = tscal * ap[i__3]
00861                                 .i;
00862                         tjjs.r = z__1.r, tjjs.i = z__1.i;
00863                     } else {
00864                         tjjs.r = tscal, tjjs.i = 0.;
00865                         if (tscal == 1.) {
00866                             goto L160;
00867                         }
00868                     }
00869                     tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), 
00870                             abs(d__2));
00871                     if (tjj > smlnum) {
00872 
00873 /*                       abs(A(j,j)) > SMLNUM: */
00874 
00875                         if (tjj < 1.) {
00876                             if (xj > tjj * bignum) {
00877 
00878 /*                             Scale X by 1/abs(x(j)). */
00879 
00880                                 rec = 1. / xj;
00881                                 zdscal_(n, &rec, &x[1], &c__1);
00882                                 *scale *= rec;
00883                                 xmax *= rec;
00884                             }
00885                         }
00886                         i__3 = j;
00887                         zladiv_(&z__1, &x[j], &tjjs);
00888                         x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00889                     } else if (tjj > 0.) {
00890 
00891 /*                       0 < abs(A(j,j)) <= SMLNUM: */
00892 
00893                         if (xj > tjj * bignum) {
00894 
00895 /*                          Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
00896 
00897                             rec = tjj * bignum / xj;
00898                             zdscal_(n, &rec, &x[1], &c__1);
00899                             *scale *= rec;
00900                             xmax *= rec;
00901                         }
00902                         i__3 = j;
00903                         zladiv_(&z__1, &x[j], &tjjs);
00904                         x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00905                     } else {
00906 
00907 /*                       A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
00908 /*                       scale = 0 and compute a solution to A**T *x = 0. */
00909 
00910                         i__3 = *n;
00911                         for (i__ = 1; i__ <= i__3; ++i__) {
00912                             i__4 = i__;
00913                             x[i__4].r = 0., x[i__4].i = 0.;
00914 /* L150: */
00915                         }
00916                         i__3 = j;
00917                         x[i__3].r = 1., x[i__3].i = 0.;
00918                         *scale = 0.;
00919                         xmax = 0.;
00920                     }
00921 L160:
00922                     ;
00923                 } else {
00924 
00925 /*                 Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot */
00926 /*                 product has already been divided by 1/A(j,j). */
00927 
00928                     i__3 = j;
00929                     zladiv_(&z__2, &x[j], &tjjs);
00930                     z__1.r = z__2.r - csumj.r, z__1.i = z__2.i - csumj.i;
00931                     x[i__3].r = z__1.r, x[i__3].i = z__1.i;
00932                 }
00933 /* Computing MAX */
00934                 i__3 = j;
00935                 d__3 = xmax, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = 
00936                         d_imag(&x[j]), abs(d__2));
00937                 xmax = max(d__3,d__4);
00938                 ++jlen;
00939                 ip += jinc * jlen;
00940 /* L170: */
00941             }
00942 
00943         } else {
00944 
00945 /*           Solve A**H * x = b */
00946 
00947             ip = jfirst * (jfirst + 1) / 2;
00948             jlen = 1;
00949             i__1 = jlast;
00950             i__2 = jinc;
00951             for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
00952 
00953 /*              Compute x(j) = b(j) - sum A(k,j)*x(k). */
00954 /*                                    k<>j */
00955 
00956                 i__3 = j;
00957                 xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j]), 
00958                         abs(d__2));
00959                 uscal.r = tscal, uscal.i = 0.;
00960                 rec = 1. / max(xmax,1.);
00961                 if (cnorm[j] > (bignum - xj) * rec) {
00962 
00963 /*                 If x(j) could overflow, scale x by 1/(2*XMAX). */
00964 
00965                     rec *= .5;
00966                     if (nounit) {
00967                         d_cnjg(&z__2, &ap[ip]);
00968                         z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
00969                         tjjs.r = z__1.r, tjjs.i = z__1.i;
00970                     } else {
00971                         tjjs.r = tscal, tjjs.i = 0.;
00972                     }
00973                     tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), 
00974                             abs(d__2));
00975                     if (tjj > 1.) {
00976 
00977 /*                       Divide by A(j,j) when scaling x if A(j,j) > 1. */
00978 
00979 /* Computing MIN */
00980                         d__1 = 1., d__2 = rec * tjj;
00981                         rec = min(d__1,d__2);
00982                         zladiv_(&z__1, &uscal, &tjjs);
00983                         uscal.r = z__1.r, uscal.i = z__1.i;
00984                     }
00985                     if (rec < 1.) {
00986                         zdscal_(n, &rec, &x[1], &c__1);
00987                         *scale *= rec;
00988                         xmax *= rec;
00989                     }
00990                 }
00991 
00992                 csumj.r = 0., csumj.i = 0.;
00993                 if (uscal.r == 1. && uscal.i == 0.) {
00994 
00995 /*                 If the scaling needed for A in the dot product is 1, */
00996 /*                 call ZDOTC to perform the dot product. */
00997 
00998                     if (upper) {
00999                         i__3 = j - 1;
01000                         zdotc_(&z__1, &i__3, &ap[ip - j + 1], &c__1, &x[1], &
01001                                 c__1);
01002                         csumj.r = z__1.r, csumj.i = z__1.i;
01003                     } else if (j < *n) {
01004                         i__3 = *n - j;
01005                         zdotc_(&z__1, &i__3, &ap[ip + 1], &c__1, &x[j + 1], &
01006                                 c__1);
01007                         csumj.r = z__1.r, csumj.i = z__1.i;
01008                     }
01009                 } else {
01010 
01011 /*                 Otherwise, use in-line code for the dot product. */
01012 
01013                     if (upper) {
01014                         i__3 = j - 1;
01015                         for (i__ = 1; i__ <= i__3; ++i__) {
01016                             d_cnjg(&z__4, &ap[ip - j + i__]);
01017                             z__3.r = z__4.r * uscal.r - z__4.i * uscal.i, 
01018                                     z__3.i = z__4.r * uscal.i + z__4.i * 
01019                                     uscal.r;
01020                             i__4 = i__;
01021                             z__2.r = z__3.r * x[i__4].r - z__3.i * x[i__4].i, 
01022                                     z__2.i = z__3.r * x[i__4].i + z__3.i * x[
01023                                     i__4].r;
01024                             z__1.r = csumj.r + z__2.r, z__1.i = csumj.i + 
01025                                     z__2.i;
01026                             csumj.r = z__1.r, csumj.i = z__1.i;
01027 /* L180: */
01028                         }
01029                     } else if (j < *n) {
01030                         i__3 = *n - j;
01031                         for (i__ = 1; i__ <= i__3; ++i__) {
01032                             d_cnjg(&z__4, &ap[ip + i__]);
01033                             z__3.r = z__4.r * uscal.r - z__4.i * uscal.i, 
01034                                     z__3.i = z__4.r * uscal.i + z__4.i * 
01035                                     uscal.r;
01036                             i__4 = j + i__;
01037                             z__2.r = z__3.r * x[i__4].r - z__3.i * x[i__4].i, 
01038                                     z__2.i = z__3.r * x[i__4].i + z__3.i * x[
01039                                     i__4].r;
01040                             z__1.r = csumj.r + z__2.r, z__1.i = csumj.i + 
01041                                     z__2.i;
01042                             csumj.r = z__1.r, csumj.i = z__1.i;
01043 /* L190: */
01044                         }
01045                     }
01046                 }
01047 
01048                 z__1.r = tscal, z__1.i = 0.;
01049                 if (uscal.r == z__1.r && uscal.i == z__1.i) {
01050 
01051 /*                 Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j) */
01052 /*                 was not used to scale the dotproduct. */
01053 
01054                     i__3 = j;
01055                     i__4 = j;
01056                     z__1.r = x[i__4].r - csumj.r, z__1.i = x[i__4].i - 
01057                             csumj.i;
01058                     x[i__3].r = z__1.r, x[i__3].i = z__1.i;
01059                     i__3 = j;
01060                     xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
01061                             , abs(d__2));
01062                     if (nounit) {
01063 
01064 /*                    Compute x(j) = x(j) / A(j,j), scaling if necessary. */
01065 
01066                         d_cnjg(&z__2, &ap[ip]);
01067                         z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
01068                         tjjs.r = z__1.r, tjjs.i = z__1.i;
01069                     } else {
01070                         tjjs.r = tscal, tjjs.i = 0.;
01071                         if (tscal == 1.) {
01072                             goto L210;
01073                         }
01074                     }
01075                     tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), 
01076                             abs(d__2));
01077                     if (tjj > smlnum) {
01078 
01079 /*                       abs(A(j,j)) > SMLNUM: */
01080 
01081                         if (tjj < 1.) {
01082                             if (xj > tjj * bignum) {
01083 
01084 /*                             Scale X by 1/abs(x(j)). */
01085 
01086                                 rec = 1. / xj;
01087                                 zdscal_(n, &rec, &x[1], &c__1);
01088                                 *scale *= rec;
01089                                 xmax *= rec;
01090                             }
01091                         }
01092                         i__3 = j;
01093                         zladiv_(&z__1, &x[j], &tjjs);
01094                         x[i__3].r = z__1.r, x[i__3].i = z__1.i;
01095                     } else if (tjj > 0.) {
01096 
01097 /*                       0 < abs(A(j,j)) <= SMLNUM: */
01098 
01099                         if (xj > tjj * bignum) {
01100 
01101 /*                          Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
01102 
01103                             rec = tjj * bignum / xj;
01104                             zdscal_(n, &rec, &x[1], &c__1);
01105                             *scale *= rec;
01106                             xmax *= rec;
01107                         }
01108                         i__3 = j;
01109                         zladiv_(&z__1, &x[j], &tjjs);
01110                         x[i__3].r = z__1.r, x[i__3].i = z__1.i;
01111                     } else {
01112 
01113 /*                       A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and */
01114 /*                       scale = 0 and compute a solution to A**H *x = 0. */
01115 
01116                         i__3 = *n;
01117                         for (i__ = 1; i__ <= i__3; ++i__) {
01118                             i__4 = i__;
01119                             x[i__4].r = 0., x[i__4].i = 0.;
01120 /* L200: */
01121                         }
01122                         i__3 = j;
01123                         x[i__3].r = 1., x[i__3].i = 0.;
01124                         *scale = 0.;
01125                         xmax = 0.;
01126                     }
01127 L210:
01128                     ;
01129                 } else {
01130 
01131 /*                 Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot */
01132 /*                 product has already been divided by 1/A(j,j). */
01133 
01134                     i__3 = j;
01135                     zladiv_(&z__2, &x[j], &tjjs);
01136                     z__1.r = z__2.r - csumj.r, z__1.i = z__2.i - csumj.i;
01137                     x[i__3].r = z__1.r, x[i__3].i = z__1.i;
01138                 }
01139 /* Computing MAX */
01140                 i__3 = j;
01141                 d__3 = xmax, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = 
01142                         d_imag(&x[j]), abs(d__2));
01143                 xmax = max(d__3,d__4);
01144                 ++jlen;
01145                 ip += jinc * jlen;
01146 /* L220: */
01147             }
01148         }
01149         *scale /= tscal;
01150     }
01151 
01152 /*     Scale the column norms by 1/TSCAL for return. */
01153 
01154     if (tscal != 1.) {
01155         d__1 = 1. / tscal;
01156         dscal_(n, &d__1, &cnorm[1], &c__1);
01157     }
01158 
01159     return 0;
01160 
01161 /*     End of ZLATPS */
01162 
01163 } /* zlatps_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:42