/* Subroutine */ int dlatbs_(char *uplo, char *trans, char *diag, char * normin, integer *n, integer *kd, doublereal *ab, integer *ldab, doublereal *x, doublereal *scale, doublereal *cnorm, integer *info) { /* -- LAPACK auxiliary routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University June 30, 1992 Purpose ======= DLATBS solves one of the triangular systems A *x = s*b or A'*x = s*b with scaling to prevent overflow, where A is an upper or lower triangular band matrix. Here A' denotes the transpose of A, x and b are n-element vectors, and s is a scaling factor, usually less than or equal to 1, chosen so that the components of x will be less than the overflow threshold. If the unscaled problem will not cause overflow, the Level 2 BLAS routine DTBSV is called. If the matrix A is singular (A(j,j) = 0 for some j), then s is set to 0 and a non-trivial solution to A*x = 0 is returned. Arguments ========= UPLO (input) CHARACTER*1 Specifies whether the matrix A is upper or lower triangular. = 'U': Upper triangular = 'L': Lower triangular TRANS (input) CHARACTER*1 Specifies the operation applied to A. = 'N': Solve A * x = s*b (No transpose) = 'T': Solve A'* x = s*b (Transpose) = 'C': Solve A'* x = s*b (Conjugate transpose = Transpose) DIAG (input) CHARACTER*1 Specifies whether or not the matrix A is unit triangular. = 'N': Non-unit triangular = 'U': Unit triangular NORMIN (input) CHARACTER*1 Specifies whether CNORM has been set or not. = 'Y': CNORM contains the column norms on entry = 'N': CNORM is not set on entry. On exit, the norms will be computed and stored in CNORM. N (input) INTEGER The order of the matrix A. N >= 0. KD (input) INTEGER The number of subdiagonals or superdiagonals in the triangular matrix A. KD >= 0. AB (input) DOUBLE PRECISION array, dimension (LDAB,N) The upper or lower triangular band matrix A, stored in the first KD+1 rows of the array. The j-th column of A is stored in the j-th column of the array AB as follows: if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). LDAB (input) INTEGER The leading dimension of the array AB. LDAB >= KD+1. X (input/output) DOUBLE PRECISION array, dimension (N) On entry, the right hand side b of the triangular system. On exit, X is overwritten by the solution vector x. SCALE (output) DOUBLE PRECISION The scaling factor s for the triangular system A * x = s*b or A'* x = s*b. If SCALE = 0, the matrix A is singular or badly scaled, and the vector x is an exact or approximate solution to A*x = 0. CNORM (input or output) DOUBLE PRECISION array, dimension (N) If NORMIN = 'Y', CNORM is an input argument and CNORM(j) contains the norm of the off-diagonal part of the j-th column of A. If TRANS = 'N', CNORM(j) must be greater than or equal to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) must be greater than or equal to the 1-norm. If NORMIN = 'N', CNORM is an output argument and CNORM(j) returns the 1-norm of the offdiagonal part of the j-th column of A. INFO (output) INTEGER = 0: successful exit < 0: if INFO = -k, the k-th argument had an illegal value Further Details ======= ======= A rough bound on x is computed; if that is less than overflow, DTBSV is called, otherwise, specific code is used which checks for possible overflow or divide-by-zero at every operation. A columnwise scheme is used for solving A*x = b. The basic algorithm if A is lower triangular is x[1:n] := b[1:n] for j = 1, ..., n x(j) := x(j) / A(j,j) x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] end Define bounds on the components of x after j iterations of the loop: M(j) = bound on x[1:j] G(j) = bound on x[j+1:n] Initially, let M(0) = 0 and G(0) = max{x(i), i=1,...,n}. Then for iteration j+1 we have M(j+1) <= G(j) / | A(j+1,j+1) | G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) where CNORM(j+1) is greater than or equal to the infinity-norm of column j+1 of A, not counting the diagonal. Hence G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) 1<=i<=j and |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) 1<=i< j Since |x(j)| <= M(j), we use the Level 2 BLAS routine DTBSV if the reciprocal of the largest M(j), j=1,..,n, is larger than max(underflow, 1/overflow). The bound on x(j) is also used to determine when a step in the columnwise method can be performed without fear of overflow. If the computed bound is greater than a large constant, x is scaled to prevent overflow, but if the bound overflows, x is set to 0, x(j) to 1, and scale to 0, and a non-trivial solution to A*x = 0 is found. Similarly, a row-wise scheme is used to solve A'*x = b. The basic algorithm for A upper triangular is for j = 1, ..., n x(j) := ( b(j) - A[1:j-1,j]' * x[1:j-1] ) / A(j,j) end We simultaneously compute two bounds G(j) = bound on ( b(i) - A[1:i-1,i]' * x[1:i-1] ), 1<=i<=j M(j) = bound on x(i), 1<=i<=j The initial values are G(0) = 0, M(0) = max{b(i), i=1,..,n}, and we add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. Then the bound on x(j) is M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) 1<=i<=j and we can safely call DTBSV if 1/M(n) and 1/G(n) are both greater than max(underflow, 1/overflow). ===================================================================== Parameter adjustments */ /* Table of constant values */ static integer c__1 = 1; static doublereal c_b36 = .5; /* System generated locals */ integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4; doublereal d__1, d__2, d__3; /* Local variables */ static integer jinc, jlen; extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *, integer *); static doublereal xbnd; static integer imax; static doublereal tmax, tjjs, xmax, grow, sumj; static integer i__, j; extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, integer *); static integer maind; extern logical lsame_(char *, char *); static doublereal tscal, uscal; extern doublereal dasum_(integer *, doublereal *, integer *); static integer jlast; extern /* Subroutine */ int dtbsv_(char *, char *, char *, integer *, integer *, doublereal *, integer *, doublereal *, integer *), daxpy_(integer *, doublereal *, doublereal *, integer *, doublereal *, integer *); static logical upper; extern doublereal dlamch_(char *); static doublereal xj; extern integer idamax_(integer *, doublereal *, integer *); extern /* Subroutine */ int xerbla_(char *, integer *); static doublereal bignum; static logical notran; static integer jfirst; static doublereal smlnum; static logical nounit; static doublereal rec, tjj; #define ab_ref(a_1,a_2) ab[(a_2)*ab_dim1 + a_1] ab_dim1 = *ldab; ab_offset = 1 + ab_dim1 * 1; ab -= ab_offset; --x; --cnorm; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); notran = lsame_(trans, "N"); nounit = lsame_(diag, "N"); /* Test the input parameters. */ if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (! notran && ! lsame_(trans, "T") && ! lsame_(trans, "C")) { *info = -2; } else if (! nounit && ! lsame_(diag, "U")) { *info = -3; } else if (! lsame_(normin, "Y") && ! lsame_(normin, "N")) { *info = -4; } else if (*n < 0) { *info = -5; } else if (*kd < 0) { *info = -6; } else if (*ldab < *kd + 1) { *info = -8; } if (*info != 0) { i__1 = -(*info); xerbla_("DLATBS", &i__1); return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } /* Determine machine dependent parameters to control overflow. */ smlnum = dlamch_("Safe minimum") / dlamch_("Precision"); bignum = 1. / smlnum; *scale = 1.; if (lsame_(normin, "N")) { /* Compute the 1-norm of each column, not including the diagonal. */ if (upper) { /* A is upper triangular. */ i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Computing MIN */ i__2 = *kd, i__3 = j - 1; jlen = min(i__2,i__3); cnorm[j] = dasum_(&jlen, &ab_ref(*kd + 1 - jlen, j), &c__1); /* L10: */ } } else { /* A is lower triangular. */ i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Computing MIN */ i__2 = *kd, i__3 = *n - j; jlen = min(i__2,i__3); if (jlen > 0) { cnorm[j] = dasum_(&jlen, &ab_ref(2, j), &c__1); } else { cnorm[j] = 0.; } /* L20: */ } } } /* Scale the column norms by TSCAL if the maximum element in CNORM is greater than BIGNUM. */ imax = idamax_(n, &cnorm[1], &c__1); tmax = cnorm[imax]; if (tmax <= bignum) { tscal = 1.; } else { tscal = 1. / (smlnum * tmax); dscal_(n, &tscal, &cnorm[1], &c__1); } /* Compute a bound on the computed solution vector to see if the Level 2 BLAS routine DTBSV can be used. */ j = idamax_(n, &x[1], &c__1); xmax = (d__1 = x[j], abs(d__1)); xbnd = xmax; if (notran) { /* Compute the growth in A * x = b. */ if (upper) { jfirst = *n; jlast = 1; jinc = -1; maind = *kd + 1; } else { jfirst = 1; jlast = *n; jinc = 1; maind = 1; } if (tscal != 1.) { grow = 0.; goto L50; } if (nounit) { /* A is non-unit triangular. Compute GROW = 1/G(j) and XBND = 1/M(j). Initially, G(0) = max{x(i), i=1,...,n}. */ grow = 1. / max(xbnd,smlnum); xbnd = grow; i__1 = jlast; i__2 = jinc; for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) { /* Exit the loop if the growth factor is too small. */ if (grow <= smlnum) { goto L50; } /* M(j) = G(j-1) / abs(A(j,j)) */ tjj = (d__1 = ab_ref(maind, j), abs(d__1)); /* Computing MIN */ d__1 = xbnd, d__2 = min(1.,tjj) * grow; xbnd = min(d__1,d__2); if (tjj + cnorm[j] >= smlnum) { /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */ grow *= tjj / (tjj + cnorm[j]); } else { /* G(j) could overflow, set GROW to 0. */ grow = 0.; } /* L30: */ } grow = xbnd; } else { /* A is unit triangular. Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. Computing MIN */ d__1 = 1., d__2 = 1. / max(xbnd,smlnum); grow = min(d__1,d__2); i__2 = jlast; i__1 = jinc; for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) { /* Exit the loop if the growth factor is too small. */ if (grow <= smlnum) { goto L50; } /* G(j) = G(j-1)*( 1 + CNORM(j) ) */ grow *= 1. / (cnorm[j] + 1.); /* L40: */ } } L50: ; } else { /* Compute the growth in A' * x = b. */ if (upper) { jfirst = 1; jlast = *n; jinc = 1; maind = *kd + 1; } else { jfirst = *n; jlast = 1; jinc = -1; maind = 1; } if (tscal != 1.) { grow = 0.; goto L80; } if (nounit) { /* A is non-unit triangular. Compute GROW = 1/G(j) and XBND = 1/M(j). Initially, M(0) = max{x(i), i=1,...,n}. */ grow = 1. / max(xbnd,smlnum); xbnd = grow; i__1 = jlast; i__2 = jinc; for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) { /* Exit the loop if the growth factor is too small. */ if (grow <= smlnum) { goto L80; } /* G(j) = max( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */ xj = cnorm[j] + 1.; /* Computing MIN */ d__1 = grow, d__2 = xbnd / xj; grow = min(d__1,d__2); /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */ tjj = (d__1 = ab_ref(maind, j), abs(d__1)); if (xj > tjj) { xbnd *= tjj / xj; } /* L60: */ } grow = min(grow,xbnd); } else { /* A is unit triangular. Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. Computing MIN */ d__1 = 1., d__2 = 1. / max(xbnd,smlnum); grow = min(d__1,d__2); i__2 = jlast; i__1 = jinc; for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) { /* Exit the loop if the growth factor is too small. */ if (grow <= smlnum) { goto L80; } /* G(j) = ( 1 + CNORM(j) )*G(j-1) */ xj = cnorm[j] + 1.; grow /= xj; /* L70: */ } } L80: ; } if (grow * tscal > smlnum) { /* Use the Level 2 BLAS solve if the reciprocal of the bound on elements of X is not too small. */ dtbsv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &x[1], &c__1); } else { /* Use a Level 1 BLAS solve, scaling intermediate results. */ if (xmax > bignum) { /* Scale X so that its components are less than or equal to BIGNUM in absolute value. */ *scale = bignum / xmax; dscal_(n, scale, &x[1], &c__1); xmax = bignum; } if (notran) { /* Solve A * x = b */ i__1 = jlast; i__2 = jinc; for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) { /* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */ xj = (d__1 = x[j], abs(d__1)); if (nounit) { tjjs = ab_ref(maind, j) * tscal; } else { tjjs = tscal; if (tscal == 1.) { goto L100; } } tjj = abs(tjjs); if (tjj > smlnum) { /* abs(A(j,j)) > SMLNUM: */ if (tjj < 1.) { if (xj > tjj * bignum) { /* Scale x by 1/b(j). */ rec = 1. / xj; dscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } } x[j] /= tjjs; xj = (d__1 = x[j], abs(d__1)); } else if (tjj > 0.) { /* 0 < abs(A(j,j)) <= SMLNUM: */ if (xj > tjj * bignum) { /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM to avoid overflow when dividing by A(j,j). */ rec = tjj * bignum / xj; if (cnorm[j] > 1.) { /* Scale by 1/CNORM(j) to avoid overflow when multiplying x(j) times column j. */ rec /= cnorm[j]; } dscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } x[j] /= tjjs; xj = (d__1 = x[j], abs(d__1)); } else { /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and scale = 0, and compute a solution to A*x = 0. */ i__3 = *n; for (i__ = 1; i__ <= i__3; ++i__) { x[i__] = 0.; /* L90: */ } x[j] = 1.; xj = 1.; *scale = 0.; xmax = 0.; } L100: /* Scale x if necessary to avoid overflow when adding a multiple of column j of A. */ if (xj > 1.) { rec = 1. / xj; if (cnorm[j] > (bignum - xmax) * rec) { /* Scale x by 1/(2*abs(x(j))). */ rec *= .5; dscal_(n, &rec, &x[1], &c__1); *scale *= rec; } } else if (xj * cnorm[j] > bignum - xmax) { /* Scale x by 1/2. */ dscal_(n, &c_b36, &x[1], &c__1); *scale *= .5; } if (upper) { if (j > 1) { /* Compute the update x(max(1,j-kd):j-1) := x(max(1,j-kd):j-1) - x(j)* A(max(1,j-kd):j-1,j) Computing MIN */ i__3 = *kd, i__4 = j - 1; jlen = min(i__3,i__4); d__1 = -x[j] * tscal; daxpy_(&jlen, &d__1, &ab_ref(*kd + 1 - jlen, j), & c__1, &x[j - jlen], &c__1); i__3 = j - 1; i__ = idamax_(&i__3, &x[1], &c__1); xmax = (d__1 = x[i__], abs(d__1)); } } else if (j < *n) { /* Compute the update x(j+1:min(j+kd,n)) := x(j+1:min(j+kd,n)) - x(j) * A(j+1:min(j+kd,n),j) Computing MIN */ i__3 = *kd, i__4 = *n - j; jlen = min(i__3,i__4); if (jlen > 0) { d__1 = -x[j] * tscal; daxpy_(&jlen, &d__1, &ab_ref(2, j), &c__1, &x[j + 1], &c__1); } i__3 = *n - j; i__ = j + idamax_(&i__3, &x[j + 1], &c__1); xmax = (d__1 = x[i__], abs(d__1)); } /* L110: */ } } else { /* Solve A' * x = b */ i__2 = jlast; i__1 = jinc; for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) { /* Compute x(j) = b(j) - sum A(k,j)*x(k). k<>j */ xj = (d__1 = x[j], abs(d__1)); uscal = tscal; rec = 1. / max(xmax,1.); if (cnorm[j] > (bignum - xj) * rec) { /* If x(j) could overflow, scale x by 1/(2*XMAX). */ rec *= .5; if (nounit) { tjjs = ab_ref(maind, j) * tscal; } else { tjjs = tscal; } tjj = abs(tjjs); if (tjj > 1.) { /* Divide by A(j,j) when scaling x if A(j,j) > 1. Computing MIN */ d__1 = 1., d__2 = rec * tjj; rec = min(d__1,d__2); uscal /= tjjs; } if (rec < 1.) { dscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } } sumj = 0.; if (uscal == 1.) { /* If the scaling needed for A in the dot product is 1, call DDOT to perform the dot product. */ if (upper) { /* Computing MIN */ i__3 = *kd, i__4 = j - 1; jlen = min(i__3,i__4); sumj = ddot_(&jlen, &ab_ref(*kd + 1 - jlen, j), &c__1, &x[j - jlen], &c__1); } else { /* Computing MIN */ i__3 = *kd, i__4 = *n - j; jlen = min(i__3,i__4); if (jlen > 0) { sumj = ddot_(&jlen, &ab_ref(2, j), &c__1, &x[j + 1], &c__1); } } } else { /* Otherwise, use in-line code for the dot product. */ if (upper) { /* Computing MIN */ i__3 = *kd, i__4 = j - 1; jlen = min(i__3,i__4); i__3 = jlen; for (i__ = 1; i__ <= i__3; ++i__) { sumj += ab_ref(*kd + i__ - jlen, j) * uscal * x[j - jlen - 1 + i__]; /* L120: */ } } else { /* Computing MIN */ i__3 = *kd, i__4 = *n - j; jlen = min(i__3,i__4); i__3 = jlen; for (i__ = 1; i__ <= i__3; ++i__) { sumj += ab_ref(i__ + 1, j) * uscal * x[j + i__]; /* L130: */ } } } if (uscal == tscal) { /* Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) was not used to scale the dotproduct. */ x[j] -= sumj; xj = (d__1 = x[j], abs(d__1)); if (nounit) { /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */ tjjs = ab_ref(maind, j) * tscal; } else { tjjs = tscal; if (tscal == 1.) { goto L150; } } tjj = abs(tjjs); if (tjj > smlnum) { /* abs(A(j,j)) > SMLNUM: */ if (tjj < 1.) { if (xj > tjj * bignum) { /* Scale X by 1/abs(x(j)). */ rec = 1. / xj; dscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } } x[j] /= tjjs; } else if (tjj > 0.) { /* 0 < abs(A(j,j)) <= SMLNUM: */ if (xj > tjj * bignum) { /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */ rec = tjj * bignum / xj; dscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } x[j] /= tjjs; } else { /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and scale = 0, and compute a solution to A'*x = 0. */ i__3 = *n; for (i__ = 1; i__ <= i__3; ++i__) { x[i__] = 0.; /* L140: */ } x[j] = 1.; *scale = 0.; xmax = 0.; } L150: ; } else { /* Compute x(j) := x(j) / A(j,j) - sumj if the dot product has already been divided by 1/A(j,j). */ x[j] = x[j] / tjjs - sumj; } /* Computing MAX */ d__2 = xmax, d__3 = (d__1 = x[j], abs(d__1)); xmax = max(d__2,d__3); /* L160: */ } } *scale /= tscal; } /* Scale the column norms by 1/TSCAL for return. */ if (tscal != 1.) { d__1 = 1. / tscal; dscal_(n, &d__1, &cnorm[1], &c__1); } return 0; /* End of DLATBS */ } /* dlatbs_ */
doublereal dlantb_(char *norm, char *uplo, char *diag, integer *n, integer *k, doublereal *ab, integer *ldab, doublereal *work) { /* System generated locals */ integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4, i__5; doublereal ret_val, d__1, d__2, d__3; /* Builtin functions */ double sqrt(doublereal); /* Local variables */ integer i__, j, l; doublereal sum, scale; logical udiag; extern logical lsame_(char *, char *); doublereal value; extern /* Subroutine */ int dlassq_(integer *, doublereal *, integer *, doublereal *, doublereal *); /* -- LAPACK auxiliary routine (version 3.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* DLANTB returns the value of the one norm, or the Frobenius norm, or */ /* the infinity norm, or the element of largest absolute value of an */ /* n by n triangular band matrix A, with ( k + 1 ) diagonals. */ /* Description */ /* =========== */ /* DLANTB returns the value */ /* DLANTB = ( max(abs(A(i,j))), NORM = 'M' or 'm' */ /* ( */ /* ( norm1(A), NORM = '1', 'O' or 'o' */ /* ( */ /* ( normI(A), NORM = 'I' or 'i' */ /* ( */ /* ( normF(A), NORM = 'F', 'f', 'E' or 'e' */ /* where norm1 denotes the one norm of a matrix (maximum column sum), */ /* normI denotes the infinity norm of a matrix (maximum row sum) and */ /* normF denotes the Frobenius norm of a matrix (square root of sum of */ /* squares). Note that max(abs(A(i,j))) is not a consistent matrix norm. */ /* Arguments */ /* ========= */ /* NORM (input) CHARACTER*1 */ /* Specifies the value to be returned in DLANTB as described */ /* above. */ /* UPLO (input) CHARACTER*1 */ /* Specifies whether the matrix A is upper or lower triangular. */ /* = 'U': Upper triangular */ /* = 'L': Lower triangular */ /* DIAG (input) CHARACTER*1 */ /* Specifies whether or not the matrix A is unit triangular. */ /* = 'N': Non-unit triangular */ /* = 'U': Unit triangular */ /* N (input) INTEGER */ /* The order of the matrix A. N >= 0. When N = 0, DLANTB is */ /* set to zero. */ /* K (input) INTEGER */ /* The number of super-diagonals of the matrix A if UPLO = 'U', */ /* or the number of sub-diagonals of the matrix A if UPLO = 'L'. */ /* K >= 0. */ /* AB (input) DOUBLE PRECISION array, dimension (LDAB,N) */ /* The upper or lower triangular band matrix A, stored in the */ /* first k+1 rows of AB. The j-th column of A is stored */ /* in the j-th column of the array AB as follows: */ /* if UPLO = 'U', AB(k+1+i-j,j) = A(i,j) for max(1,j-k)<=i<=j; */ /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+k). */ /* Note that when DIAG = 'U', the elements of the array AB */ /* corresponding to the diagonal elements of the matrix A are */ /* not referenced, but are assumed to be one. */ /* LDAB (input) INTEGER */ /* The leading dimension of the array AB. LDAB >= K+1. */ /* WORK (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)), */ /* where LWORK >= N when NORM = 'I'; otherwise, WORK is not */ /* referenced. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Parameter adjustments */ ab_dim1 = *ldab; ab_offset = 1 + ab_dim1; ab -= ab_offset; --work; /* Function Body */ if (*n == 0) { value = 0.; } else if (lsame_(norm, "M")) { /* Find max(abs(A(i,j))). */ if (lsame_(diag, "U")) { value = 1.; if (lsame_(uplo, "U")) { i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Computing MAX */ i__2 = *k + 2 - j; i__3 = *k; for (i__ = max(i__2,1); i__ <= i__3; ++i__) { /* Computing MAX */ d__2 = value, d__3 = (d__1 = ab[i__ + j * ab_dim1], abs(d__1)); value = max(d__2,d__3); /* L10: */ } /* L20: */ } } else { i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Computing MIN */ i__2 = *n + 1 - j, i__4 = *k + 1; i__3 = min(i__2,i__4); for (i__ = 2; i__ <= i__3; ++i__) { /* Computing MAX */ d__2 = value, d__3 = (d__1 = ab[i__ + j * ab_dim1], abs(d__1)); value = max(d__2,d__3); /* L30: */ } /* L40: */ } } } else { value = 0.; if (lsame_(uplo, "U")) { i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Computing MAX */ i__3 = *k + 2 - j; i__2 = *k + 1; for (i__ = max(i__3,1); i__ <= i__2; ++i__) { /* Computing MAX */ d__2 = value, d__3 = (d__1 = ab[i__ + j * ab_dim1], abs(d__1)); value = max(d__2,d__3); /* L50: */ } /* L60: */ } } else { i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Computing MIN */ i__3 = *n + 1 - j, i__4 = *k + 1; i__2 = min(i__3,i__4); for (i__ = 1; i__ <= i__2; ++i__) { /* Computing MAX */ d__2 = value, d__3 = (d__1 = ab[i__ + j * ab_dim1], abs(d__1)); value = max(d__2,d__3); /* L70: */ } /* L80: */ } } } } else if (lsame_(norm, "O") || *(unsigned char *) norm == '1') { /* Find norm1(A). */ value = 0.; udiag = lsame_(diag, "U"); if (lsame_(uplo, "U")) { i__1 = *n; for (j = 1; j <= i__1; ++j) { if (udiag) { sum = 1.; /* Computing MAX */ i__2 = *k + 2 - j; i__3 = *k; for (i__ = max(i__2,1); i__ <= i__3; ++i__) { sum += (d__1 = ab[i__ + j * ab_dim1], abs(d__1)); /* L90: */ } } else { sum = 0.; /* Computing MAX */ i__3 = *k + 2 - j; i__2 = *k + 1; for (i__ = max(i__3,1); i__ <= i__2; ++i__) { sum += (d__1 = ab[i__ + j * ab_dim1], abs(d__1)); /* L100: */ } } value = max(value,sum); /* L110: */ } } else { i__1 = *n; for (j = 1; j <= i__1; ++j) { if (udiag) { sum = 1.; /* Computing MIN */ i__3 = *n + 1 - j, i__4 = *k + 1; i__2 = min(i__3,i__4); for (i__ = 2; i__ <= i__2; ++i__) { sum += (d__1 = ab[i__ + j * ab_dim1], abs(d__1)); /* L120: */ } } else { sum = 0.; /* Computing MIN */ i__3 = *n + 1 - j, i__4 = *k + 1; i__2 = min(i__3,i__4); for (i__ = 1; i__ <= i__2; ++i__) { sum += (d__1 = ab[i__ + j * ab_dim1], abs(d__1)); /* L130: */ } } value = max(value,sum); /* L140: */ } } } else if (lsame_(norm, "I")) { /* Find normI(A). */ value = 0.; if (lsame_(uplo, "U")) { if (lsame_(diag, "U")) { i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { work[i__] = 1.; /* L150: */ } i__1 = *n; for (j = 1; j <= i__1; ++j) { l = *k + 1 - j; /* Computing MAX */ i__2 = 1, i__3 = j - *k; i__4 = j - 1; for (i__ = max(i__2,i__3); i__ <= i__4; ++i__) { work[i__] += (d__1 = ab[l + i__ + j * ab_dim1], abs( d__1)); /* L160: */ } /* L170: */ } } else { i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { work[i__] = 0.; /* L180: */ } i__1 = *n; for (j = 1; j <= i__1; ++j) { l = *k + 1 - j; /* Computing MAX */ i__4 = 1, i__2 = j - *k; i__3 = j; for (i__ = max(i__4,i__2); i__ <= i__3; ++i__) { work[i__] += (d__1 = ab[l + i__ + j * ab_dim1], abs( d__1)); /* L190: */ } /* L200: */ } } } else { if (lsame_(diag, "U")) { i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { work[i__] = 1.; /* L210: */ } i__1 = *n; for (j = 1; j <= i__1; ++j) { l = 1 - j; /* Computing MIN */ i__4 = *n, i__2 = j + *k; i__3 = min(i__4,i__2); for (i__ = j + 1; i__ <= i__3; ++i__) { work[i__] += (d__1 = ab[l + i__ + j * ab_dim1], abs( d__1)); /* L220: */ } /* L230: */ } } else { i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { work[i__] = 0.; /* L240: */ } i__1 = *n; for (j = 1; j <= i__1; ++j) { l = 1 - j; /* Computing MIN */ i__4 = *n, i__2 = j + *k; i__3 = min(i__4,i__2); for (i__ = j; i__ <= i__3; ++i__) { work[i__] += (d__1 = ab[l + i__ + j * ab_dim1], abs( d__1)); /* L250: */ } /* L260: */ } } } i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { /* Computing MAX */ d__1 = value, d__2 = work[i__]; value = max(d__1,d__2); /* L270: */ } } else if (lsame_(norm, "F") || lsame_(norm, "E")) { /* Find normF(A). */ if (lsame_(uplo, "U")) { if (lsame_(diag, "U")) { scale = 1.; sum = (doublereal) (*n); if (*k > 0) { i__1 = *n; for (j = 2; j <= i__1; ++j) { /* Computing MIN */ i__4 = j - 1; i__3 = min(i__4,*k); /* Computing MAX */ i__2 = *k + 2 - j; dlassq_(&i__3, &ab[max(i__2, 1)+ j * ab_dim1], &c__1, &scale, &sum); /* L280: */ } } } else { scale = 0.; sum = 1.; i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Computing MIN */ i__4 = j, i__2 = *k + 1; i__3 = min(i__4,i__2); /* Computing MAX */ i__5 = *k + 2 - j; dlassq_(&i__3, &ab[max(i__5, 1)+ j * ab_dim1], &c__1, & scale, &sum); /* L290: */ } } } else { if (lsame_(diag, "U")) { scale = 1.; sum = (doublereal) (*n); if (*k > 0) { i__1 = *n - 1; for (j = 1; j <= i__1; ++j) { /* Computing MIN */ i__4 = *n - j; i__3 = min(i__4,*k); dlassq_(&i__3, &ab[j * ab_dim1 + 2], &c__1, &scale, & sum); /* L300: */ } } } else { scale = 0.; sum = 1.; i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Computing MIN */ i__4 = *n - j + 1, i__2 = *k + 1; i__3 = min(i__4,i__2); dlassq_(&i__3, &ab[j * ab_dim1 + 1], &c__1, &scale, &sum); /* L310: */ } } } value = scale * sqrt(sum); } ret_val = value; return ret_val; /* End of DLANTB */ } /* dlantb_ */
/* Subroutine */ int zsyconv_(char *uplo, char *way, integer *n, doublecomplex *a, integer *lda, integer *ipiv, doublecomplex *work, integer *info) { /* System generated locals */ integer a_dim1, a_offset, i__1, i__2, i__3; /* Local variables */ integer i__, j, ip; doublecomplex temp; extern logical lsame_(char *, char *); logical upper; extern /* Subroutine */ int xerbla_(char *, integer *); logical convert; /* -- LAPACK computational routine (version 3.4.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* November 2011 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. External Functions .. */ /* .. External Subroutines .. */ /* .. Local Scalars .. */ /* .. */ /* .. Executable Statements .. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; --ipiv; --work; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); convert = lsame_(way, "C"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (! convert && ! lsame_(way, "R")) { *info = -2; } else if (*n < 0) { *info = -3; } else if (*lda < max(1,*n)) { *info = -5; } if (*info != 0) { i__1 = -(*info); xerbla_("ZSYCONV", &i__1); return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } if (upper) { /* A is UPPER */ if (convert) { /* Convert A (A is upper) */ /* Convert VALUE */ i__ = *n; work[1].r = 0.; work[1].i = 0.; // , expr subst while(i__ > 1) { if (ipiv[i__] < 0) { i__1 = i__; i__2 = i__ - 1 + i__ * a_dim1; work[i__1].r = a[i__2].r; work[i__1].i = a[i__2].i; // , expr subst i__1 = i__ - 1 + i__ * a_dim1; a[i__1].r = 0.; a[i__1].i = 0.; // , expr subst --i__; } else { i__1 = i__; work[i__1].r = 0.; work[i__1].i = 0.; // , expr subst } --i__; } /* Convert PERMUTATIONS */ i__ = *n; while(i__ >= 1) { if (ipiv[i__] > 0) { ip = ipiv[i__]; if (i__ < *n) { i__1 = *n; for (j = i__ + 1; j <= i__1; ++j) { i__2 = ip + j * a_dim1; temp.r = a[i__2].r; temp.i = a[i__2].i; // , expr subst i__2 = ip + j * a_dim1; i__3 = i__ + j * a_dim1; a[i__2].r = a[i__3].r; a[i__2].i = a[i__3].i; // , expr subst i__2 = i__ + j * a_dim1; a[i__2].r = temp.r; a[i__2].i = temp.i; // , expr subst /* L12: */ } } } else { ip = -ipiv[i__]; if (i__ < *n) { i__1 = *n; for (j = i__ + 1; j <= i__1; ++j) { i__2 = ip + j * a_dim1; temp.r = a[i__2].r; temp.i = a[i__2].i; // , expr subst i__2 = ip + j * a_dim1; i__3 = i__ - 1 + j * a_dim1; a[i__2].r = a[i__3].r; a[i__2].i = a[i__3].i; // , expr subst i__2 = i__ - 1 + j * a_dim1; a[i__2].r = temp.r; a[i__2].i = temp.i; // , expr subst /* L13: */ } } --i__; } --i__; } } else { /* Revert A (A is upper) */ /* Revert PERMUTATIONS */ i__ = 1; while(i__ <= *n) { if (ipiv[i__] > 0) { ip = ipiv[i__]; if (i__ < *n) { i__1 = *n; for (j = i__ + 1; j <= i__1; ++j) { i__2 = ip + j * a_dim1; temp.r = a[i__2].r; temp.i = a[i__2].i; // , expr subst i__2 = ip + j * a_dim1; i__3 = i__ + j * a_dim1; a[i__2].r = a[i__3].r; a[i__2].i = a[i__3].i; // , expr subst i__2 = i__ + j * a_dim1; a[i__2].r = temp.r; a[i__2].i = temp.i; // , expr subst } } } else { ip = -ipiv[i__]; ++i__; if (i__ < *n) { i__1 = *n; for (j = i__ + 1; j <= i__1; ++j) { i__2 = ip + j * a_dim1; temp.r = a[i__2].r; temp.i = a[i__2].i; // , expr subst i__2 = ip + j * a_dim1; i__3 = i__ - 1 + j * a_dim1; a[i__2].r = a[i__3].r; a[i__2].i = a[i__3].i; // , expr subst i__2 = i__ - 1 + j * a_dim1; a[i__2].r = temp.r; a[i__2].i = temp.i; // , expr subst } } } ++i__; } /* Revert VALUE */ i__ = *n; while(i__ > 1) { if (ipiv[i__] < 0) { i__1 = i__ - 1 + i__ * a_dim1; i__2 = i__; a[i__1].r = work[i__2].r; a[i__1].i = work[i__2].i; // , expr subst --i__; } --i__; } } } else { /* A is LOWER */ if (convert) { /* Convert A (A is lower) */ /* Convert VALUE */ i__ = 1; i__1 = *n; work[i__1].r = 0.; work[i__1].i = 0.; // , expr subst while(i__ <= *n) { if (i__ < *n && ipiv[i__] < 0) { i__1 = i__; i__2 = i__ + 1 + i__ * a_dim1; work[i__1].r = a[i__2].r; work[i__1].i = a[i__2].i; // , expr subst i__1 = i__ + 1 + i__ * a_dim1; a[i__1].r = 0.; a[i__1].i = 0.; // , expr subst ++i__; } else { i__1 = i__; work[i__1].r = 0.; work[i__1].i = 0.; // , expr subst } ++i__; } /* Convert PERMUTATIONS */ i__ = 1; while(i__ <= *n) { if (ipiv[i__] > 0) { ip = ipiv[i__]; if (i__ > 1) { i__1 = i__ - 1; for (j = 1; j <= i__1; ++j) { i__2 = ip + j * a_dim1; temp.r = a[i__2].r; temp.i = a[i__2].i; // , expr subst i__2 = ip + j * a_dim1; i__3 = i__ + j * a_dim1; a[i__2].r = a[i__3].r; a[i__2].i = a[i__3].i; // , expr subst i__2 = i__ + j * a_dim1; a[i__2].r = temp.r; a[i__2].i = temp.i; // , expr subst /* L22: */ } } } else { ip = -ipiv[i__]; if (i__ > 1) { i__1 = i__ - 1; for (j = 1; j <= i__1; ++j) { i__2 = ip + j * a_dim1; temp.r = a[i__2].r; temp.i = a[i__2].i; // , expr subst i__2 = ip + j * a_dim1; i__3 = i__ + 1 + j * a_dim1; a[i__2].r = a[i__3].r; a[i__2].i = a[i__3].i; // , expr subst i__2 = i__ + 1 + j * a_dim1; a[i__2].r = temp.r; a[i__2].i = temp.i; // , expr subst /* L23: */ } } ++i__; } ++i__; } } else { /* Revert A (A is lower) */ /* Revert PERMUTATIONS */ i__ = *n; while(i__ >= 1) { if (ipiv[i__] > 0) { ip = ipiv[i__]; if (i__ > 1) { i__1 = i__ - 1; for (j = 1; j <= i__1; ++j) { i__2 = i__ + j * a_dim1; temp.r = a[i__2].r; temp.i = a[i__2].i; // , expr subst i__2 = i__ + j * a_dim1; i__3 = ip + j * a_dim1; a[i__2].r = a[i__3].r; a[i__2].i = a[i__3].i; // , expr subst i__2 = ip + j * a_dim1; a[i__2].r = temp.r; a[i__2].i = temp.i; // , expr subst } } } else { ip = -ipiv[i__]; --i__; if (i__ > 1) { i__1 = i__ - 1; for (j = 1; j <= i__1; ++j) { i__2 = i__ + 1 + j * a_dim1; temp.r = a[i__2].r; temp.i = a[i__2].i; // , expr subst i__2 = i__ + 1 + j * a_dim1; i__3 = ip + j * a_dim1; a[i__2].r = a[i__3].r; a[i__2].i = a[i__3].i; // , expr subst i__2 = ip + j * a_dim1; a[i__2].r = temp.r; a[i__2].i = temp.i; // , expr subst } } } --i__; } /* Revert VALUE */ i__ = 1; while(i__ <= *n - 1) { if (ipiv[i__] < 0) { i__1 = i__ + 1 + i__ * a_dim1; i__2 = i__; a[i__1].r = work[i__2].r; a[i__1].i = work[i__2].i; // , expr subst ++i__; } ++i__; } } } return 0; /* End of ZSYCONV */ }
/* Subroutine */ int zherfs_(char *uplo, integer *n, integer *nrhs, doublecomplex *a, integer *lda, doublecomplex *af, integer *ldaf, integer *ipiv, doublecomplex *b, integer *ldb, doublecomplex *x, integer *ldx, doublereal *ferr, doublereal *berr, doublecomplex *work, doublereal *rwork, integer *info) { /* -- LAPACK routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University September 30, 1994 Purpose ======= ZHERFS improves the computed solution to a system of linear equations when the coefficient matrix is Hermitian indefinite, and provides error bounds and backward error estimates for the solution. Arguments ========= UPLO (input) CHARACTER*1 = 'U': Upper triangle of A is stored; = 'L': Lower triangle of A is stored. N (input) INTEGER The order of the matrix A. N >= 0. NRHS (input) INTEGER The number of right hand sides, i.e., the number of columns of the matrices B and X. NRHS >= 0. A (input) COMPLEX*16 array, dimension (LDA,N) The Hermitian matrix A. If UPLO = 'U', the leading N-by-N upper triangular part of A contains the upper triangular part of the matrix A, and the strictly lower triangular part of A is not referenced. If UPLO = 'L', the leading N-by-N lower triangular part of A contains the lower triangular part of the matrix A, and the strictly upper triangular part of A is not referenced. LDA (input) INTEGER The leading dimension of the array A. LDA >= max(1,N). AF (input) COMPLEX*16 array, dimension (LDAF,N) The factored form of the matrix A. AF contains the block diagonal matrix D and the multipliers used to obtain the factor U or L from the factorization A = U*D*U**H or A = L*D*L**H as computed by ZHETRF. LDAF (input) INTEGER The leading dimension of the array AF. LDAF >= max(1,N). IPIV (input) INTEGER array, dimension (N) Details of the interchanges and the block structure of D as determined by ZHETRF. B (input) COMPLEX*16 array, dimension (LDB,NRHS) The right hand side matrix B. LDB (input) INTEGER The leading dimension of the array B. LDB >= max(1,N). X (input/output) COMPLEX*16 array, dimension (LDX,NRHS) On entry, the solution matrix X, as computed by ZHETRS. On exit, the improved solution matrix X. LDX (input) INTEGER The leading dimension of the array X. LDX >= max(1,N). FERR (output) DOUBLE PRECISION array, dimension (NRHS) The estimated forward error bound for each solution vector X(j) (the j-th column of the solution matrix X). If XTRUE is the true solution corresponding to X(j), FERR(j) is an estimated upper bound for the magnitude of the largest element in (X(j) - XTRUE) divided by the magnitude of the largest element in X(j). The estimate is as reliable as the estimate for RCOND, and is almost always a slight overestimate of the true error. BERR (output) DOUBLE PRECISION array, dimension (NRHS) The componentwise relative backward error of each solution vector X(j) (i.e., the smallest relative change in any element of A or B that makes X(j) an exact solution). WORK (workspace) COMPLEX*16 array, dimension (2*N) RWORK (workspace) DOUBLE PRECISION array, dimension (N) INFO (output) INTEGER = 0: successful exit < 0: if INFO = -i, the i-th argument had an illegal value Internal Parameters =================== ITMAX is the maximum number of steps of iterative refinement. ===================================================================== Test the input parameters. Parameter adjustments */ /* Table of constant values */ static doublecomplex c_b1 = {1.,0.}; static integer c__1 = 1; /* System generated locals */ integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5; doublereal d__1, d__2, d__3, d__4; doublecomplex z__1; /* Builtin functions */ double d_imag(doublecomplex *); /* Local variables */ static integer kase; static doublereal safe1, safe2; static integer i__, j, k; static doublereal s; extern logical lsame_(char *, char *); static integer count; extern /* Subroutine */ int zhemv_(char *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *); static logical upper; extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, doublecomplex *, integer *), zaxpy_(integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *); extern doublereal dlamch_(char *); static doublereal xk; static integer nz; static doublereal safmin; extern /* Subroutine */ int xerbla_(char *, integer *), zlacon_( integer *, doublecomplex *, doublecomplex *, doublereal *, integer *); static doublereal lstres; extern /* Subroutine */ int zhetrs_(char *, integer *, integer *, doublecomplex *, integer *, integer *, doublecomplex *, integer *, integer *); static doublereal eps; #define a_subscr(a_1,a_2) (a_2)*a_dim1 + a_1 #define a_ref(a_1,a_2) a[a_subscr(a_1,a_2)] #define b_subscr(a_1,a_2) (a_2)*b_dim1 + a_1 #define b_ref(a_1,a_2) b[b_subscr(a_1,a_2)] #define x_subscr(a_1,a_2) (a_2)*x_dim1 + a_1 #define x_ref(a_1,a_2) x[x_subscr(a_1,a_2)] a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; af_dim1 = *ldaf; af_offset = 1 + af_dim1 * 1; af -= af_offset; --ipiv; b_dim1 = *ldb; b_offset = 1 + b_dim1 * 1; b -= b_offset; x_dim1 = *ldx; x_offset = 1 + x_dim1 * 1; x -= x_offset; --ferr; --berr; --work; --rwork; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*nrhs < 0) { *info = -3; } else if (*lda < max(1,*n)) { *info = -5; } else if (*ldaf < max(1,*n)) { *info = -7; } else if (*ldb < max(1,*n)) { *info = -10; } else if (*ldx < max(1,*n)) { *info = -12; } if (*info != 0) { i__1 = -(*info); xerbla_("ZHERFS", &i__1); return 0; } /* Quick return if possible */ if (*n == 0 || *nrhs == 0) { i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { ferr[j] = 0.; berr[j] = 0.; /* L10: */ } return 0; } /* NZ = maximum number of nonzero elements in each row of A, plus 1 */ nz = *n + 1; eps = dlamch_("Epsilon"); safmin = dlamch_("Safe minimum"); safe1 = nz * safmin; safe2 = safe1 / eps; /* Do for each right hand side */ i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { count = 1; lstres = 3.; L20: /* Loop until stopping criterion is satisfied. Compute residual R = B - A * X */ zcopy_(n, &b_ref(1, j), &c__1, &work[1], &c__1); z__1.r = -1., z__1.i = 0.; zhemv_(uplo, n, &z__1, &a[a_offset], lda, &x_ref(1, j), &c__1, &c_b1, &work[1], &c__1); /* Compute componentwise relative backward error from formula max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) where abs(Z) is the componentwise absolute value of the matrix or vector Z. If the i-th component of the denominator is less than SAFE2, then SAFE1 is added to the i-th components of the numerator and denominator before dividing. */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = b_subscr(i__, j); rwork[i__] = (d__1 = b[i__3].r, abs(d__1)) + (d__2 = d_imag(& b_ref(i__, j)), abs(d__2)); /* L30: */ } /* Compute abs(A)*abs(X) + abs(B). */ if (upper) { i__2 = *n; for (k = 1; k <= i__2; ++k) { s = 0.; i__3 = x_subscr(k, j); xk = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x_ref(k, j)), abs(d__2)); i__3 = k - 1; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = a_subscr(i__, k); rwork[i__] += ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = d_imag(&a_ref(i__, k)), abs(d__2))) * xk; i__4 = a_subscr(i__, k); i__5 = x_subscr(i__, j); s += ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = d_imag(& a_ref(i__, k)), abs(d__2))) * ((d__3 = x[i__5].r, abs(d__3)) + (d__4 = d_imag(&x_ref(i__, j)), abs( d__4))); /* L40: */ } i__3 = a_subscr(k, k); rwork[k] = rwork[k] + (d__1 = a[i__3].r, abs(d__1)) * xk + s; /* L50: */ } } else { i__2 = *n; for (k = 1; k <= i__2; ++k) { s = 0.; i__3 = x_subscr(k, j); xk = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x_ref(k, j)), abs(d__2)); i__3 = a_subscr(k, k); rwork[k] += (d__1 = a[i__3].r, abs(d__1)) * xk; i__3 = *n; for (i__ = k + 1; i__ <= i__3; ++i__) { i__4 = a_subscr(i__, k); rwork[i__] += ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = d_imag(&a_ref(i__, k)), abs(d__2))) * xk; i__4 = a_subscr(i__, k); i__5 = x_subscr(i__, j); s += ((d__1 = a[i__4].r, abs(d__1)) + (d__2 = d_imag(& a_ref(i__, k)), abs(d__2))) * ((d__3 = x[i__5].r, abs(d__3)) + (d__4 = d_imag(&x_ref(i__, j)), abs( d__4))); /* L60: */ } rwork[k] += s; /* L70: */ } } s = 0.; i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { if (rwork[i__] > safe2) { /* Computing MAX */ i__3 = i__; d__3 = s, d__4 = ((d__1 = work[i__3].r, abs(d__1)) + (d__2 = d_imag(&work[i__]), abs(d__2))) / rwork[i__]; s = max(d__3,d__4); } else { /* Computing MAX */ i__3 = i__; d__3 = s, d__4 = ((d__1 = work[i__3].r, abs(d__1)) + (d__2 = d_imag(&work[i__]), abs(d__2)) + safe1) / (rwork[i__] + safe1); s = max(d__3,d__4); } /* L80: */ } berr[j] = s; /* Test stopping criterion. Continue iterating if 1) The residual BERR(J) is larger than machine epsilon, and 2) BERR(J) decreased by at least a factor of 2 during the last iteration, and 3) At most ITMAX iterations tried. */ if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) { /* Update solution and try again. */ zhetrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[1], n, info); zaxpy_(n, &c_b1, &work[1], &c__1, &x_ref(1, j), &c__1); lstres = berr[j]; ++count; goto L20; } /* Bound error from formula norm(X - XTRUE) / norm(X) .le. FERR = norm( abs(inv(A))* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) where norm(Z) is the magnitude of the largest component of Z inv(A) is the inverse of A abs(Z) is the componentwise absolute value of the matrix or vector Z NZ is the maximum number of nonzeros in any row of A, plus 1 EPS is machine epsilon The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) is incremented by SAFE1 if the i-th component of abs(A)*abs(X) + abs(B) is less than SAFE2. Use ZLACON to estimate the infinity-norm of the matrix inv(A) * diag(W), where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { if (rwork[i__] > safe2) { i__3 = i__; rwork[i__] = (d__1 = work[i__3].r, abs(d__1)) + (d__2 = d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__] ; } else { i__3 = i__; rwork[i__] = (d__1 = work[i__3].r, abs(d__1)) + (d__2 = d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__] + safe1; } /* L90: */ } kase = 0; L100: zlacon_(n, &work[*n + 1], &work[1], &ferr[j], &kase); if (kase != 0) { if (kase == 1) { /* Multiply by diag(W)*inv(A'). */ zhetrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[ 1], n, info); i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__; i__4 = i__; i__5 = i__; z__1.r = rwork[i__4] * work[i__5].r, z__1.i = rwork[i__4] * work[i__5].i; work[i__3].r = z__1.r, work[i__3].i = z__1.i; /* L110: */ } } else if (kase == 2) { /* Multiply by inv(A)*diag(W). */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__; i__4 = i__; i__5 = i__; z__1.r = rwork[i__4] * work[i__5].r, z__1.i = rwork[i__4] * work[i__5].i; work[i__3].r = z__1.r, work[i__3].i = z__1.i; /* L120: */ } zhetrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[ 1], n, info); } goto L100; } /* Normalize error. */ lstres = 0.; i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { /* Computing MAX */ i__3 = x_subscr(i__, j); d__3 = lstres, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x_ref(i__, j)), abs(d__2)); lstres = max(d__3,d__4); /* L130: */ } if (lstres != 0.) { ferr[j] /= lstres; } /* L140: */ } return 0; /* End of ZHERFS */ } /* zherfs_ */
/* Subroutine */ int dtptrs_(char *uplo, char *trans, char *diag, integer *n, integer *nrhs, doublereal *ap, doublereal *b, integer *ldb, integer * info) { /* System generated locals */ integer b_dim1, b_offset, i__1; /* Local variables */ integer j, jc; extern logical lsame_(char *, char *); logical upper; extern /* Subroutine */ int dtpsv_(char *, char *, char *, integer *, doublereal *, doublereal *, integer *), xerbla_(char *, integer *); logical nounit; /* -- LAPACK routine (version 3.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* DTPTRS solves a triangular system of the form */ /* A * X = B or A**T * X = B, */ /* where A is a triangular matrix of order N stored in packed format, */ /* and B is an N-by-NRHS matrix. A check is made to verify that A is */ /* nonsingular. */ /* Arguments */ /* ========= */ /* UPLO (input) CHARACTER*1 */ /* = 'U': A is upper triangular; */ /* = 'L': A is lower triangular. */ /* TRANS (input) CHARACTER*1 */ /* Specifies the form of the system of equations: */ /* = 'N': A * X = B (No transpose) */ /* = 'T': A**T * X = B (Transpose) */ /* = 'C': A**H * X = B (Conjugate transpose = Transpose) */ /* DIAG (input) CHARACTER*1 */ /* = 'N': A is non-unit triangular; */ /* = 'U': A is unit triangular. */ /* N (input) INTEGER */ /* The order of the matrix A. N >= 0. */ /* NRHS (input) INTEGER */ /* The number of right hand sides, i.e., the number of columns */ /* of the matrix B. NRHS >= 0. */ /* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ /* The upper or lower triangular matrix A, packed columnwise in */ /* a linear array. The j-th column of A is stored in the array */ /* AP as follows: */ /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ /* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */ /* On entry, the right hand side matrix B. */ /* On exit, if INFO = 0, the solution matrix X. */ /* LDB (input) INTEGER */ /* The leading dimension of the array B. LDB >= max(1,N). */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value */ /* > 0: if INFO = i, the i-th diagonal element of A is zero, */ /* indicating that the matrix is singular and the */ /* solutions X have not been computed. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input parameters. */ /* Parameter adjustments */ --ap; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); nounit = lsame_(diag, "N"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (! lsame_(trans, "N") && ! lsame_(trans, "T") && ! lsame_(trans, "C")) { *info = -2; } else if (! nounit && ! lsame_(diag, "U")) { *info = -3; } else if (*n < 0) { *info = -4; } else if (*nrhs < 0) { *info = -5; } else if (*ldb < max(1,*n)) { *info = -8; } if (*info != 0) { i__1 = -(*info); xerbla_("DTPTRS", &i__1); return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } /* Check for singularity. */ if (nounit) { if (upper) { jc = 1; i__1 = *n; for (*info = 1; *info <= i__1; ++(*info)) { if (ap[jc + *info - 1] == 0.) { return 0; } jc += *info; /* L10: */ } } else { jc = 1; i__1 = *n; for (*info = 1; *info <= i__1; ++(*info)) { if (ap[jc] == 0.) { return 0; } jc = jc + *n - *info + 1; /* L20: */ } } } *info = 0; /* Solve A * x = b or A' * x = b. */ i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { dtpsv_(uplo, trans, diag, n, &ap[1], &b[j * b_dim1 + 1], &c__1); /* L30: */ } return 0; /* End of DTPTRS */ } /* dtptrs_ */
/* Subroutine */ int zupgtr_(char *uplo, integer *n, doublecomplex *ap, doublecomplex *tau, doublecomplex *q, integer *ldq, doublecomplex * work, integer *info) { /* System generated locals */ integer q_dim1, q_offset, i__1, i__2, i__3, i__4; /* Local variables */ integer i__, j, ij; integer iinfo; logical upper; /* -- LAPACK routine (version 3.2) -- */ /* November 2006 */ /* Purpose */ /* ======= */ /* ZUPGTR generates a complex unitary matrix Q which is defined as the */ /* product of n-1 elementary reflectors H(i) of order n, as returned by */ /* ZHPTRD using packed storage: */ /* if UPLO = 'U', Q = H(n-1) . . . H(2) H(1), */ /* if UPLO = 'L', Q = H(1) H(2) . . . H(n-1). */ /* Arguments */ /* ========= */ /* UPLO (input) CHARACTER*1 */ /* = 'U': Upper triangular packed storage used in previous */ /* call to ZHPTRD; */ /* = 'L': Lower triangular packed storage used in previous */ /* call to ZHPTRD. */ /* N (input) INTEGER */ /* The order of the matrix Q. N >= 0. */ /* AP (input) COMPLEX*16 array, dimension (N*(N+1)/2) */ /* The vectors which define the elementary reflectors, as */ /* returned by ZHPTRD. */ /* TAU (input) COMPLEX*16 array, dimension (N-1) */ /* TAU(i) must contain the scalar factor of the elementary */ /* reflector H(i), as returned by ZHPTRD. */ /* Q (output) COMPLEX*16 array, dimension (LDQ,N) */ /* The N-by-N unitary matrix Q. */ /* LDQ (input) INTEGER */ /* The leading dimension of the array Q. LDQ >= max(1,N). */ /* WORK (workspace) COMPLEX*16 array, dimension (N-1) */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value */ /* ===================================================================== */ /* Test the input arguments */ /* Parameter adjustments */ --ap; --tau; q_dim1 = *ldq; q_offset = 1 + q_dim1; q -= q_offset; --work; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*ldq < max(1,*n)) { *info = -6; } if (*info != 0) { i__1 = -(*info); xerbla_("ZUPGTR", &i__1); return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } if (upper) { /* Q was determined by a call to ZHPTRD with UPLO = 'U' */ /* Unpack the vectors which define the elementary reflectors and */ /* set the last row and column of Q equal to those of the unit */ /* matrix */ ij = 2; i__1 = *n - 1; for (j = 1; j <= i__1; ++j) { i__2 = j - 1; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__ + j * q_dim1; i__4 = ij; q[i__3].r = ap[i__4].r, q[i__3].i = ap[i__4].i; ++ij; } ij += 2; i__2 = *n + j * q_dim1; q[i__2].r = 0., q[i__2].i = 0.; } i__1 = *n - 1; for (i__ = 1; i__ <= i__1; ++i__) { i__2 = i__ + *n * q_dim1; q[i__2].r = 0., q[i__2].i = 0.; } i__1 = *n + *n * q_dim1; q[i__1].r = 1., q[i__1].i = 0.; /* Generate Q(1:n-1,1:n-1) */ i__1 = *n - 1; i__2 = *n - 1; i__3 = *n - 1; zung2l_(&i__1, &i__2, &i__3, &q[q_offset], ldq, &tau[1], &work[1], & iinfo); } else { /* Q was determined by a call to ZHPTRD with UPLO = 'L'. */ /* Unpack the vectors which define the elementary reflectors and */ /* set the first row and column of Q equal to those of the unit */ /* matrix */ i__1 = q_dim1 + 1; q[i__1].r = 1., q[i__1].i = 0.; i__1 = *n; for (i__ = 2; i__ <= i__1; ++i__) { i__2 = i__ + q_dim1; q[i__2].r = 0., q[i__2].i = 0.; } ij = 3; i__1 = *n; for (j = 2; j <= i__1; ++j) { i__2 = j * q_dim1 + 1; q[i__2].r = 0., q[i__2].i = 0.; i__2 = *n; for (i__ = j + 1; i__ <= i__2; ++i__) { i__3 = i__ + j * q_dim1; i__4 = ij; q[i__3].r = ap[i__4].r, q[i__3].i = ap[i__4].i; ++ij; } ij += 2; } if (*n > 1) { /* Generate Q(2:n,2:n) */ i__1 = *n - 1; i__2 = *n - 1; i__3 = *n - 1; zung2r_(&i__1, &i__2, &i__3, &q[(q_dim1 << 1) + 2], ldq, &tau[1], &work[1], &iinfo); } } return 0; /* End of ZUPGTR */ } /* zupgtr_ */
/* Subroutine */ int sgghrd_(char *compq, char *compz, integer *n, integer * ilo, integer *ihi, real *a, integer *lda, real *b, integer *ldb, real *q, integer *ldq, real *z__, integer *ldz, integer *info) { /* -- LAPACK routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University September 30, 1994 Purpose ======= SGGHRD reduces a pair of real matrices (A,B) to generalized upper Hessenberg form using orthogonal transformations, where A is a general matrix and B is upper triangular: Q' * A * Z = H and Q' * B * Z = T, where H is upper Hessenberg, T is upper triangular, and Q and Z are orthogonal, and ' means transpose. The orthogonal matrices Q and Z are determined as products of Givens rotations. They may either be formed explicitly, or they may be postmultiplied into input matrices Q1 and Z1, so that Q1 * A * Z1' = (Q1*Q) * H * (Z1*Z)' Q1 * B * Z1' = (Q1*Q) * T * (Z1*Z)' Arguments ========= COMPQ (input) CHARACTER*1 = 'N': do not compute Q; = 'I': Q is initialized to the unit matrix, and the orthogonal matrix Q is returned; = 'V': Q must contain an orthogonal matrix Q1 on entry, and the product Q1*Q is returned. COMPZ (input) CHARACTER*1 = 'N': do not compute Z; = 'I': Z is initialized to the unit matrix, and the orthogonal matrix Z is returned; = 'V': Z must contain an orthogonal matrix Z1 on entry, and the product Z1*Z is returned. N (input) INTEGER The order of the matrices A and B. N >= 0. ILO (input) INTEGER IHI (input) INTEGER It is assumed that A is already upper triangular in rows and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally set by a previous call to SGGBAL; otherwise they should be set to 1 and N respectively. 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. A (input/output) REAL array, dimension (LDA, N) On entry, the N-by-N general matrix to be reduced. On exit, the upper triangle and the first subdiagonal of A are overwritten with the upper Hessenberg matrix H, and the rest is set to zero. LDA (input) INTEGER The leading dimension of the array A. LDA >= max(1,N). B (input/output) REAL array, dimension (LDB, N) On entry, the N-by-N upper triangular matrix B. On exit, the upper triangular matrix T = Q' B Z. The elements below the diagonal are set to zero. LDB (input) INTEGER The leading dimension of the array B. LDB >= max(1,N). Q (input/output) REAL array, dimension (LDQ, N) If COMPQ='N': Q is not referenced. If COMPQ='I': on entry, Q need not be set, and on exit it contains the orthogonal matrix Q, where Q' is the product of the Givens transformations which are applied to A and B on the left. If COMPQ='V': on entry, Q must contain an orthogonal matrix Q1, and on exit this is overwritten by Q1*Q. LDQ (input) INTEGER The leading dimension of the array Q. LDQ >= N if COMPQ='V' or 'I'; LDQ >= 1 otherwise. Z (input/output) REAL array, dimension (LDZ, N) If COMPZ='N': Z is not referenced. If COMPZ='I': on entry, Z need not be set, and on exit it contains the orthogonal matrix Z, which is the product of the Givens transformations which are applied to A and B on the right. If COMPZ='V': on entry, Z must contain an orthogonal matrix Z1, and on exit this is overwritten by Z1*Z. LDZ (input) INTEGER The leading dimension of the array Z. LDZ >= N if COMPZ='V' or 'I'; LDZ >= 1 otherwise. INFO (output) INTEGER = 0: successful exit. < 0: if INFO = -i, the i-th argument had an illegal value. Further Details =============== This routine reduces A to Hessenberg and B to triangular form by an unblocked reduction, as described in _Matrix_Computations_, by Golub and Van Loan (Johns Hopkins Press.) ===================================================================== Decode COMPQ Parameter adjustments */ /* Table of constant values */ static real c_b10 = 0.f; static real c_b11 = 1.f; static integer c__1 = 1; /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1, z_offset, i__1, i__2, i__3; /* Local variables */ static integer jcol; static real temp; static integer jrow; extern /* Subroutine */ int srot_(integer *, real *, integer *, real *, integer *, real *, real *); static real c__, s; extern logical lsame_(char *, char *); extern /* Subroutine */ int xerbla_(char *, integer *); static integer icompq; extern /* Subroutine */ int slaset_(char *, integer *, integer *, real *, real *, real *, integer *), slartg_(real *, real *, real * , real *, real *); static integer icompz; static logical ilq, ilz; #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1] #define b_ref(a_1,a_2) b[(a_2)*b_dim1 + a_1] #define q_ref(a_1,a_2) q[(a_2)*q_dim1 + a_1] #define z___ref(a_1,a_2) z__[(a_2)*z_dim1 + a_1] a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1 * 1; b -= b_offset; q_dim1 = *ldq; q_offset = 1 + q_dim1 * 1; q -= q_offset; z_dim1 = *ldz; z_offset = 1 + z_dim1 * 1; z__ -= z_offset; /* Function Body */ if (lsame_(compq, "N")) { ilq = FALSE_; icompq = 1; } else if (lsame_(compq, "V")) { ilq = TRUE_; icompq = 2; } else if (lsame_(compq, "I")) { ilq = TRUE_; icompq = 3; } else { icompq = 0; } /* Decode COMPZ */ if (lsame_(compz, "N")) { ilz = FALSE_; icompz = 1; } else if (lsame_(compz, "V")) { ilz = TRUE_; icompz = 2; } else if (lsame_(compz, "I")) { ilz = TRUE_; icompz = 3; } else { icompz = 0; } /* Test the input parameters. */ *info = 0; if (icompq <= 0) { *info = -1; } else if (icompz <= 0) { *info = -2; } else if (*n < 0) { *info = -3; } else if (*ilo < 1) { *info = -4; } else if (*ihi > *n || *ihi < *ilo - 1) { *info = -5; } else if (*lda < max(1,*n)) { *info = -7; } else if (*ldb < max(1,*n)) { *info = -9; } else if (ilq && *ldq < *n || *ldq < 1) { *info = -11; } else if (ilz && *ldz < *n || *ldz < 1) { *info = -13; } if (*info != 0) { i__1 = -(*info); xerbla_("SGGHRD", &i__1); return 0; } /* Initialize Q and Z if desired. */ if (icompq == 3) { slaset_("Full", n, n, &c_b10, &c_b11, &q[q_offset], ldq); } if (icompz == 3) { slaset_("Full", n, n, &c_b10, &c_b11, &z__[z_offset], ldz); } /* Quick return if possible */ if (*n <= 1) { return 0; } /* Zero out lower triangle of B */ i__1 = *n - 1; for (jcol = 1; jcol <= i__1; ++jcol) { i__2 = *n; for (jrow = jcol + 1; jrow <= i__2; ++jrow) { b_ref(jrow, jcol) = 0.f; /* L10: */ } /* L20: */ } /* Reduce A and B */ i__1 = *ihi - 2; for (jcol = *ilo; jcol <= i__1; ++jcol) { i__2 = jcol + 2; for (jrow = *ihi; jrow >= i__2; --jrow) { /* Step 1: rotate rows JROW-1, JROW to kill A(JROW,JCOL) */ temp = a_ref(jrow - 1, jcol); slartg_(&temp, &a_ref(jrow, jcol), &c__, &s, &a_ref(jrow - 1, jcol)); a_ref(jrow, jcol) = 0.f; i__3 = *n - jcol; srot_(&i__3, &a_ref(jrow - 1, jcol + 1), lda, &a_ref(jrow, jcol + 1), lda, &c__, &s); i__3 = *n + 2 - jrow; srot_(&i__3, &b_ref(jrow - 1, jrow - 1), ldb, &b_ref(jrow, jrow - 1), ldb, &c__, &s); if (ilq) { srot_(n, &q_ref(1, jrow - 1), &c__1, &q_ref(1, jrow), &c__1, & c__, &s); } /* Step 2: rotate columns JROW, JROW-1 to kill B(JROW,JROW-1) */ temp = b_ref(jrow, jrow); slartg_(&temp, &b_ref(jrow, jrow - 1), &c__, &s, &b_ref(jrow, jrow)); b_ref(jrow, jrow - 1) = 0.f; srot_(ihi, &a_ref(1, jrow), &c__1, &a_ref(1, jrow - 1), &c__1, & c__, &s); i__3 = jrow - 1; srot_(&i__3, &b_ref(1, jrow), &c__1, &b_ref(1, jrow - 1), &c__1, & c__, &s); if (ilz) { srot_(n, &z___ref(1, jrow), &c__1, &z___ref(1, jrow - 1), & c__1, &c__, &s); } /* L30: */ } /* L40: */ } return 0; /* End of SGGHRD */ } /* sgghrd_ */
/* Subroutine */ int chetf2_(char *uplo, integer *n, complex *a, integer *lda, integer *ipiv, integer *info) { /* -- LAPACK routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University June 30, 1999 Purpose ======= CHETF2 computes the factorization of a complex Hermitian matrix A using the Bunch-Kaufman diagonal pivoting method: A = U*D*U' or A = L*D*L' where U (or L) is a product of permutation and unit upper (lower) triangular matrices, U' is the conjugate transpose of U, and D is Hermitian and block diagonal with 1-by-1 and 2-by-2 diagonal blocks. This is the unblocked version of the algorithm, calling Level 2 BLAS. Arguments ========= UPLO (input) CHARACTER*1 Specifies whether the upper or lower triangular part of the Hermitian matrix A is stored: = 'U': Upper triangular = 'L': Lower triangular N (input) INTEGER The order of the matrix A. N >= 0. A (input/output) COMPLEX array, dimension (LDA,N) On entry, the Hermitian matrix A. If UPLO = 'U', the leading n-by-n upper triangular part of A contains the upper triangular part of the matrix A, and the strictly lower triangular part of A is not referenced. If UPLO = 'L', the leading n-by-n lower triangular part of A contains the lower triangular part of the matrix A, and the strictly upper triangular part of A is not referenced. On exit, the block diagonal matrix D and the multipliers used to obtain the factor U or L (see below for further details). LDA (input) INTEGER The leading dimension of the array A. LDA >= max(1,N). IPIV (output) INTEGER array, dimension (N) Details of the interchanges and the block structure of D. If IPIV(k) > 0, then rows and columns k and IPIV(k) were interchanged and D(k,k) is a 1-by-1 diagonal block. If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. INFO (output) INTEGER = 0: successful exit < 0: if INFO = -k, the k-th argument had an illegal value > 0: if INFO = k, D(k,k) is exactly zero. The factorization has been completed, but the block diagonal matrix D is exactly singular, and division by zero will occur if it is used to solve a system of equations. Further Details =============== 1-96 - Based on modifications by J. Lewis, Boeing Computer Services Company A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA If UPLO = 'U', then A = U*D*U', where U = P(n)*U(n)* ... *P(k)U(k)* ..., i.e., U is a product of terms P(k)*U(k), where k decreases from n to 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as defined by IPIV(k), and U(k) is a unit upper triangular matrix, such that if the diagonal block D(k) is of order s (s = 1 or 2), then ( I v 0 ) k-s U(k) = ( 0 I 0 ) s ( 0 0 I ) n-k k-s s n-k If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), and A(k,k), and v overwrites A(1:k-2,k-1:k). If UPLO = 'L', then A = L*D*L', where L = P(1)*L(1)* ... *P(k)*L(k)* ..., i.e., L is a product of terms P(k)*L(k), where k increases from 1 to n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as defined by IPIV(k), and L(k) is a unit lower triangular matrix, such that if the diagonal block D(k) is of order s (s = 1 or 2), then ( I 0 0 ) k-1 L(k) = ( 0 I 0 ) s ( 0 v I ) n-k-s+1 k-1 s n-k-s+1 If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). ===================================================================== Test the input parameters. Parameter adjustments */ /* Table of constant values */ static integer c__1 = 1; /* System generated locals */ integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6; real r__1, r__2, r__3, r__4; complex q__1, q__2, q__3, q__4, q__5, q__6; /* Builtin functions */ double sqrt(doublereal), r_imag(complex *); void r_cnjg(complex *, complex *); /* Local variables */ extern /* Subroutine */ int cher_(char *, integer *, real *, complex *, integer *, complex *, integer *); static integer imax, jmax; static real d__; static integer i__, j, k; static complex t; static real alpha; extern logical lsame_(char *, char *); extern /* Subroutine */ int cswap_(integer *, complex *, integer *, complex *, integer *); static integer kstep; static logical upper; static real r1, d11; static complex d12; static real d22; static complex d21; extern doublereal slapy2_(real *, real *); static integer kk, kp; static real absakk; static complex wk; extern integer icamax_(integer *, complex *, integer *); static real tt; extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer *), xerbla_(char *, integer *); static real colmax, rowmax; static complex wkm1, wkp1; #define a_subscr(a_1,a_2) (a_2)*a_dim1 + a_1 #define a_ref(a_1,a_2) a[a_subscr(a_1,a_2)] a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; --ipiv; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*lda < max(1,*n)) { *info = -4; } if (*info != 0) { i__1 = -(*info); xerbla_("CHETF2", &i__1); return 0; } /* Initialize ALPHA for use in choosing pivot block size. */ alpha = (sqrt(17.f) + 1.f) / 8.f; if (upper) { /* Factorize A as U*D*U' using the upper triangle of A K is the main loop index, decreasing from N to 1 in steps of 1 or 2 */ k = *n; L10: /* If K < 1, exit from loop */ if (k < 1) { goto L90; } kstep = 1; /* Determine rows and columns to be interchanged and whether a 1-by-1 or 2-by-2 pivot block will be used */ i__1 = a_subscr(k, k); absakk = (r__1 = a[i__1].r, dabs(r__1)); /* IMAX is the row-index of the largest off-diagonal element in column K, and COLMAX is its absolute value */ if (k > 1) { i__1 = k - 1; imax = icamax_(&i__1, &a_ref(1, k), &c__1); i__1 = a_subscr(imax, k); colmax = (r__1 = a[i__1].r, dabs(r__1)) + (r__2 = r_imag(&a_ref( imax, k)), dabs(r__2)); } else { colmax = 0.f; } if (dmax(absakk,colmax) == 0.f) { /* Column K is zero: set INFO and continue */ if (*info == 0) { *info = k; } kp = k; i__1 = a_subscr(k, k); i__2 = a_subscr(k, k); r__1 = a[i__2].r; a[i__1].r = r__1, a[i__1].i = 0.f; } else { if (absakk >= alpha * colmax) { /* no interchange, use 1-by-1 pivot block */ kp = k; } else { /* JMAX is the column-index of the largest off-diagonal element in row IMAX, and ROWMAX is its absolute value */ i__1 = k - imax; jmax = imax + icamax_(&i__1, &a_ref(imax, imax + 1), lda); i__1 = a_subscr(imax, jmax); rowmax = (r__1 = a[i__1].r, dabs(r__1)) + (r__2 = r_imag(& a_ref(imax, jmax)), dabs(r__2)); if (imax > 1) { i__1 = imax - 1; jmax = icamax_(&i__1, &a_ref(1, imax), &c__1); /* Computing MAX */ i__1 = a_subscr(jmax, imax); r__3 = rowmax, r__4 = (r__1 = a[i__1].r, dabs(r__1)) + ( r__2 = r_imag(&a_ref(jmax, imax)), dabs(r__2)); rowmax = dmax(r__3,r__4); } if (absakk >= alpha * colmax * (colmax / rowmax)) { /* no interchange, use 1-by-1 pivot block */ kp = k; } else /* if(complicated condition) */ { i__1 = a_subscr(imax, imax); if ((r__1 = a[i__1].r, dabs(r__1)) >= alpha * rowmax) { /* interchange rows and columns K and IMAX, use 1-by-1 pivot block */ kp = imax; } else { /* interchange rows and columns K-1 and IMAX, use 2-by-2 pivot block */ kp = imax; kstep = 2; } } } kk = k - kstep + 1; if (kp != kk) { /* Interchange rows and columns KK and KP in the leading submatrix A(1:k,1:k) */ i__1 = kp - 1; cswap_(&i__1, &a_ref(1, kk), &c__1, &a_ref(1, kp), &c__1); i__1 = kk - 1; for (j = kp + 1; j <= i__1; ++j) { r_cnjg(&q__1, &a_ref(j, kk)); t.r = q__1.r, t.i = q__1.i; i__2 = a_subscr(j, kk); r_cnjg(&q__1, &a_ref(kp, j)); a[i__2].r = q__1.r, a[i__2].i = q__1.i; i__2 = a_subscr(kp, j); a[i__2].r = t.r, a[i__2].i = t.i; /* L20: */ } i__1 = a_subscr(kp, kk); r_cnjg(&q__1, &a_ref(kp, kk)); a[i__1].r = q__1.r, a[i__1].i = q__1.i; i__1 = a_subscr(kk, kk); r1 = a[i__1].r; i__1 = a_subscr(kk, kk); i__2 = a_subscr(kp, kp); r__1 = a[i__2].r; a[i__1].r = r__1, a[i__1].i = 0.f; i__1 = a_subscr(kp, kp); a[i__1].r = r1, a[i__1].i = 0.f; if (kstep == 2) { i__1 = a_subscr(k, k); i__2 = a_subscr(k, k); r__1 = a[i__2].r; a[i__1].r = r__1, a[i__1].i = 0.f; i__1 = a_subscr(k - 1, k); t.r = a[i__1].r, t.i = a[i__1].i; i__1 = a_subscr(k - 1, k); i__2 = a_subscr(kp, k); a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i; i__1 = a_subscr(kp, k); a[i__1].r = t.r, a[i__1].i = t.i; } } else { i__1 = a_subscr(k, k); i__2 = a_subscr(k, k); r__1 = a[i__2].r; a[i__1].r = r__1, a[i__1].i = 0.f; if (kstep == 2) { i__1 = a_subscr(k - 1, k - 1); i__2 = a_subscr(k - 1, k - 1); r__1 = a[i__2].r; a[i__1].r = r__1, a[i__1].i = 0.f; } } /* Update the leading submatrix */ if (kstep == 1) { /* 1-by-1 pivot block D(k): column k now holds W(k) = U(k)*D(k) where U(k) is the k-th column of U Perform a rank-1 update of A(1:k-1,1:k-1) as A := A - U(k)*D(k)*U(k)' = A - W(k)*1/D(k)*W(k)' */ i__1 = a_subscr(k, k); r1 = 1.f / a[i__1].r; i__1 = k - 1; r__1 = -r1; cher_(uplo, &i__1, &r__1, &a_ref(1, k), &c__1, &a[a_offset], lda); /* Store U(k) in column k */ i__1 = k - 1; csscal_(&i__1, &r1, &a_ref(1, k), &c__1); } else { /* 2-by-2 pivot block D(k): columns k and k-1 now hold ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) where U(k) and U(k-1) are the k-th and (k-1)-th columns of U Perform a rank-2 update of A(1:k-2,1:k-2) as A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )' = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )' */ if (k > 2) { i__1 = a_subscr(k - 1, k); r__1 = a[i__1].r; r__2 = r_imag(&a_ref(k - 1, k)); d__ = slapy2_(&r__1, &r__2); i__1 = a_subscr(k - 1, k - 1); d22 = a[i__1].r / d__; i__1 = a_subscr(k, k); d11 = a[i__1].r / d__; tt = 1.f / (d11 * d22 - 1.f); i__1 = a_subscr(k - 1, k); q__1.r = a[i__1].r / d__, q__1.i = a[i__1].i / d__; d12.r = q__1.r, d12.i = q__1.i; d__ = tt / d__; for (j = k - 2; j >= 1; --j) { i__1 = a_subscr(j, k - 1); q__3.r = d11 * a[i__1].r, q__3.i = d11 * a[i__1].i; r_cnjg(&q__5, &d12); i__2 = a_subscr(j, k); q__4.r = q__5.r * a[i__2].r - q__5.i * a[i__2].i, q__4.i = q__5.r * a[i__2].i + q__5.i * a[i__2] .r; q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i; q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i; wkm1.r = q__1.r, wkm1.i = q__1.i; i__1 = a_subscr(j, k); q__3.r = d22 * a[i__1].r, q__3.i = d22 * a[i__1].i; i__2 = a_subscr(j, k - 1); q__4.r = d12.r * a[i__2].r - d12.i * a[i__2].i, q__4.i = d12.r * a[i__2].i + d12.i * a[i__2] .r; q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i; q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i; wk.r = q__1.r, wk.i = q__1.i; for (i__ = j; i__ >= 1; --i__) { i__1 = a_subscr(i__, j); i__2 = a_subscr(i__, j); i__3 = a_subscr(i__, k); r_cnjg(&q__4, &wk); q__3.r = a[i__3].r * q__4.r - a[i__3].i * q__4.i, q__3.i = a[i__3].r * q__4.i + a[i__3].i * q__4.r; q__2.r = a[i__2].r - q__3.r, q__2.i = a[i__2].i - q__3.i; i__4 = a_subscr(i__, k - 1); r_cnjg(&q__6, &wkm1); q__5.r = a[i__4].r * q__6.r - a[i__4].i * q__6.i, q__5.i = a[i__4].r * q__6.i + a[i__4].i * q__6.r; q__1.r = q__2.r - q__5.r, q__1.i = q__2.i - q__5.i; a[i__1].r = q__1.r, a[i__1].i = q__1.i; /* L30: */ } i__1 = a_subscr(j, k); a[i__1].r = wk.r, a[i__1].i = wk.i; i__1 = a_subscr(j, k - 1); a[i__1].r = wkm1.r, a[i__1].i = wkm1.i; i__1 = a_subscr(j, j); i__2 = a_subscr(j, j); r__1 = a[i__2].r; q__1.r = r__1, q__1.i = 0.f; a[i__1].r = q__1.r, a[i__1].i = q__1.i; /* L40: */ } } } } /* Store details of the interchanges in IPIV */ if (kstep == 1) { ipiv[k] = kp; } else { ipiv[k] = -kp; ipiv[k - 1] = -kp; } /* Decrease K and return to the start of the main loop */ k -= kstep; goto L10; } else { /* Factorize A as L*D*L' using the lower triangle of A K is the main loop index, increasing from 1 to N in steps of 1 or 2 */ k = 1; L50: /* If K > N, exit from loop */ if (k > *n) { goto L90; } kstep = 1; /* Determine rows and columns to be interchanged and whether a 1-by-1 or 2-by-2 pivot block will be used */ i__1 = a_subscr(k, k); absakk = (r__1 = a[i__1].r, dabs(r__1)); /* IMAX is the row-index of the largest off-diagonal element in column K, and COLMAX is its absolute value */ if (k < *n) { i__1 = *n - k; imax = k + icamax_(&i__1, &a_ref(k + 1, k), &c__1); i__1 = a_subscr(imax, k); colmax = (r__1 = a[i__1].r, dabs(r__1)) + (r__2 = r_imag(&a_ref( imax, k)), dabs(r__2)); } else { colmax = 0.f; } if (dmax(absakk,colmax) == 0.f) { /* Column K is zero: set INFO and continue */ if (*info == 0) { *info = k; } kp = k; i__1 = a_subscr(k, k); i__2 = a_subscr(k, k); r__1 = a[i__2].r; a[i__1].r = r__1, a[i__1].i = 0.f; } else { if (absakk >= alpha * colmax) { /* no interchange, use 1-by-1 pivot block */ kp = k; } else { /* JMAX is the column-index of the largest off-diagonal element in row IMAX, and ROWMAX is its absolute value */ i__1 = imax - k; jmax = k - 1 + icamax_(&i__1, &a_ref(imax, k), lda); i__1 = a_subscr(imax, jmax); rowmax = (r__1 = a[i__1].r, dabs(r__1)) + (r__2 = r_imag(& a_ref(imax, jmax)), dabs(r__2)); if (imax < *n) { i__1 = *n - imax; jmax = imax + icamax_(&i__1, &a_ref(imax + 1, imax), & c__1); /* Computing MAX */ i__1 = a_subscr(jmax, imax); r__3 = rowmax, r__4 = (r__1 = a[i__1].r, dabs(r__1)) + ( r__2 = r_imag(&a_ref(jmax, imax)), dabs(r__2)); rowmax = dmax(r__3,r__4); } if (absakk >= alpha * colmax * (colmax / rowmax)) { /* no interchange, use 1-by-1 pivot block */ kp = k; } else /* if(complicated condition) */ { i__1 = a_subscr(imax, imax); if ((r__1 = a[i__1].r, dabs(r__1)) >= alpha * rowmax) { /* interchange rows and columns K and IMAX, use 1-by-1 pivot block */ kp = imax; } else { /* interchange rows and columns K+1 and IMAX, use 2-by-2 pivot block */ kp = imax; kstep = 2; } } } kk = k + kstep - 1; if (kp != kk) { /* Interchange rows and columns KK and KP in the trailing submatrix A(k:n,k:n) */ if (kp < *n) { i__1 = *n - kp; cswap_(&i__1, &a_ref(kp + 1, kk), &c__1, &a_ref(kp + 1, kp), &c__1); } i__1 = kp - 1; for (j = kk + 1; j <= i__1; ++j) { r_cnjg(&q__1, &a_ref(j, kk)); t.r = q__1.r, t.i = q__1.i; i__2 = a_subscr(j, kk); r_cnjg(&q__1, &a_ref(kp, j)); a[i__2].r = q__1.r, a[i__2].i = q__1.i; i__2 = a_subscr(kp, j); a[i__2].r = t.r, a[i__2].i = t.i; /* L60: */ } i__1 = a_subscr(kp, kk); r_cnjg(&q__1, &a_ref(kp, kk)); a[i__1].r = q__1.r, a[i__1].i = q__1.i; i__1 = a_subscr(kk, kk); r1 = a[i__1].r; i__1 = a_subscr(kk, kk); i__2 = a_subscr(kp, kp); r__1 = a[i__2].r; a[i__1].r = r__1, a[i__1].i = 0.f; i__1 = a_subscr(kp, kp); a[i__1].r = r1, a[i__1].i = 0.f; if (kstep == 2) { i__1 = a_subscr(k, k); i__2 = a_subscr(k, k); r__1 = a[i__2].r; a[i__1].r = r__1, a[i__1].i = 0.f; i__1 = a_subscr(k + 1, k); t.r = a[i__1].r, t.i = a[i__1].i; i__1 = a_subscr(k + 1, k); i__2 = a_subscr(kp, k); a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i; i__1 = a_subscr(kp, k); a[i__1].r = t.r, a[i__1].i = t.i; } } else { i__1 = a_subscr(k, k); i__2 = a_subscr(k, k); r__1 = a[i__2].r; a[i__1].r = r__1, a[i__1].i = 0.f; if (kstep == 2) { i__1 = a_subscr(k + 1, k + 1); i__2 = a_subscr(k + 1, k + 1); r__1 = a[i__2].r; a[i__1].r = r__1, a[i__1].i = 0.f; } } /* Update the trailing submatrix */ if (kstep == 1) { /* 1-by-1 pivot block D(k): column k now holds W(k) = L(k)*D(k) where L(k) is the k-th column of L */ if (k < *n) { /* Perform a rank-1 update of A(k+1:n,k+1:n) as A := A - L(k)*D(k)*L(k)' = A - W(k)*(1/D(k))*W(k)' */ i__1 = a_subscr(k, k); r1 = 1.f / a[i__1].r; i__1 = *n - k; r__1 = -r1; cher_(uplo, &i__1, &r__1, &a_ref(k + 1, k), &c__1, &a_ref( k + 1, k + 1), lda); /* Store L(k) in column K */ i__1 = *n - k; csscal_(&i__1, &r1, &a_ref(k + 1, k), &c__1); } } else { /* 2-by-2 pivot block D(k) */ if (k < *n - 1) { /* Perform a rank-2 update of A(k+2:n,k+2:n) as A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )' = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )' where L(k) and L(k+1) are the k-th and (k+1)-th columns of L */ i__1 = a_subscr(k + 1, k); r__1 = a[i__1].r; r__2 = r_imag(&a_ref(k + 1, k)); d__ = slapy2_(&r__1, &r__2); i__1 = a_subscr(k + 1, k + 1); d11 = a[i__1].r / d__; i__1 = a_subscr(k, k); d22 = a[i__1].r / d__; tt = 1.f / (d11 * d22 - 1.f); i__1 = a_subscr(k + 1, k); q__1.r = a[i__1].r / d__, q__1.i = a[i__1].i / d__; d21.r = q__1.r, d21.i = q__1.i; d__ = tt / d__; i__1 = *n; for (j = k + 2; j <= i__1; ++j) { i__2 = a_subscr(j, k); q__3.r = d11 * a[i__2].r, q__3.i = d11 * a[i__2].i; i__3 = a_subscr(j, k + 1); q__4.r = d21.r * a[i__3].r - d21.i * a[i__3].i, q__4.i = d21.r * a[i__3].i + d21.i * a[i__3] .r; q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i; q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i; wk.r = q__1.r, wk.i = q__1.i; i__2 = a_subscr(j, k + 1); q__3.r = d22 * a[i__2].r, q__3.i = d22 * a[i__2].i; r_cnjg(&q__5, &d21); i__3 = a_subscr(j, k); q__4.r = q__5.r * a[i__3].r - q__5.i * a[i__3].i, q__4.i = q__5.r * a[i__3].i + q__5.i * a[i__3] .r; q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i; q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i; wkp1.r = q__1.r, wkp1.i = q__1.i; i__2 = *n; for (i__ = j; i__ <= i__2; ++i__) { i__3 = a_subscr(i__, j); i__4 = a_subscr(i__, j); i__5 = a_subscr(i__, k); r_cnjg(&q__4, &wk); q__3.r = a[i__5].r * q__4.r - a[i__5].i * q__4.i, q__3.i = a[i__5].r * q__4.i + a[i__5].i * q__4.r; q__2.r = a[i__4].r - q__3.r, q__2.i = a[i__4].i - q__3.i; i__6 = a_subscr(i__, k + 1); r_cnjg(&q__6, &wkp1); q__5.r = a[i__6].r * q__6.r - a[i__6].i * q__6.i, q__5.i = a[i__6].r * q__6.i + a[i__6].i * q__6.r; q__1.r = q__2.r - q__5.r, q__1.i = q__2.i - q__5.i; a[i__3].r = q__1.r, a[i__3].i = q__1.i; /* L70: */ } i__2 = a_subscr(j, k); a[i__2].r = wk.r, a[i__2].i = wk.i; i__2 = a_subscr(j, k + 1); a[i__2].r = wkp1.r, a[i__2].i = wkp1.i; i__2 = a_subscr(j, j); i__3 = a_subscr(j, j); r__1 = a[i__3].r; q__1.r = r__1, q__1.i = 0.f; a[i__2].r = q__1.r, a[i__2].i = q__1.i; /* L80: */ } } } } /* Store details of the interchanges in IPIV */ if (kstep == 1) { ipiv[k] = kp; } else { ipiv[k] = -kp; ipiv[k + 1] = -kp; } /* Increase K and return to the start of the main loop */ k += kstep; goto L50; } L90: return 0; /* End of CHETF2 */ } /* chetf2_ */
/* Subroutine */ int dlatrs_(char *uplo, char *trans, char *diag, char * normin, integer *n, doublereal *a, integer *lda, doublereal *x, doublereal *scale, doublereal *cnorm, integer *info) { /* System generated locals */ integer a_dim1, a_offset, i__1, i__2, i__3; doublereal d__1, d__2, d__3; /* Local variables */ integer i__, j; doublereal xj, rec, tjj; integer jinc; extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *, integer *); doublereal xbnd; integer imax; doublereal tmax, tjjs, xmax, grow, sumj; extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, integer *); extern logical lsame_(char *, char *); doublereal tscal, uscal; extern doublereal dasum_(integer *, doublereal *, integer *); integer jlast; extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *, integer *, doublereal *, integer *); logical upper; extern /* Subroutine */ int dtrsv_(char *, char *, char *, integer *, doublereal *, integer *, doublereal *, integer *); extern doublereal dlamch_(char *); extern integer idamax_(integer *, doublereal *, integer *); extern /* Subroutine */ int xerbla_(char *, integer *); doublereal bignum; logical notran; integer jfirst; doublereal smlnum; logical nounit; /* -- LAPACK auxiliary routine (version 3.2) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* DLATRS solves one of the triangular systems */ /* A *x = s*b or A'*x = s*b */ /* with scaling to prevent overflow. Here A is an upper or lower */ /* triangular matrix, A' denotes the transpose of A, x and b are */ /* n-element vectors, and s is a scaling factor, usually less than */ /* or equal to 1, chosen so that the components of x will be less than */ /* the overflow threshold. If the unscaled problem will not cause */ /* overflow, the Level 2 BLAS routine DTRSV is called. If the matrix A */ /* is singular (A(j,j) = 0 for some j), then s is set to 0 and a */ /* non-trivial solution to A*x = 0 is returned. */ /* Arguments */ /* ========= */ /* UPLO (input) CHARACTER*1 */ /* Specifies whether the matrix A is upper or lower triangular. */ /* = 'U': Upper triangular */ /* = 'L': Lower triangular */ /* TRANS (input) CHARACTER*1 */ /* Specifies the operation applied to A. */ /* = 'N': Solve A * x = s*b (No transpose) */ /* = 'T': Solve A'* x = s*b (Transpose) */ /* = 'C': Solve A'* x = s*b (Conjugate transpose = Transpose) */ /* DIAG (input) CHARACTER*1 */ /* Specifies whether or not the matrix A is unit triangular. */ /* = 'N': Non-unit triangular */ /* = 'U': Unit triangular */ /* NORMIN (input) CHARACTER*1 */ /* Specifies whether CNORM has been set or not. */ /* = 'Y': CNORM contains the column norms on entry */ /* = 'N': CNORM is not set on entry. On exit, the norms will */ /* be computed and stored in CNORM. */ /* N (input) INTEGER */ /* The order of the matrix A. N >= 0. */ /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */ /* The triangular matrix A. If UPLO = 'U', the leading n by n */ /* upper triangular part of the array A contains the upper */ /* triangular matrix, and the strictly lower triangular part of */ /* A is not referenced. If UPLO = 'L', the leading n by n lower */ /* triangular part of the array A contains the lower triangular */ /* matrix, and the strictly upper triangular part of A is not */ /* referenced. If DIAG = 'U', the diagonal elements of A are */ /* also not referenced and are assumed to be 1. */ /* LDA (input) INTEGER */ /* The leading dimension of the array A. LDA >= max (1,N). */ /* X (input/output) DOUBLE PRECISION array, dimension (N) */ /* On entry, the right hand side b of the triangular system. */ /* On exit, X is overwritten by the solution vector x. */ /* SCALE (output) DOUBLE PRECISION */ /* The scaling factor s for the triangular system */ /* A * x = s*b or A'* x = s*b. */ /* If SCALE = 0, the matrix A is singular or badly scaled, and */ /* the vector x is an exact or approximate solution to A*x = 0. */ /* CNORM (input or output) DOUBLE PRECISION array, dimension (N) */ /* If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */ /* contains the norm of the off-diagonal part of the j-th column */ /* of A. If TRANS = 'N', CNORM(j) must be greater than or equal */ /* to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */ /* must be greater than or equal to the 1-norm. */ /* If NORMIN = 'N', CNORM is an output argument and CNORM(j) */ /* returns the 1-norm of the offdiagonal part of the j-th column */ /* of A. */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -k, the k-th argument had an illegal value */ /* Further Details */ /* ======= ======= */ /* A rough bound on x is computed; if that is less than overflow, DTRSV */ /* is called, otherwise, specific code is used which checks for possible */ /* overflow or divide-by-zero at every operation. */ /* A columnwise scheme is used for solving A*x = b. The basic algorithm */ /* if A is lower triangular is */ /* x[1:n] := b[1:n] */ /* for j = 1, ..., n */ /* x(j) := x(j) / A(j,j) */ /* x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */ /* end */ /* Define bounds on the components of x after j iterations of the loop: */ /* M(j) = bound on x[1:j] */ /* G(j) = bound on x[j+1:n] */ /* Initially, let M(0) = 0 and G(0) = max{x(i), i=1,...,n}. */ /* Then for iteration j+1 we have */ /* M(j+1) <= G(j) / | A(j+1,j+1) | */ /* G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */ /* <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */ /* where CNORM(j+1) is greater than or equal to the infinity-norm of */ /* column j+1 of A, not counting the diagonal. Hence */ /* G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */ /* 1<=i<=j */ /* and */ /* |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */ /* 1<=i< j */ /* Since |x(j)| <= M(j), we use the Level 2 BLAS routine DTRSV if the */ /* reciprocal of the largest M(j), j=1,..,n, is larger than */ /* max(underflow, 1/overflow). */ /* The bound on x(j) is also used to determine when a step in the */ /* columnwise method can be performed without fear of overflow. If */ /* the computed bound is greater than a large constant, x is scaled to */ /* prevent overflow, but if the bound overflows, x is set to 0, x(j) to */ /* 1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */ /* Similarly, a row-wise scheme is used to solve A'*x = b. The basic */ /* algorithm for A upper triangular is */ /* for j = 1, ..., n */ /* x(j) := ( b(j) - A[1:j-1,j]' * x[1:j-1] ) / A(j,j) */ /* end */ /* We simultaneously compute two bounds */ /* G(j) = bound on ( b(i) - A[1:i-1,i]' * x[1:i-1] ), 1<=i<=j */ /* M(j) = bound on x(i), 1<=i<=j */ /* The initial values are G(0) = 0, M(0) = max{b(i), i=1,..,n}, and we */ /* add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */ /* Then the bound on x(j) is */ /* M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */ /* <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */ /* 1<=i<=j */ /* and we can safely call DTRSV if 1/M(n) and 1/G(n) are both greater */ /* than max(underflow, 1/overflow). */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; --x; --cnorm; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); notran = lsame_(trans, "N"); nounit = lsame_(diag, "N"); /* Test the input parameters. */ if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (! notran && ! lsame_(trans, "T") && ! lsame_(trans, "C")) { *info = -2; } else if (! nounit && ! lsame_(diag, "U")) { *info = -3; } else if (! lsame_(normin, "Y") && ! lsame_(normin, "N")) { *info = -4; } else if (*n < 0) { *info = -5; } else if (*lda < max(1,*n)) { *info = -7; } if (*info != 0) { i__1 = -(*info); xerbla_("DLATRS", &i__1); return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } /* Determine machine dependent parameters to control overflow. */ smlnum = dlamch_("Safe minimum") / dlamch_("Precision"); bignum = 1. / smlnum; *scale = 1.; if (lsame_(normin, "N")) { /* Compute the 1-norm of each column, not including the diagonal. */ if (upper) { /* A is upper triangular. */ i__1 = *n; for (j = 1; j <= i__1; ++j) { i__2 = j - 1; cnorm[j] = dasum_(&i__2, &a[j * a_dim1 + 1], &c__1); /* L10: */ } } else { /* A is lower triangular. */ i__1 = *n - 1; for (j = 1; j <= i__1; ++j) { i__2 = *n - j; cnorm[j] = dasum_(&i__2, &a[j + 1 + j * a_dim1], &c__1); /* L20: */ } cnorm[*n] = 0.; } } /* Scale the column norms by TSCAL if the maximum element in CNORM is */ /* greater than BIGNUM. */ imax = idamax_(n, &cnorm[1], &c__1); tmax = cnorm[imax]; if (tmax <= bignum) { tscal = 1.; } else { tscal = 1. / (smlnum * tmax); dscal_(n, &tscal, &cnorm[1], &c__1); } /* Compute a bound on the computed solution vector to see if the */ /* Level 2 BLAS routine DTRSV can be used. */ j = idamax_(n, &x[1], &c__1); xmax = (d__1 = x[j], abs(d__1)); xbnd = xmax; if (notran) { /* Compute the growth in A * x = b. */ if (upper) { jfirst = *n; jlast = 1; jinc = -1; } else { jfirst = 1; jlast = *n; jinc = 1; } if (tscal != 1.) { grow = 0.; goto L50; } if (nounit) { /* A is non-unit triangular. */ /* Compute GROW = 1/G(j) and XBND = 1/M(j). */ /* Initially, G(0) = max{x(i), i=1,...,n}. */ grow = 1. / max(xbnd,smlnum); xbnd = grow; i__1 = jlast; i__2 = jinc; for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) { /* Exit the loop if the growth factor is too small. */ if (grow <= smlnum) { goto L50; } /* M(j) = G(j-1) / abs(A(j,j)) */ tjj = (d__1 = a[j + j * a_dim1], abs(d__1)); /* Computing MIN */ d__1 = xbnd, d__2 = min(1.,tjj) * grow; xbnd = min(d__1,d__2); if (tjj + cnorm[j] >= smlnum) { /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */ grow *= tjj / (tjj + cnorm[j]); } else { /* G(j) could overflow, set GROW to 0. */ grow = 0.; } /* L30: */ } grow = xbnd; } else { /* A is unit triangular. */ /* Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */ /* Computing MIN */ d__1 = 1., d__2 = 1. / max(xbnd,smlnum); grow = min(d__1,d__2); i__2 = jlast; i__1 = jinc; for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) { /* Exit the loop if the growth factor is too small. */ if (grow <= smlnum) { goto L50; } /* G(j) = G(j-1)*( 1 + CNORM(j) ) */ grow *= 1. / (cnorm[j] + 1.); /* L40: */ } } L50: ; } else { /* Compute the growth in A' * x = b. */ if (upper) { jfirst = 1; jlast = *n; jinc = 1; } else { jfirst = *n; jlast = 1; jinc = -1; } if (tscal != 1.) { grow = 0.; goto L80; } if (nounit) { /* A is non-unit triangular. */ /* Compute GROW = 1/G(j) and XBND = 1/M(j). */ /* Initially, M(0) = max{x(i), i=1,...,n}. */ grow = 1. / max(xbnd,smlnum); xbnd = grow; i__1 = jlast; i__2 = jinc; for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) { /* Exit the loop if the growth factor is too small. */ if (grow <= smlnum) { goto L80; } /* G(j) = max( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */ xj = cnorm[j] + 1.; /* Computing MIN */ d__1 = grow, d__2 = xbnd / xj; grow = min(d__1,d__2); /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */ tjj = (d__1 = a[j + j * a_dim1], abs(d__1)); if (xj > tjj) { xbnd *= tjj / xj; } /* L60: */ } grow = min(grow,xbnd); } else { /* A is unit triangular. */ /* Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */ /* Computing MIN */ d__1 = 1., d__2 = 1. / max(xbnd,smlnum); grow = min(d__1,d__2); i__2 = jlast; i__1 = jinc; for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) { /* Exit the loop if the growth factor is too small. */ if (grow <= smlnum) { goto L80; } /* G(j) = ( 1 + CNORM(j) )*G(j-1) */ xj = cnorm[j] + 1.; grow /= xj; /* L70: */ } } L80: ; } if (grow * tscal > smlnum) { /* Use the Level 2 BLAS solve if the reciprocal of the bound on */ /* elements of X is not too small. */ dtrsv_(uplo, trans, diag, n, &a[a_offset], lda, &x[1], &c__1); } else { /* Use a Level 1 BLAS solve, scaling intermediate results. */ if (xmax > bignum) { /* Scale X so that its components are less than or equal to */ /* BIGNUM in absolute value. */ *scale = bignum / xmax; dscal_(n, scale, &x[1], &c__1); xmax = bignum; } if (notran) { /* Solve A * x = b */ i__1 = jlast; i__2 = jinc; for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) { /* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */ xj = (d__1 = x[j], abs(d__1)); if (nounit) { tjjs = a[j + j * a_dim1] * tscal; } else { tjjs = tscal; if (tscal == 1.) { goto L100; } } tjj = abs(tjjs); if (tjj > smlnum) { /* abs(A(j,j)) > SMLNUM: */ if (tjj < 1.) { if (xj > tjj * bignum) { /* Scale x by 1/b(j). */ rec = 1. / xj; dscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } } x[j] /= tjjs; xj = (d__1 = x[j], abs(d__1)); } else if (tjj > 0.) { /* 0 < abs(A(j,j)) <= SMLNUM: */ if (xj > tjj * bignum) { /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */ /* to avoid overflow when dividing by A(j,j). */ rec = tjj * bignum / xj; if (cnorm[j] > 1.) { /* Scale by 1/CNORM(j) to avoid overflow when */ /* multiplying x(j) times column j. */ rec /= cnorm[j]; } dscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } x[j] /= tjjs; xj = (d__1 = x[j], abs(d__1)); } else { /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */ /* scale = 0, and compute a solution to A*x = 0. */ i__3 = *n; for (i__ = 1; i__ <= i__3; ++i__) { x[i__] = 0.; /* L90: */ } x[j] = 1.; xj = 1.; *scale = 0.; xmax = 0.; } L100: /* Scale x if necessary to avoid overflow when adding a */ /* multiple of column j of A. */ if (xj > 1.) { rec = 1. / xj; if (cnorm[j] > (bignum - xmax) * rec) { /* Scale x by 1/(2*abs(x(j))). */ rec *= .5; dscal_(n, &rec, &x[1], &c__1); *scale *= rec; } } else if (xj * cnorm[j] > bignum - xmax) { /* Scale x by 1/2. */ dscal_(n, &c_b36, &x[1], &c__1); *scale *= .5; } if (upper) { if (j > 1) { /* Compute the update */ /* x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j) */ i__3 = j - 1; d__1 = -x[j] * tscal; daxpy_(&i__3, &d__1, &a[j * a_dim1 + 1], &c__1, &x[1], &c__1); i__3 = j - 1; i__ = idamax_(&i__3, &x[1], &c__1); xmax = (d__1 = x[i__], abs(d__1)); } } else { if (j < *n) { /* Compute the update */ /* x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j) */ i__3 = *n - j; d__1 = -x[j] * tscal; daxpy_(&i__3, &d__1, &a[j + 1 + j * a_dim1], &c__1, & x[j + 1], &c__1); i__3 = *n - j; i__ = j + idamax_(&i__3, &x[j + 1], &c__1); xmax = (d__1 = x[i__], abs(d__1)); } } /* L110: */ } } else { /* Solve A' * x = b */ i__2 = jlast; i__1 = jinc; for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) { /* Compute x(j) = b(j) - sum A(k,j)*x(k). */ /* k<>j */ xj = (d__1 = x[j], abs(d__1)); uscal = tscal; rec = 1. / max(xmax,1.); if (cnorm[j] > (bignum - xj) * rec) { /* If x(j) could overflow, scale x by 1/(2*XMAX). */ rec *= .5; if (nounit) { tjjs = a[j + j * a_dim1] * tscal; } else { tjjs = tscal; } tjj = abs(tjjs); if (tjj > 1.) { /* Divide by A(j,j) when scaling x if A(j,j) > 1. */ /* Computing MIN */ d__1 = 1., d__2 = rec * tjj; rec = min(d__1,d__2); uscal /= tjjs; } if (rec < 1.) { dscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } } sumj = 0.; if (uscal == 1.) { /* If the scaling needed for A in the dot product is 1, */ /* call DDOT to perform the dot product. */ if (upper) { i__3 = j - 1; sumj = ddot_(&i__3, &a[j * a_dim1 + 1], &c__1, &x[1], &c__1); } else if (j < *n) { i__3 = *n - j; sumj = ddot_(&i__3, &a[j + 1 + j * a_dim1], &c__1, &x[ j + 1], &c__1); } } else { /* Otherwise, use in-line code for the dot product. */ if (upper) { i__3 = j - 1; for (i__ = 1; i__ <= i__3; ++i__) { sumj += a[i__ + j * a_dim1] * uscal * x[i__]; /* L120: */ } } else if (j < *n) { i__3 = *n; for (i__ = j + 1; i__ <= i__3; ++i__) { sumj += a[i__ + j * a_dim1] * uscal * x[i__]; /* L130: */ } } } if (uscal == tscal) { /* Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */ /* was not used to scale the dotproduct. */ x[j] -= sumj; xj = (d__1 = x[j], abs(d__1)); if (nounit) { tjjs = a[j + j * a_dim1] * tscal; } else { tjjs = tscal; if (tscal == 1.) { goto L150; } } /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */ tjj = abs(tjjs); if (tjj > smlnum) { /* abs(A(j,j)) > SMLNUM: */ if (tjj < 1.) { if (xj > tjj * bignum) { /* Scale X by 1/abs(x(j)). */ rec = 1. / xj; dscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } } x[j] /= tjjs; } else if (tjj > 0.) { /* 0 < abs(A(j,j)) <= SMLNUM: */ if (xj > tjj * bignum) { /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */ rec = tjj * bignum / xj; dscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } x[j] /= tjjs; } else { /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */ /* scale = 0, and compute a solution to A'*x = 0. */ i__3 = *n; for (i__ = 1; i__ <= i__3; ++i__) { x[i__] = 0.; /* L140: */ } x[j] = 1.; *scale = 0.; xmax = 0.; } L150: ; } else { /* Compute x(j) := x(j) / A(j,j) - sumj if the dot */ /* product has already been divided by 1/A(j,j). */ x[j] = x[j] / tjjs - sumj; } /* Computing MAX */ d__2 = xmax, d__3 = (d__1 = x[j], abs(d__1)); xmax = max(d__2,d__3); /* L160: */ } } *scale /= tscal; } /* Scale the column norms by 1/TSCAL for return. */ if (tscal != 1.) { d__1 = 1. / tscal; dscal_(n, &d__1, &cnorm[1], &c__1); } return 0; /* End of DLATRS */ } /* dlatrs_ */
/* Subroutine */ int dspgvd_(integer *itype, char *jobz, char *uplo, integer * n, doublereal *ap, doublereal *bp, doublereal *w, doublereal *z__, integer *ldz, doublereal *work, integer *lwork, integer *iwork, integer *liwork, integer *info, ftnlen jobz_len, ftnlen uplo_len) { /* System generated locals */ integer z_dim1, z_offset, i__1; doublereal d__1, d__2; /* Builtin functions */ double log(doublereal); integer pow_ii(integer *, integer *); /* Local variables */ static integer j, lgn, neig; extern logical lsame_(char *, char *, ftnlen, ftnlen); static integer lwmin; static char trans[1]; static logical upper; extern /* Subroutine */ int dtpmv_(char *, char *, char *, integer *, doublereal *, doublereal *, integer *, ftnlen, ftnlen, ftnlen), dtpsv_(char *, char *, char *, integer *, doublereal *, doublereal *, integer *, ftnlen, ftnlen, ftnlen); static logical wantz; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), dspevd_( char *, char *, integer *, doublereal *, doublereal *, doublereal *, integer *, doublereal *, integer *, integer *, integer *, integer *, ftnlen, ftnlen); static integer liwmin; extern /* Subroutine */ int dpptrf_(char *, integer *, doublereal *, integer *, ftnlen), dspgst_(integer *, char *, integer *, doublereal *, doublereal *, integer *, ftnlen); static logical lquery; /* -- LAPACK driver routine (version 3.0) -- */ /* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */ /* Courant Institute, Argonne National Lab, and Rice University */ /* June 30, 1999 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* DSPGVD computes all the eigenvalues, and optionally, the eigenvectors */ /* of a real generalized symmetric-definite eigenproblem, of the form */ /* A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A and */ /* B are assumed to be symmetric, stored in packed format, and B is also */ /* positive definite. */ /* If eigenvectors are desired, it uses a divide and conquer algorithm. */ /* The divide and conquer algorithm makes very mild assumptions about */ /* floating point arithmetic. It will work on machines with a guard */ /* digit in add/subtract, or on those binary machines without guard */ /* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */ /* Cray-2. It could conceivably fail on hexadecimal or decimal machines */ /* without guard digits, but we know of none. */ /* Arguments */ /* ========= */ /* ITYPE (input) INTEGER */ /* Specifies the problem type to be solved: */ /* = 1: A*x = (lambda)*B*x */ /* = 2: A*B*x = (lambda)*x */ /* = 3: B*A*x = (lambda)*x */ /* JOBZ (input) CHARACTER*1 */ /* = 'N': Compute eigenvalues only; */ /* = 'V': Compute eigenvalues and eigenvectors. */ /* UPLO (input) CHARACTER*1 */ /* = 'U': Upper triangles of A and B are stored; */ /* = 'L': Lower triangles of A and B are stored. */ /* N (input) INTEGER */ /* The order of the matrices A and B. N >= 0. */ /* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ /* On entry, the upper or lower triangle of the symmetric matrix */ /* A, packed columnwise in a linear array. The j-th column of A */ /* is stored in the array AP as follows: */ /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ /* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ /* On exit, the contents of AP are destroyed. */ /* BP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ /* On entry, the upper or lower triangle of the symmetric matrix */ /* B, packed columnwise in a linear array. The j-th column of B */ /* is stored in the array BP as follows: */ /* if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j; */ /* if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n. */ /* On exit, the triangular factor U or L from the Cholesky */ /* factorization B = U**T*U or B = L*L**T, in the same storage */ /* format as B. */ /* W (output) DOUBLE PRECISION array, dimension (N) */ /* If INFO = 0, the eigenvalues in ascending order. */ /* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */ /* If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */ /* eigenvectors. The eigenvectors are normalized as follows: */ /* if ITYPE = 1 or 2, Z**T*B*Z = I; */ /* if ITYPE = 3, Z**T*inv(B)*Z = I. */ /* If JOBZ = 'N', then Z is not referenced. */ /* LDZ (input) INTEGER */ /* The leading dimension of the array Z. LDZ >= 1, and if */ /* JOBZ = 'V', LDZ >= max(1,N). */ /* WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK) */ /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ /* LWORK (input) INTEGER */ /* The dimension of the array WORK. */ /* If N <= 1, LWORK >= 1. */ /* If JOBZ = 'N' and N > 1, LWORK >= 2*N. */ /* If JOBZ = 'V' and N > 1, LWORK >= 1 + 6*N + 2*N**2. */ /* If LWORK = -1, then a workspace query is assumed; the routine */ /* only calculates the optimal size of the WORK array, returns */ /* this value as the first entry of the WORK array, and no error */ /* message related to LWORK is issued by XERBLA. */ /* IWORK (workspace/output) INTEGER array, dimension (LIWORK) */ /* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */ /* LIWORK (input) INTEGER */ /* The dimension of the array IWORK. */ /* If JOBZ = 'N' or N <= 1, LIWORK >= 1. */ /* If JOBZ = 'V' and N > 1, LIWORK >= 3 + 5*N. */ /* If LIWORK = -1, then a workspace query is assumed; the */ /* routine only calculates the optimal size of the IWORK array, */ /* returns this value as the first entry of the IWORK array, and */ /* no error message related to LIWORK is issued by XERBLA. */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value */ /* > 0: DPPTRF or DSPEVD returned an error code: */ /* <= N: if INFO = i, DSPEVD failed to converge; */ /* i off-diagonal elements of an intermediate */ /* tridiagonal form did not converge to zero; */ /* > N: if INFO = N + i, for 1 <= i <= N, then the leading */ /* minor of order i of B is not positive definite. */ /* The factorization of B could not be completed and */ /* no eigenvalues or eigenvectors were computed. */ /* Further Details */ /* =============== */ /* Based on contributions by */ /* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input parameters. */ /* Parameter adjustments */ --ap; --bp; --w; z_dim1 = *ldz; z_offset = 1 + z_dim1; z__ -= z_offset; --work; --iwork; /* Function Body */ wantz = lsame_(jobz, "V", (ftnlen)1, (ftnlen)1); upper = lsame_(uplo, "U", (ftnlen)1, (ftnlen)1); lquery = *lwork == -1 || *liwork == -1; *info = 0; if (*n <= 1) { lgn = 0; liwmin = 1; lwmin = 1; } else { lgn = (integer) (log((doublereal) (*n)) / log(2.)); if (pow_ii(&c__2, &lgn) < *n) { ++lgn; } if (pow_ii(&c__2, &lgn) < *n) { ++lgn; } if (wantz) { liwmin = *n * 5 + 3; /* Computing 2nd power */ i__1 = *n; lwmin = *n * 5 + 1 + (*n << 1) * lgn + (i__1 * i__1 << 1); } else { liwmin = 1; lwmin = *n << 1; } } if (*itype < 0 || *itype > 3) { *info = -1; } else if (! (wantz || lsame_(jobz, "N", (ftnlen)1, (ftnlen)1))) { *info = -2; } else if (! (upper || lsame_(uplo, "L", (ftnlen)1, (ftnlen)1))) { *info = -3; } else if (*n < 0) { *info = -4; } else if (*ldz < max(1,*n)) { *info = -9; } else if (*lwork < lwmin && ! lquery) { *info = -11; } else if (*liwork < liwmin && ! lquery) { *info = -13; } if (*info == 0) { work[1] = (doublereal) lwmin; iwork[1] = liwmin; } if (*info != 0) { i__1 = -(*info); xerbla_("DSPGVD", &i__1, (ftnlen)6); return 0; } else if (lquery) { return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } /* Form a Cholesky factorization of BP. */ dpptrf_(uplo, n, &bp[1], info, (ftnlen)1); if (*info != 0) { *info = *n + *info; return 0; } /* Transform problem to standard eigenvalue problem and solve. */ dspgst_(itype, uplo, n, &ap[1], &bp[1], info, (ftnlen)1); dspevd_(jobz, uplo, n, &ap[1], &w[1], &z__[z_offset], ldz, &work[1], lwork, &iwork[1], liwork, info, (ftnlen)1, (ftnlen)1); /* Computing MAX */ d__1 = (doublereal) lwmin; lwmin = (integer) max(d__1,work[1]); /* Computing MAX */ d__1 = (doublereal) liwmin, d__2 = (doublereal) iwork[1]; liwmin = (integer) max(d__1,d__2); if (wantz) { /* Backtransform eigenvectors to the original problem. */ neig = *n; if (*info > 0) { neig = *info - 1; } if (*itype == 1 || *itype == 2) { /* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */ /* backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */ if (upper) { *(unsigned char *)trans = 'N'; } else { *(unsigned char *)trans = 'T'; } i__1 = neig; for (j = 1; j <= i__1; ++j) { dtpsv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 + 1], &c__1, (ftnlen)1, (ftnlen)1, (ftnlen)8); /* L10: */ } } else if (*itype == 3) { /* For B*A*x=(lambda)*x; */ /* backtransform eigenvectors: x = L*y or U'*y */ if (upper) { *(unsigned char *)trans = 'T'; } else { *(unsigned char *)trans = 'N'; } i__1 = neig; for (j = 1; j <= i__1; ++j) { dtpmv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 + 1], &c__1, (ftnlen)1, (ftnlen)1, (ftnlen)8); /* L20: */ } } } work[1] = (doublereal) lwmin; iwork[1] = liwmin; return 0; /* End of DSPGVD */ } /* dspgvd_ */
/* Subroutine */ int dsymm_(char *side, char *uplo, integer *m, integer *n, doublereal *alpha, doublereal *a, integer *lda, doublereal *b, integer *ldb, doublereal *beta, doublereal *c__, integer *ldc) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, i__1, i__2, i__3; /* Local variables */ integer i__, j, k, info; doublereal temp1, temp2; extern logical lsame_(char *, char *); integer nrowa; logical upper; extern /* Subroutine */ int xerbla_(char *, integer *); /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* DSYMM performs one of the matrix-matrix operations */ /* C := alpha*A*B + beta*C, */ /* or */ /* C := alpha*B*A + beta*C, */ /* where alpha and beta are scalars, A is a symmetric matrix and B and */ /* C are m by n matrices. */ /* Arguments */ /* ========== */ /* SIDE - CHARACTER*1. */ /* On entry, SIDE specifies whether the symmetric matrix A */ /* appears on the left or right in the operation as follows: */ /* SIDE = 'L' or 'l' C := alpha*A*B + beta*C, */ /* SIDE = 'R' or 'r' C := alpha*B*A + beta*C, */ /* Unchanged on exit. */ /* UPLO - CHARACTER*1. */ /* On entry, UPLO specifies whether the upper or lower */ /* triangular part of the symmetric matrix A is to be */ /* referenced as follows: */ /* UPLO = 'U' or 'u' Only the upper triangular part of the */ /* symmetric matrix is to be referenced. */ /* UPLO = 'L' or 'l' Only the lower triangular part of the */ /* symmetric matrix is to be referenced. */ /* Unchanged on exit. */ /* M - INTEGER. */ /* On entry, M specifies the number of rows of the matrix C. */ /* M must be at least zero. */ /* Unchanged on exit. */ /* N - INTEGER. */ /* On entry, N specifies the number of columns of the matrix C. */ /* N must be at least zero. */ /* Unchanged on exit. */ /* ALPHA - DOUBLE PRECISION. */ /* On entry, ALPHA specifies the scalar alpha. */ /* Unchanged on exit. */ /* A - DOUBLE PRECISION array of DIMENSION ( LDA, ka ), where ka is */ /* m when SIDE = 'L' or 'l' and is n otherwise. */ /* Before entry with SIDE = 'L' or 'l', the m by m part of */ /* the array A must contain the symmetric matrix, such that */ /* when UPLO = 'U' or 'u', the leading m by m upper triangular */ /* part of the array A must contain the upper triangular part */ /* of the symmetric matrix and the strictly lower triangular */ /* part of A is not referenced, and when UPLO = 'L' or 'l', */ /* the leading m by m lower triangular part of the array A */ /* must contain the lower triangular part of the symmetric */ /* matrix and the strictly upper triangular part of A is not */ /* referenced. */ /* Before entry with SIDE = 'R' or 'r', the n by n part of */ /* the array A must contain the symmetric matrix, such that */ /* when UPLO = 'U' or 'u', the leading n by n upper triangular */ /* part of the array A must contain the upper triangular part */ /* of the symmetric matrix and the strictly lower triangular */ /* part of A is not referenced, and when UPLO = 'L' or 'l', */ /* the leading n by n lower triangular part of the array A */ /* must contain the lower triangular part of the symmetric */ /* matrix and the strictly upper triangular part of A is not */ /* referenced. */ /* Unchanged on exit. */ /* LDA - INTEGER. */ /* On entry, LDA specifies the first dimension of A as declared */ /* in the calling (sub) program. When SIDE = 'L' or 'l' then */ /* LDA must be at least max( 1, m ), otherwise LDA must be at */ /* least max( 1, n ). */ /* Unchanged on exit. */ /* B - DOUBLE PRECISION array of DIMENSION ( LDB, n ). */ /* Before entry, the leading m by n part of the array B must */ /* contain the matrix B. */ /* Unchanged on exit. */ /* LDB - INTEGER. */ /* On entry, LDB specifies the first dimension of B as declared */ /* in the calling (sub) program. LDB must be at least */ /* max( 1, m ). */ /* Unchanged on exit. */ /* BETA - DOUBLE PRECISION. */ /* On entry, BETA specifies the scalar beta. When BETA is */ /* supplied as zero then C need not be set on input. */ /* Unchanged on exit. */ /* C - DOUBLE PRECISION array of DIMENSION ( LDC, n ). */ /* Before entry, the leading m by n part of the array C must */ /* contain the matrix C, except when beta is zero, in which */ /* case C need not be set on entry. */ /* On exit, the array C is overwritten by the m by n updated */ /* matrix. */ /* LDC - INTEGER. */ /* On entry, LDC specifies the first dimension of C as declared */ /* in the calling (sub) program. LDC must be at least */ /* max( 1, m ). */ /* Unchanged on exit. */ /* Level 3 Blas routine. */ /* -- Written on 8-February-1989. */ /* Jack Dongarra, Argonne National Laboratory. */ /* Iain Duff, AERE Harwell. */ /* Jeremy Du Croz, Numerical Algorithms Group Ltd. */ /* Sven Hammarling, Numerical Algorithms Group Ltd. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Parameters .. */ /* .. */ /* Set NROWA as the number of rows of A. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; c_dim1 = *ldc; c_offset = 1 + c_dim1; c__ -= c_offset; /* Function Body */ if (lsame_(side, "L")) { nrowa = *m; } else { nrowa = *n; } upper = lsame_(uplo, "U"); /* Test the input parameters. */ info = 0; if (! lsame_(side, "L") && ! lsame_(side, "R")) { info = 1; } else if (! upper && ! lsame_(uplo, "L")) { info = 2; } else if (*m < 0) { info = 3; } else if (*n < 0) { info = 4; } else if (*lda < max(1,nrowa)) { info = 7; } else if (*ldb < max(1,*m)) { info = 9; } else if (*ldc < max(1,*m)) { info = 12; } if (info != 0) { xerbla_("DSYMM ", &info); return 0; } /* Quick return if possible. */ if (*m == 0 || *n == 0 || *alpha == 0. && *beta == 1.) { return 0; } /* And when alpha.eq.zero. */ if (*alpha == 0.) { if (*beta == 0.) { i__1 = *n; for (j = 1; j <= i__1; ++j) { i__2 = *m; for (i__ = 1; i__ <= i__2; ++i__) { c__[i__ + j * c_dim1] = 0.; /* L10: */ } /* L20: */ } } else { i__1 = *n; for (j = 1; j <= i__1; ++j) { i__2 = *m; for (i__ = 1; i__ <= i__2; ++i__) { c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1]; /* L30: */ } /* L40: */ } } return 0; } /* Start the operations. */ if (lsame_(side, "L")) { /* Form C := alpha*A*B + beta*C. */ if (upper) { i__1 = *n; for (j = 1; j <= i__1; ++j) { i__2 = *m; for (i__ = 1; i__ <= i__2; ++i__) { temp1 = *alpha * b[i__ + j * b_dim1]; temp2 = 0.; i__3 = i__ - 1; for (k = 1; k <= i__3; ++k) { c__[k + j * c_dim1] += temp1 * a[k + i__ * a_dim1]; temp2 += b[k + j * b_dim1] * a[k + i__ * a_dim1]; /* L50: */ } if (*beta == 0.) { c__[i__ + j * c_dim1] = temp1 * a[i__ + i__ * a_dim1] + *alpha * temp2; } else { c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1] + temp1 * a[i__ + i__ * a_dim1] + *alpha * temp2; } /* L60: */ } /* L70: */ } } else { i__1 = *n; for (j = 1; j <= i__1; ++j) { for (i__ = *m; i__ >= 1; --i__) { temp1 = *alpha * b[i__ + j * b_dim1]; temp2 = 0.; i__2 = *m; for (k = i__ + 1; k <= i__2; ++k) { c__[k + j * c_dim1] += temp1 * a[k + i__ * a_dim1]; temp2 += b[k + j * b_dim1] * a[k + i__ * a_dim1]; /* L80: */ } if (*beta == 0.) { c__[i__ + j * c_dim1] = temp1 * a[i__ + i__ * a_dim1] + *alpha * temp2; } else { c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1] + temp1 * a[i__ + i__ * a_dim1] + *alpha * temp2; } /* L90: */ } /* L100: */ } } } else { /* Form C := alpha*B*A + beta*C. */ i__1 = *n; for (j = 1; j <= i__1; ++j) { temp1 = *alpha * a[j + j * a_dim1]; if (*beta == 0.) { i__2 = *m; for (i__ = 1; i__ <= i__2; ++i__) { c__[i__ + j * c_dim1] = temp1 * b[i__ + j * b_dim1]; /* L110: */ } } else { i__2 = *m; for (i__ = 1; i__ <= i__2; ++i__) { c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1] + temp1 * b[i__ + j * b_dim1]; /* L120: */ } } i__2 = j - 1; for (k = 1; k <= i__2; ++k) { if (upper) { temp1 = *alpha * a[k + j * a_dim1]; } else { temp1 = *alpha * a[j + k * a_dim1]; } i__3 = *m; for (i__ = 1; i__ <= i__3; ++i__) { c__[i__ + j * c_dim1] += temp1 * b[i__ + k * b_dim1]; /* L130: */ } /* L140: */ } i__2 = *n; for (k = j + 1; k <= i__2; ++k) { if (upper) { temp1 = *alpha * a[j + k * a_dim1]; } else { temp1 = *alpha * a[k + j * a_dim1]; } i__3 = *m; for (i__ = 1; i__ <= i__3; ++i__) { c__[i__ + j * c_dim1] += temp1 * b[i__ + k * b_dim1]; /* L150: */ } /* L160: */ } /* L170: */ } } return 0; /* End of DSYMM . */ } /* dsymm_ */
/* Subroutine */ int sla_syrfsx_extended__(integer *prec_type__, char *uplo, integer *n, integer *nrhs, real *a, integer *lda, real *af, integer * ldaf, integer *ipiv, logical *colequ, real *c__, real *b, integer * ldb, real *y, integer *ldy, real *berr_out__, integer *n_norms__, real *err_bnds_norm__, real *err_bnds_comp__, real *res, real *ayb, real *dy, real *y_tail__, real *rcond, integer *ithresh, real * rthresh, real *dz_ub__, logical *ignore_cwise__, integer *info, ftnlen uplo_len) { /* System generated locals */ integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, y_dim1, y_offset, err_bnds_norm_dim1, err_bnds_norm_offset, err_bnds_comp_dim1, err_bnds_comp_offset, i__1, i__2, i__3; real r__1, r__2; /* Local variables */ real dxratmax, dzratmax; integer i__, j; logical incr_prec__; extern /* Subroutine */ int sla_syamv__(integer *, integer *, real *, real *, integer *, real *, integer *, real *, real *, integer *); real prev_dz_z__, yk, final_dx_x__, final_dz_z__; extern /* Subroutine */ int sla_wwaddw__(integer *, real *, real *, real * ); real prevnormdx; integer cnt; real dyk, eps, incr_thresh__, dx_x__, dz_z__, ymin; extern /* Subroutine */ int sla_lin_berr__(integer *, integer *, integer * , real *, real *, real *); integer y_prec_state__, uplo2; extern /* Subroutine */ int blas_ssymv_x__(integer *, integer *, real *, real *, integer *, real *, integer *, real *, real *, integer *, integer *); extern logical lsame_(char *, char *); real dxrat, dzrat; extern /* Subroutine */ int blas_ssymv2_x__(integer *, integer *, real *, real *, integer *, real *, real *, integer *, real *, real *, integer *, integer *), scopy_(integer *, real *, integer *, real * , integer *); real normx, normy; extern /* Subroutine */ int saxpy_(integer *, real *, real *, integer *, real *, integer *), ssymv_(char *, integer *, real *, real *, integer *, real *, integer *, real *, real *, integer *); extern doublereal slamch_(char *); real normdx; extern /* Subroutine */ int ssytrs_(char *, integer *, integer *, real *, integer *, integer *, real *, integer *, integer *); real hugeval; extern integer ilauplo_(char *); integer x_state__, z_state__; /* -- LAPACK routine (version 3.2.1) -- */ /* -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */ /* -- Jason Riedy of Univ. of California Berkeley. -- */ /* -- April 2009 -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley and NAG Ltd. -- */ /* .. */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* SLA_SYRFSX_EXTENDED improves the computed solution to a system of */ /* linear equations by performing extra-precise iterative refinement */ /* and provides error bounds and backward error estimates for the solution. */ /* This subroutine is called by SSYRFSX to perform iterative refinement. */ /* In addition to normwise error bound, the code provides maximum */ /* componentwise error bound if possible. See comments for ERR_BNDS_NORM */ /* and ERR_BNDS_COMP for details of the error bounds. Note that this */ /* subroutine is only resonsible for setting the second fields of */ /* ERR_BNDS_NORM and ERR_BNDS_COMP. */ /* Arguments */ /* ========= */ /* PREC_TYPE (input) INTEGER */ /* Specifies the intermediate precision to be used in refinement. */ /* The value is defined by ILAPREC(P) where P is a CHARACTER and */ /* P = 'S': Single */ /* = 'D': Double */ /* = 'I': Indigenous */ /* = 'X', 'E': Extra */ /* UPLO (input) CHARACTER*1 */ /* = 'U': Upper triangle of A is stored; */ /* = 'L': Lower triangle of A is stored. */ /* N (input) INTEGER */ /* The number of linear equations, i.e., the order of the */ /* matrix A. N >= 0. */ /* NRHS (input) INTEGER */ /* The number of right-hand-sides, i.e., the number of columns of the */ /* matrix B. */ /* A (input) REAL array, dimension (LDA,N) */ /* On entry, the N-by-N matrix A. */ /* LDA (input) INTEGER */ /* The leading dimension of the array A. LDA >= max(1,N). */ /* AF (input) REAL array, dimension (LDAF,N) */ /* The block diagonal matrix D and the multipliers used to */ /* obtain the factor U or L as computed by SSYTRF. */ /* LDAF (input) INTEGER */ /* The leading dimension of the array AF. LDAF >= max(1,N). */ /* IPIV (input) INTEGER array, dimension (N) */ /* Details of the interchanges and the block structure of D */ /* as determined by SSYTRF. */ /* COLEQU (input) LOGICAL */ /* If .TRUE. then column equilibration was done to A before calling */ /* this routine. This is needed to compute the solution and error */ /* bounds correctly. */ /* C (input) REAL array, dimension (N) */ /* The column scale factors for A. If COLEQU = .FALSE., C */ /* is not accessed. If C is input, each element of C should be a power */ /* of the radix to ensure a reliable solution and error estimates. */ /* Scaling by powers of the radix does not cause rounding errors unless */ /* the result underflows or overflows. Rounding errors during scaling */ /* lead to refining with a matrix that is not equivalent to the */ /* input matrix, producing error estimates that may not be */ /* reliable. */ /* B (input) REAL array, dimension (LDB,NRHS) */ /* The right-hand-side matrix B. */ /* LDB (input) INTEGER */ /* The leading dimension of the array B. LDB >= max(1,N). */ /* Y (input/output) REAL array, dimension (LDY,NRHS) */ /* On entry, the solution matrix X, as computed by SSYTRS. */ /* On exit, the improved solution matrix Y. */ /* LDY (input) INTEGER */ /* The leading dimension of the array Y. LDY >= max(1,N). */ /* BERR_OUT (output) REAL array, dimension (NRHS) */ /* On exit, BERR_OUT(j) contains the componentwise relative backward */ /* error for right-hand-side j from the formula */ /* max(i) ( abs(RES(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) ) */ /* where abs(Z) is the componentwise absolute value of the matrix */ /* or vector Z. This is computed by SLA_LIN_BERR. */ /* N_NORMS (input) INTEGER */ /* Determines which error bounds to return (see ERR_BNDS_NORM */ /* and ERR_BNDS_COMP). */ /* If N_NORMS >= 1 return normwise error bounds. */ /* If N_NORMS >= 2 return componentwise error bounds. */ /* ERR_BNDS_NORM (input/output) REAL array, dimension (NRHS, N_ERR_BNDS) */ /* For each right-hand side, this array contains information about */ /* various error bounds and condition numbers corresponding to the */ /* normwise relative error, which is defined as follows: */ /* Normwise relative error in the ith solution vector: */ /* max_j (abs(XTRUE(j,i) - X(j,i))) */ /* ------------------------------ */ /* max_j abs(X(j,i)) */ /* The array is indexed by the type of error information as described */ /* below. There currently are up to three pieces of information */ /* returned. */ /* The first index in ERR_BNDS_NORM(i,:) corresponds to the ith */ /* right-hand side. */ /* The second index in ERR_BNDS_NORM(:,err) contains the following */ /* three fields: */ /* err = 1 "Trust/don't trust" boolean. Trust the answer if the */ /* reciprocal condition number is less than the threshold */ /* sqrt(n) * slamch('Epsilon'). */ /* err = 2 "Guaranteed" error bound: The estimated forward error, */ /* almost certainly within a factor of 10 of the true error */ /* so long as the next entry is greater than the threshold */ /* sqrt(n) * slamch('Epsilon'). This error bound should only */ /* be trusted if the previous boolean is true. */ /* err = 3 Reciprocal condition number: Estimated normwise */ /* reciprocal condition number. Compared with the threshold */ /* sqrt(n) * slamch('Epsilon') to determine if the error */ /* estimate is "guaranteed". These reciprocal condition */ /* numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */ /* appropriately scaled matrix Z. */ /* Let Z = S*A, where S scales each row by a power of the */ /* radix so all absolute row sums of Z are approximately 1. */ /* This subroutine is only responsible for setting the second field */ /* above. */ /* See Lapack Working Note 165 for further details and extra */ /* cautions. */ /* ERR_BNDS_COMP (input/output) REAL array, dimension (NRHS, N_ERR_BNDS) */ /* For each right-hand side, this array contains information about */ /* various error bounds and condition numbers corresponding to the */ /* componentwise relative error, which is defined as follows: */ /* Componentwise relative error in the ith solution vector: */ /* abs(XTRUE(j,i) - X(j,i)) */ /* max_j ---------------------- */ /* abs(X(j,i)) */ /* The array is indexed by the right-hand side i (on which the */ /* componentwise relative error depends), and the type of error */ /* information as described below. There currently are up to three */ /* pieces of information returned for each right-hand side. If */ /* componentwise accuracy is not requested (PARAMS(3) = 0.0), then */ /* ERR_BNDS_COMP is not accessed. If N_ERR_BNDS .LT. 3, then at most */ /* the first (:,N_ERR_BNDS) entries are returned. */ /* The first index in ERR_BNDS_COMP(i,:) corresponds to the ith */ /* right-hand side. */ /* The second index in ERR_BNDS_COMP(:,err) contains the following */ /* three fields: */ /* err = 1 "Trust/don't trust" boolean. Trust the answer if the */ /* reciprocal condition number is less than the threshold */ /* sqrt(n) * slamch('Epsilon'). */ /* err = 2 "Guaranteed" error bound: The estimated forward error, */ /* almost certainly within a factor of 10 of the true error */ /* so long as the next entry is greater than the threshold */ /* sqrt(n) * slamch('Epsilon'). This error bound should only */ /* be trusted if the previous boolean is true. */ /* err = 3 Reciprocal condition number: Estimated componentwise */ /* reciprocal condition number. Compared with the threshold */ /* sqrt(n) * slamch('Epsilon') to determine if the error */ /* estimate is "guaranteed". These reciprocal condition */ /* numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */ /* appropriately scaled matrix Z. */ /* Let Z = S*(A*diag(x)), where x is the solution for the */ /* current right-hand side and S scales each row of */ /* A*diag(x) by a power of the radix so all absolute row */ /* sums of Z are approximately 1. */ /* This subroutine is only responsible for setting the second field */ /* above. */ /* See Lapack Working Note 165 for further details and extra */ /* cautions. */ /* RES (input) REAL array, dimension (N) */ /* Workspace to hold the intermediate residual. */ /* AYB (input) REAL array, dimension (N) */ /* Workspace. This can be the same workspace passed for Y_TAIL. */ /* DY (input) REAL array, dimension (N) */ /* Workspace to hold the intermediate solution. */ /* Y_TAIL (input) REAL array, dimension (N) */ /* Workspace to hold the trailing bits of the intermediate solution. */ /* RCOND (input) REAL */ /* Reciprocal scaled condition number. This is an estimate of the */ /* reciprocal Skeel condition number of the matrix A after */ /* equilibration (if done). If this is less than the machine */ /* precision (in particular, if it is zero), the matrix is singular */ /* to working precision. Note that the error may still be small even */ /* if this number is very small and the matrix appears ill- */ /* conditioned. */ /* ITHRESH (input) INTEGER */ /* The maximum number of residual computations allowed for */ /* refinement. The default is 10. For 'aggressive' set to 100 to */ /* permit convergence using approximate factorizations or */ /* factorizations other than LU. If the factorization uses a */ /* technique other than Gaussian elimination, the guarantees in */ /* ERR_BNDS_NORM and ERR_BNDS_COMP may no longer be trustworthy. */ /* RTHRESH (input) REAL */ /* Determines when to stop refinement if the error estimate stops */ /* decreasing. Refinement will stop when the next solution no longer */ /* satisfies norm(dx_{i+1}) < RTHRESH * norm(dx_i) where norm(Z) is */ /* the infinity norm of Z. RTHRESH satisfies 0 < RTHRESH <= 1. The */ /* default value is 0.5. For 'aggressive' set to 0.9 to permit */ /* convergence on extremely ill-conditioned matrices. See LAWN 165 */ /* for more details. */ /* DZ_UB (input) REAL */ /* Determines when to start considering componentwise convergence. */ /* Componentwise convergence is only considered after each component */ /* of the solution Y is stable, which we definte as the relative */ /* change in each component being less than DZ_UB. The default value */ /* is 0.25, requiring the first bit to be stable. See LAWN 165 for */ /* more details. */ /* IGNORE_CWISE (input) LOGICAL */ /* If .TRUE. then ignore componentwise convergence. Default value */ /* is .FALSE.. */ /* INFO (output) INTEGER */ /* = 0: Successful exit. */ /* < 0: if INFO = -i, the ith argument to SSYTRS had an illegal */ /* value */ /* ===================================================================== */ /* .. Local Scalars .. */ /* .. */ /* .. Parameters .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Parameter adjustments */ err_bnds_comp_dim1 = *nrhs; err_bnds_comp_offset = 1 + err_bnds_comp_dim1; err_bnds_comp__ -= err_bnds_comp_offset; err_bnds_norm_dim1 = *nrhs; err_bnds_norm_offset = 1 + err_bnds_norm_dim1; err_bnds_norm__ -= err_bnds_norm_offset; a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; af_dim1 = *ldaf; af_offset = 1 + af_dim1; af -= af_offset; --ipiv; --c__; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; y_dim1 = *ldy; y_offset = 1 + y_dim1; y -= y_offset; --berr_out__; --res; --ayb; --dy; --y_tail__; /* Function Body */ if (*info != 0) { return 0; } eps = slamch_("Epsilon"); hugeval = slamch_("Overflow"); /* Force HUGEVAL to Inf */ hugeval *= hugeval; /* Using HUGEVAL may lead to spurious underflows. */ incr_thresh__ = (real) (*n) * eps; if (lsame_(uplo, "L")) { uplo2 = ilauplo_("L"); } else { uplo2 = ilauplo_("U"); } i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { y_prec_state__ = 1; if (y_prec_state__ == 2) { i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { y_tail__[i__] = 0.f; } } dxrat = 0.f; dxratmax = 0.f; dzrat = 0.f; dzratmax = 0.f; final_dx_x__ = hugeval; final_dz_z__ = hugeval; prevnormdx = hugeval; prev_dz_z__ = hugeval; dz_z__ = hugeval; dx_x__ = hugeval; x_state__ = 1; z_state__ = 0; incr_prec__ = FALSE_; i__2 = *ithresh; for (cnt = 1; cnt <= i__2; ++cnt) { /* Compute residual RES = B_s - op(A_s) * Y, */ /* op(A) = A, A**T, or A**H depending on TRANS (and type). */ scopy_(n, &b[j * b_dim1 + 1], &c__1, &res[1], &c__1); if (y_prec_state__ == 0) { ssymv_(uplo, n, &c_b9, &a[a_offset], lda, &y[j * y_dim1 + 1], &c__1, &c_b11, &res[1], &c__1); } else if (y_prec_state__ == 1) { blas_ssymv_x__(&uplo2, n, &c_b9, &a[a_offset], lda, &y[j * y_dim1 + 1], &c__1, &c_b11, &res[1], &c__1, prec_type__); } else { blas_ssymv2_x__(&uplo2, n, &c_b9, &a[a_offset], lda, &y[j * y_dim1 + 1], &y_tail__[1], &c__1, &c_b11, &res[1], & c__1, prec_type__); } /* XXX: RES is no longer needed. */ scopy_(n, &res[1], &c__1, &dy[1], &c__1); ssytrs_(uplo, n, nrhs, &af[af_offset], ldaf, &ipiv[1], &dy[1], n, info); /* Calculate relative changes DX_X, DZ_Z and ratios DXRAT, DZRAT. */ normx = 0.f; normy = 0.f; normdx = 0.f; dz_z__ = 0.f; ymin = hugeval; i__3 = *n; for (i__ = 1; i__ <= i__3; ++i__) { yk = (r__1 = y[i__ + j * y_dim1], dabs(r__1)); dyk = (r__1 = dy[i__], dabs(r__1)); if (yk != 0.f) { /* Computing MAX */ r__1 = dz_z__, r__2 = dyk / yk; dz_z__ = dmax(r__1,r__2); } else if (dyk != 0.f) { dz_z__ = hugeval; } ymin = dmin(ymin,yk); normy = dmax(normy,yk); if (*colequ) { /* Computing MAX */ r__1 = normx, r__2 = yk * c__[i__]; normx = dmax(r__1,r__2); /* Computing MAX */ r__1 = normdx, r__2 = dyk * c__[i__]; normdx = dmax(r__1,r__2); } else { normx = normy; normdx = dmax(normdx,dyk); } } if (normx != 0.f) { dx_x__ = normdx / normx; } else if (normdx == 0.f) { dx_x__ = 0.f; } else { dx_x__ = hugeval; } dxrat = normdx / prevnormdx; dzrat = dz_z__ / prev_dz_z__; /* Check termination criteria. */ if (ymin * *rcond < incr_thresh__ * normy && y_prec_state__ < 2) { incr_prec__ = TRUE_; } if (x_state__ == 3 && dxrat <= *rthresh) { x_state__ = 1; } if (x_state__ == 1) { if (dx_x__ <= eps) { x_state__ = 2; } else if (dxrat > *rthresh) { if (y_prec_state__ != 2) { incr_prec__ = TRUE_; } else { x_state__ = 3; } } else { if (dxrat > dxratmax) { dxratmax = dxrat; } } if (x_state__ > 1) { final_dx_x__ = dx_x__; } } if (z_state__ == 0 && dz_z__ <= *dz_ub__) { z_state__ = 1; } if (z_state__ == 3 && dzrat <= *rthresh) { z_state__ = 1; } if (z_state__ == 1) { if (dz_z__ <= eps) { z_state__ = 2; } else if (dz_z__ > *dz_ub__) { z_state__ = 0; dzratmax = 0.f; final_dz_z__ = hugeval; } else if (dzrat > *rthresh) { if (y_prec_state__ != 2) { incr_prec__ = TRUE_; } else { z_state__ = 3; } } else { if (dzrat > dzratmax) { dzratmax = dzrat; } } if (z_state__ > 1) { final_dz_z__ = dz_z__; } } if (x_state__ != 1 && (*ignore_cwise__ || z_state__ != 1)) { goto L666; } if (incr_prec__) { incr_prec__ = FALSE_; ++y_prec_state__; i__3 = *n; for (i__ = 1; i__ <= i__3; ++i__) { y_tail__[i__] = 0.f; } } prevnormdx = normdx; prev_dz_z__ = dz_z__; /* Update soluton. */ if (y_prec_state__ < 2) { saxpy_(n, &c_b11, &dy[1], &c__1, &y[j * y_dim1 + 1], &c__1); } else { sla_wwaddw__(n, &y[j * y_dim1 + 1], &y_tail__[1], &dy[1]); } } /* Target of "IF (Z_STOP .AND. X_STOP)". Sun's f77 won't EXIT. */ L666: /* Set final_* when cnt hits ithresh. */ if (x_state__ == 1) { final_dx_x__ = dx_x__; } if (z_state__ == 1) { final_dz_z__ = dz_z__; } /* Compute error bounds. */ if (*n_norms__ >= 1) { err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = final_dx_x__ / ( 1 - dxratmax); } if (*n_norms__ >= 2) { err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = final_dz_z__ / ( 1 - dzratmax); } /* Compute componentwise relative backward error from formula */ /* max(i) ( abs(R(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) ) */ /* where abs(Z) is the componentwise absolute value of the matrix */ /* or vector Z. */ /* Compute residual RES = B_s - op(A_s) * Y, */ /* op(A) = A, A**T, or A**H depending on TRANS (and type). */ scopy_(n, &b[j * b_dim1 + 1], &c__1, &res[1], &c__1); ssymv_(uplo, n, &c_b9, &a[a_offset], lda, &y[j * y_dim1 + 1], &c__1, & c_b11, &res[1], &c__1); i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { ayb[i__] = (r__1 = b[i__ + j * b_dim1], dabs(r__1)); } /* Compute abs(op(A_s))*abs(Y) + abs(B_s). */ sla_syamv__(&uplo2, n, &c_b11, &a[a_offset], lda, &y[j * y_dim1 + 1], &c__1, &c_b11, &ayb[1], &c__1); sla_lin_berr__(n, n, &c__1, &res[1], &ayb[1], &berr_out__[j]); /* End of loop for each RHS. */ } return 0; } /* sla_syrfsx_extended__ */
/* Subroutine */ int clatme_(integer *n, char *dist, integer *iseed, complex * d__, integer *mode, real *cond, complex *dmax__, char *ei, char * rsign, char *upper, char *sim, real *ds, integer *modes, real *conds, integer *kl, integer *ku, real *anorm, complex *a, integer *lda, complex *work, integer *info) { /* System generated locals */ integer a_dim1, a_offset, i__1, i__2; real r__1, r__2; complex q__1, q__2; /* Builtin functions */ double c_abs(complex *); void r_cnjg(complex *, complex *); /* Local variables */ integer i__, j, ic, jc, ir, jcr; complex tau; logical bads; integer isim; real temp; extern /* Subroutine */ int cgerc_(integer *, integer *, complex *, complex *, integer *, complex *, integer *, complex *, integer *); complex alpha; extern /* Subroutine */ int cscal_(integer *, complex *, complex *, integer *); extern logical lsame_(char *, char *); extern /* Subroutine */ int cgemv_(char *, integer *, integer *, complex * , complex *, integer *, complex *, integer *, complex *, complex * , integer *); integer iinfo; real tempa[1]; integer icols, idist; extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, complex *, integer *); integer irows; extern /* Subroutine */ int clatm1_(integer *, real *, integer *, integer *, integer *, complex *, integer *, integer *), slatm1_(integer *, real *, integer *, integer *, integer *, real *, integer *, integer *); extern doublereal clange_(char *, integer *, integer *, complex *, integer *, real *); extern /* Subroutine */ int clarge_(integer *, complex *, integer *, integer *, complex *, integer *), clarfg_(integer *, complex *, complex *, integer *, complex *), clacgv_(integer *, complex *, integer *); extern /* Complex */ VOID clarnd_(complex *, integer *, integer *); real ralpha; extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer *), claset_(char *, integer *, integer *, complex *, complex *, complex *, integer *), xerbla_(char *, integer *), clarnv_(integer *, integer *, integer *, complex *); integer irsign, iupper; complex xnorms; /* -- LAPACK test routine (version 3.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* CLATME generates random non-symmetric square matrices with */ /* specified eigenvalues for testing LAPACK programs. */ /* CLATME operates by applying the following sequence of */ /* operations: */ /* 1. Set the diagonal to D, where D may be input or */ /* computed according to MODE, COND, DMAX, and RSIGN */ /* as described below. */ /* 2. If UPPER='T', the upper triangle of A is set to random values */ /* out of distribution DIST. */ /* 3. If SIM='T', A is multiplied on the left by a random matrix */ /* X, whose singular values are specified by DS, MODES, and */ /* CONDS, and on the right by X inverse. */ /* 4. If KL < N-1, the lower bandwidth is reduced to KL using */ /* Householder transformations. If KU < N-1, the upper */ /* bandwidth is reduced to KU. */ /* 5. If ANORM is not negative, the matrix is scaled to have */ /* maximum-element-norm ANORM. */ /* (Note: since the matrix cannot be reduced beyond Hessenberg form, */ /* no packing options are available.) */ /* Arguments */ /* ========= */ /* N - INTEGER */ /* The number of columns (or rows) of A. Not modified. */ /* DIST - CHARACTER*1 */ /* On entry, DIST specifies the type of distribution to be used */ /* to generate the random eigen-/singular values, and on the */ /* upper triangle (see UPPER). */ /* 'U' => UNIFORM( 0, 1 ) ( 'U' for uniform ) */ /* 'S' => UNIFORM( -1, 1 ) ( 'S' for symmetric ) */ /* 'N' => NORMAL( 0, 1 ) ( 'N' for normal ) */ /* 'D' => uniform on the complex disc |z| < 1. */ /* Not modified. */ /* ISEED - INTEGER array, dimension ( 4 ) */ /* On entry ISEED specifies the seed of the random number */ /* generator. They should lie between 0 and 4095 inclusive, */ /* and ISEED(4) should be odd. The random number generator */ /* uses a linear congruential sequence limited to small */ /* integers, and so should produce machine independent */ /* random numbers. The values of ISEED are changed on */ /* exit, and can be used in the next call to CLATME */ /* to continue the same random number sequence. */ /* Changed on exit. */ /* D - COMPLEX array, dimension ( N ) */ /* This array is used to specify the eigenvalues of A. If */ /* MODE=0, then D is assumed to contain the eigenvalues */ /* otherwise they will be computed according to MODE, COND, */ /* DMAX, and RSIGN and placed in D. */ /* Modified if MODE is nonzero. */ /* MODE - INTEGER */ /* On entry this describes how the eigenvalues are to */ /* be specified: */ /* MODE = 0 means use D as input */ /* MODE = 1 sets D(1)=1 and D(2:N)=1.0/COND */ /* MODE = 2 sets D(1:N-1)=1 and D(N)=1.0/COND */ /* MODE = 3 sets D(I)=COND**(-(I-1)/(N-1)) */ /* MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */ /* MODE = 5 sets D to random numbers in the range */ /* ( 1/COND , 1 ) such that their logarithms */ /* are uniformly distributed. */ /* MODE = 6 set D to random numbers from same distribution */ /* as the rest of the matrix. */ /* MODE < 0 has the same meaning as ABS(MODE), except that */ /* the order of the elements of D is reversed. */ /* Thus if MODE is between 1 and 4, D has entries ranging */ /* from 1 to 1/COND, if between -1 and -4, D has entries */ /* ranging from 1/COND to 1, */ /* Not modified. */ /* COND - REAL */ /* On entry, this is used as described under MODE above. */ /* If used, it must be >= 1. Not modified. */ /* DMAX - COMPLEX */ /* If MODE is neither -6, 0 nor 6, the contents of D, as */ /* computed according to MODE and COND, will be scaled by */ /* DMAX / max(abs(D(i))). Note that DMAX need not be */ /* positive or real: if DMAX is negative or complex (or zero), */ /* D will be scaled by a negative or complex number (or zero). */ /* If RSIGN='F' then the largest (absolute) eigenvalue will be */ /* equal to DMAX. */ /* Not modified. */ /* EI - CHARACTER*1 (ignored) */ /* Not modified. */ /* RSIGN - CHARACTER*1 */ /* If MODE is not 0, 6, or -6, and RSIGN='T', then the */ /* elements of D, as computed according to MODE and COND, will */ /* be multiplied by a random complex number from the unit */ /* circle |z| = 1. If RSIGN='F', they will not be. RSIGN may */ /* only have the values 'T' or 'F'. */ /* Not modified. */ /* UPPER - CHARACTER*1 */ /* If UPPER='T', then the elements of A above the diagonal */ /* will be set to random numbers out of DIST. If UPPER='F', */ /* they will not. UPPER may only have the values 'T' or 'F'. */ /* Not modified. */ /* SIM - CHARACTER*1 */ /* If SIM='T', then A will be operated on by a "similarity */ /* transform", i.e., multiplied on the left by a matrix X and */ /* on the right by X inverse. X = U S V, where U and V are */ /* random unitary matrices and S is a (diagonal) matrix of */ /* singular values specified by DS, MODES, and CONDS. If */ /* SIM='F', then A will not be transformed. */ /* Not modified. */ /* DS - REAL array, dimension ( N ) */ /* This array is used to specify the singular values of X, */ /* in the same way that D specifies the eigenvalues of A. */ /* If MODE=0, the DS contains the singular values, which */ /* may not be zero. */ /* Modified if MODE is nonzero. */ /* MODES - INTEGER */ /* CONDS - REAL */ /* Similar to MODE and COND, but for specifying the diagonal */ /* of S. MODES=-6 and +6 are not allowed (since they would */ /* result in randomly ill-conditioned eigenvalues.) */ /* KL - INTEGER */ /* This specifies the lower bandwidth of the matrix. KL=1 */ /* specifies upper Hessenberg form. If KL is at least N-1, */ /* then A will have full lower bandwidth. */ /* Not modified. */ /* KU - INTEGER */ /* This specifies the upper bandwidth of the matrix. KU=1 */ /* specifies lower Hessenberg form. If KU is at least N-1, */ /* then A will have full upper bandwidth; if KU and KL */ /* are both at least N-1, then A will be dense. Only one of */ /* KU and KL may be less than N-1. */ /* Not modified. */ /* ANORM - REAL */ /* If ANORM is not negative, then A will be scaled by a non- */ /* negative real number to make the maximum-element-norm of A */ /* to be ANORM. */ /* Not modified. */ /* A - COMPLEX array, dimension ( LDA, N ) */ /* On exit A is the desired test matrix. */ /* Modified. */ /* LDA - INTEGER */ /* LDA specifies the first dimension of A as declared in the */ /* calling program. LDA must be at least M. */ /* Not modified. */ /* WORK - COMPLEX array, dimension ( 3*N ) */ /* Workspace. */ /* Modified. */ /* INFO - INTEGER */ /* Error code. On exit, INFO will be set to one of the */ /* following values: */ /* 0 => normal return */ /* -1 => N negative */ /* -2 => DIST illegal string */ /* -5 => MODE not in range -6 to 6 */ /* -6 => COND less than 1.0, and MODE neither -6, 0 nor 6 */ /* -9 => RSIGN is not 'T' or 'F' */ /* -10 => UPPER is not 'T' or 'F' */ /* -11 => SIM is not 'T' or 'F' */ /* -12 => MODES=0 and DS has a zero singular value. */ /* -13 => MODES is not in the range -5 to 5. */ /* -14 => MODES is nonzero and CONDS is less than 1. */ /* -15 => KL is less than 1. */ /* -16 => KU is less than 1, or KL and KU are both less than */ /* N-1. */ /* -19 => LDA is less than M. */ /* 1 => Error return from CLATM1 (computing D) */ /* 2 => Cannot scale to DMAX (max. eigenvalue is 0) */ /* 3 => Error return from SLATM1 (computing DS) */ /* 4 => Error return from CLARGE */ /* 5 => Zero singular value from SLATM1. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* 1) Decode and Test the input parameters. */ /* Initialize flags & seed. */ /* Parameter adjustments */ --iseed; --d__; --ds; a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; --work; /* Function Body */ *info = 0; /* Quick return if possible */ if (*n == 0) { return 0; } /* Decode DIST */ if (lsame_(dist, "U")) { idist = 1; } else if (lsame_(dist, "S")) { idist = 2; } else if (lsame_(dist, "N")) { idist = 3; } else if (lsame_(dist, "D")) { idist = 4; } else { idist = -1; } /* Decode RSIGN */ if (lsame_(rsign, "T")) { irsign = 1; } else if (lsame_(rsign, "F")) { irsign = 0; } else { irsign = -1; } /* Decode UPPER */ if (lsame_(upper, "T")) { iupper = 1; } else if (lsame_(upper, "F")) { iupper = 0; } else { iupper = -1; } /* Decode SIM */ if (lsame_(sim, "T")) { isim = 1; } else if (lsame_(sim, "F")) { isim = 0; } else { isim = -1; } /* Check DS, if MODES=0 and ISIM=1 */ bads = FALSE_; if (*modes == 0 && isim == 1) { i__1 = *n; for (j = 1; j <= i__1; ++j) { if (ds[j] == 0.f) { bads = TRUE_; } /* L10: */ } } /* Set INFO if an error */ if (*n < 0) { *info = -1; } else if (idist == -1) { *info = -2; } else if (abs(*mode) > 6) { *info = -5; } else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.f) { *info = -6; } else if (irsign == -1) { *info = -9; } else if (iupper == -1) { *info = -10; } else if (isim == -1) { *info = -11; } else if (bads) { *info = -12; } else if (isim == 1 && abs(*modes) > 5) { *info = -13; } else if (isim == 1 && *modes != 0 && *conds < 1.f) { *info = -14; } else if (*kl < 1) { *info = -15; } else if (*ku < 1 || *ku < *n - 1 && *kl < *n - 1) { *info = -16; } else if (*lda < max(1,*n)) { *info = -19; } if (*info != 0) { i__1 = -(*info); xerbla_("CLATME", &i__1); return 0; } /* Initialize random number generator */ for (i__ = 1; i__ <= 4; ++i__) { iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096; /* L20: */ } if (iseed[4] % 2 != 1) { ++iseed[4]; } /* 2) Set up diagonal of A */ /* Compute D according to COND and MODE */ clatm1_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], n, &iinfo); if (iinfo != 0) { *info = 1; return 0; } if (*mode != 0 && abs(*mode) != 6) { /* Scale by DMAX */ temp = c_abs(&d__[1]); i__1 = *n; for (i__ = 2; i__ <= i__1; ++i__) { /* Computing MAX */ r__1 = temp, r__2 = c_abs(&d__[i__]); temp = dmax(r__1,r__2); /* L30: */ } if (temp > 0.f) { q__1.r = dmax__->r / temp, q__1.i = dmax__->i / temp; alpha.r = q__1.r, alpha.i = q__1.i; } else { *info = 2; return 0; } cscal_(n, &alpha, &d__[1], &c__1); } claset_("Full", n, n, &c_b1, &c_b1, &a[a_offset], lda); i__1 = *lda + 1; ccopy_(n, &d__[1], &c__1, &a[a_offset], &i__1); /* 3) If UPPER='T', set upper triangle of A to random numbers. */ if (iupper != 0) { i__1 = *n; for (jc = 2; jc <= i__1; ++jc) { i__2 = jc - 1; clarnv_(&idist, &iseed[1], &i__2, &a[jc * a_dim1 + 1]); /* L40: */ } } /* 4) If SIM='T', apply similarity transformation. */ /* -1 */ /* Transform is X A X , where X = U S V, thus */ /* it is U S V A V' (1/S) U' */ if (isim != 0) { /* Compute S (singular values of the eigenvector matrix) */ /* according to CONDS and MODES */ slatm1_(modes, conds, &c__0, &c__0, &iseed[1], &ds[1], n, &iinfo); if (iinfo != 0) { *info = 3; return 0; } /* Multiply by V and V' */ clarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo); if (iinfo != 0) { *info = 4; return 0; } /* Multiply by S and (1/S) */ i__1 = *n; for (j = 1; j <= i__1; ++j) { csscal_(n, &ds[j], &a[j + a_dim1], lda); if (ds[j] != 0.f) { r__1 = 1.f / ds[j]; csscal_(n, &r__1, &a[j * a_dim1 + 1], &c__1); } else { *info = 5; return 0; } /* L50: */ } /* Multiply by U and U' */ clarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo); if (iinfo != 0) { *info = 4; return 0; } } /* 5) Reduce the bandwidth. */ if (*kl < *n - 1) { /* Reduce bandwidth -- kill column */ i__1 = *n - 1; for (jcr = *kl + 1; jcr <= i__1; ++jcr) { ic = jcr - *kl; irows = *n + 1 - jcr; icols = *n + *kl - jcr; ccopy_(&irows, &a[jcr + ic * a_dim1], &c__1, &work[1], &c__1); xnorms.r = work[1].r, xnorms.i = work[1].i; clarfg_(&irows, &xnorms, &work[2], &c__1, &tau); r_cnjg(&q__1, &tau); tau.r = q__1.r, tau.i = q__1.i; work[1].r = 1.f, work[1].i = 0.f; clarnd_(&q__1, &c__5, &iseed[1]); alpha.r = q__1.r, alpha.i = q__1.i; cgemv_("C", &irows, &icols, &c_b2, &a[jcr + (ic + 1) * a_dim1], lda, &work[1], &c__1, &c_b1, &work[irows + 1], &c__1); q__1.r = -tau.r, q__1.i = -tau.i; cgerc_(&irows, &icols, &q__1, &work[1], &c__1, &work[irows + 1], & c__1, &a[jcr + (ic + 1) * a_dim1], lda); cgemv_("N", n, &irows, &c_b2, &a[jcr * a_dim1 + 1], lda, &work[1], &c__1, &c_b1, &work[irows + 1], &c__1); r_cnjg(&q__2, &tau); q__1.r = -q__2.r, q__1.i = -q__2.i; cgerc_(n, &irows, &q__1, &work[irows + 1], &c__1, &work[1], &c__1, &a[jcr * a_dim1 + 1], lda); i__2 = jcr + ic * a_dim1; a[i__2].r = xnorms.r, a[i__2].i = xnorms.i; i__2 = irows - 1; claset_("Full", &i__2, &c__1, &c_b1, &c_b1, &a[jcr + 1 + ic * a_dim1], lda); i__2 = icols + 1; cscal_(&i__2, &alpha, &a[jcr + ic * a_dim1], lda); r_cnjg(&q__1, &alpha); cscal_(n, &q__1, &a[jcr * a_dim1 + 1], &c__1); /* L60: */ } } else if (*ku < *n - 1) { /* Reduce upper bandwidth -- kill a row at a time. */ i__1 = *n - 1; for (jcr = *ku + 1; jcr <= i__1; ++jcr) { ir = jcr - *ku; irows = *n + *ku - jcr; icols = *n + 1 - jcr; ccopy_(&icols, &a[ir + jcr * a_dim1], lda, &work[1], &c__1); xnorms.r = work[1].r, xnorms.i = work[1].i; clarfg_(&icols, &xnorms, &work[2], &c__1, &tau); r_cnjg(&q__1, &tau); tau.r = q__1.r, tau.i = q__1.i; work[1].r = 1.f, work[1].i = 0.f; i__2 = icols - 1; clacgv_(&i__2, &work[2], &c__1); clarnd_(&q__1, &c__5, &iseed[1]); alpha.r = q__1.r, alpha.i = q__1.i; cgemv_("N", &irows, &icols, &c_b2, &a[ir + 1 + jcr * a_dim1], lda, &work[1], &c__1, &c_b1, &work[icols + 1], &c__1); q__1.r = -tau.r, q__1.i = -tau.i; cgerc_(&irows, &icols, &q__1, &work[icols + 1], &c__1, &work[1], & c__1, &a[ir + 1 + jcr * a_dim1], lda); cgemv_("C", &icols, n, &c_b2, &a[jcr + a_dim1], lda, &work[1], & c__1, &c_b1, &work[icols + 1], &c__1); r_cnjg(&q__2, &tau); q__1.r = -q__2.r, q__1.i = -q__2.i; cgerc_(&icols, n, &q__1, &work[1], &c__1, &work[icols + 1], &c__1, &a[jcr + a_dim1], lda); i__2 = ir + jcr * a_dim1; a[i__2].r = xnorms.r, a[i__2].i = xnorms.i; i__2 = icols - 1; claset_("Full", &c__1, &i__2, &c_b1, &c_b1, &a[ir + (jcr + 1) * a_dim1], lda); i__2 = irows + 1; cscal_(&i__2, &alpha, &a[ir + jcr * a_dim1], &c__1); r_cnjg(&q__1, &alpha); cscal_(n, &q__1, &a[jcr + a_dim1], lda); /* L70: */ } } /* Scale the matrix to have norm ANORM */ if (*anorm >= 0.f) { temp = clange_("M", n, n, &a[a_offset], lda, tempa); if (temp > 0.f) { ralpha = *anorm / temp; i__1 = *n; for (j = 1; j <= i__1; ++j) { csscal_(n, &ralpha, &a[j * a_dim1 + 1], &c__1); /* L80: */ } } } return 0; /* End of CLATME */ } /* clatme_ */
/* Subroutine */ int dstev_(char *jobz, integer *n, doublereal *d__, doublereal *e, doublereal *z__, integer *ldz, doublereal *work, integer *info) { /* -- LAPACK driver routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University September 30, 1994 Purpose ======= DSTEV computes all eigenvalues and, optionally, eigenvectors of a real symmetric tridiagonal matrix A. Arguments ========= JOBZ (input) CHARACTER*1 = 'N': Compute eigenvalues only; = 'V': Compute eigenvalues and eigenvectors. N (input) INTEGER The order of the matrix. N >= 0. D (input/output) DOUBLE PRECISION array, dimension (N) On entry, the n diagonal elements of the tridiagonal matrix A. On exit, if INFO = 0, the eigenvalues in ascending order. E (input/output) DOUBLE PRECISION array, dimension (N) On entry, the (n-1) subdiagonal elements of the tridiagonal matrix A, stored in elements 1 to N-1 of E; E(N) need not be set, but is used by the routine. On exit, the contents of E are destroyed. Z (output) DOUBLE PRECISION array, dimension (LDZ, N) If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal eigenvectors of the matrix A, with the i-th column of Z holding the eigenvector associated with D(i). If JOBZ = 'N', then Z is not referenced. LDZ (input) INTEGER The leading dimension of the array Z. LDZ >= 1, and if JOBZ = 'V', LDZ >= max(1,N). WORK (workspace) DOUBLE PRECISION array, dimension (max(1,2*N-2)) If JOBZ = 'N', WORK is not referenced. INFO (output) INTEGER = 0: successful exit < 0: if INFO = -i, the i-th argument had an illegal value > 0: if INFO = i, the algorithm failed to converge; i off-diagonal elements of E did not converge to zero. ===================================================================== Test the input parameters. Parameter adjustments */ /* Table of constant values */ static integer c__1 = 1; /* System generated locals */ integer z_dim1, z_offset, i__1; doublereal d__1; /* Builtin functions */ double sqrt(doublereal); /* Local variables */ static integer imax; static doublereal rmin, rmax, tnrm; extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, integer *); static doublereal sigma; extern logical lsame_(char *, char *); static logical wantz; extern doublereal dlamch_(char *); static integer iscale; static doublereal safmin; extern /* Subroutine */ int xerbla_(char *, integer *); static doublereal bignum; extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *); extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *, integer *), dsteqr_(char *, integer *, doublereal *, doublereal * , doublereal *, integer *, doublereal *, integer *); static doublereal smlnum, eps; #define z___ref(a_1,a_2) z__[(a_2)*z_dim1 + a_1] --d__; --e; z_dim1 = *ldz; z_offset = 1 + z_dim1 * 1; z__ -= z_offset; --work; /* Function Body */ wantz = lsame_(jobz, "V"); *info = 0; if (! (wantz || lsame_(jobz, "N"))) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*ldz < 1 || wantz && *ldz < *n) { *info = -6; } if (*info != 0) { i__1 = -(*info); xerbla_("DSTEV ", &i__1); return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } if (*n == 1) { if (wantz) { z___ref(1, 1) = 1.; } return 0; } /* Get machine constants. */ safmin = dlamch_("Safe minimum"); eps = dlamch_("Precision"); smlnum = safmin / eps; bignum = 1. / smlnum; rmin = sqrt(smlnum); rmax = sqrt(bignum); /* Scale matrix to allowable range, if necessary. */ iscale = 0; tnrm = dlanst_("M", n, &d__[1], &e[1]); if (tnrm > 0. && tnrm < rmin) { iscale = 1; sigma = rmin / tnrm; } else if (tnrm > rmax) { iscale = 1; sigma = rmax / tnrm; } if (iscale == 1) { dscal_(n, &sigma, &d__[1], &c__1); i__1 = *n - 1; dscal_(&i__1, &sigma, &e[1], &c__1); } /* For eigenvalues only, call DSTERF. For eigenvalues and eigenvectors, call DSTEQR. */ if (! wantz) { dsterf_(n, &d__[1], &e[1], info); } else { dsteqr_("I", n, &d__[1], &e[1], &z__[z_offset], ldz, &work[1], info); } /* If matrix was scaled, then rescale eigenvalues appropriately. */ if (iscale == 1) { if (*info == 0) { imax = *n; } else { imax = *info - 1; } d__1 = 1. / sigma; dscal_(&imax, &d__1, &d__[1], &c__1); } return 0; /* End of DSTEV */ } /* dstev_ */
int dtgsja_(char *jobu, char *jobv, char *jobq, int *m, int *p, int *n, int *k, int *l, double *a, int *lda, double *b, int *ldb, double *tola, double *tolb, double *alpha, double *beta, double *u, int *ldu, double *v, int *ldv, double *q, int * ldq, double *work, int *ncycle, int *info) { /* System generated locals */ int a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, u_dim1, u_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4; double d__1; /* Local variables */ int i__, j; double a1, a2, a3, b1, b2, b3, csq, csu, csv, snq, rwk, snu, snv; extern int drot_(int *, double *, int *, double *, int *, double *, double *); double gamma; extern int dscal_(int *, double *, double *, int *); extern int lsame_(char *, char *); extern int dcopy_(int *, double *, int *, double *, int *); int initq, initu, initv, wantq, upper; double error, ssmin; int wantu, wantv; extern int dlags2_(int *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *), dlapll_(int *, double *, int *, double *, int *, double *); int kcycle; extern int dlartg_(double *, double *, double *, double *, double *), dlaset_(char *, int *, int *, double *, double *, double *, int *), xerbla_(char *, int *); /* -- LAPACK routine (version 3.2) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* DTGSJA computes the generalized singular value decomposition (GSVD) */ /* of two float upper triangular (or trapezoidal) matrices A and B. */ /* On entry, it is assumed that matrices A and B have the following */ /* forms, which may be obtained by the preprocessing subroutine DGGSVP */ /* from a general M-by-N matrix A and P-by-N matrix B: */ /* N-K-L K L */ /* A = K ( 0 A12 A13 ) if M-K-L >= 0; */ /* L ( 0 0 A23 ) */ /* M-K-L ( 0 0 0 ) */ /* N-K-L K L */ /* A = K ( 0 A12 A13 ) if M-K-L < 0; */ /* M-K ( 0 0 A23 ) */ /* N-K-L K L */ /* B = L ( 0 0 B13 ) */ /* P-L ( 0 0 0 ) */ /* where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular */ /* upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0, */ /* otherwise A23 is (M-K)-by-L upper trapezoidal. */ /* On exit, */ /* U'*A*Q = D1*( 0 R ), V'*B*Q = D2*( 0 R ), */ /* where U, V and Q are orthogonal matrices, Z' denotes the transpose */ /* of Z, R is a nonsingular upper triangular matrix, and D1 and D2 are */ /* ``diagonal'' matrices, which are of the following structures: */ /* If M-K-L >= 0, */ /* K L */ /* D1 = K ( I 0 ) */ /* L ( 0 C ) */ /* M-K-L ( 0 0 ) */ /* K L */ /* D2 = L ( 0 S ) */ /* P-L ( 0 0 ) */ /* N-K-L K L */ /* ( 0 R ) = K ( 0 R11 R12 ) K */ /* L ( 0 0 R22 ) L */ /* where */ /* C = diag( ALPHA(K+1), ... , ALPHA(K+L) ), */ /* S = diag( BETA(K+1), ... , BETA(K+L) ), */ /* C**2 + S**2 = I. */ /* R is stored in A(1:K+L,N-K-L+1:N) on exit. */ /* If M-K-L < 0, */ /* K M-K K+L-M */ /* D1 = K ( I 0 0 ) */ /* M-K ( 0 C 0 ) */ /* K M-K K+L-M */ /* D2 = M-K ( 0 S 0 ) */ /* K+L-M ( 0 0 I ) */ /* P-L ( 0 0 0 ) */ /* N-K-L K M-K K+L-M */ /* ( 0 R ) = K ( 0 R11 R12 R13 ) */ /* M-K ( 0 0 R22 R23 ) */ /* K+L-M ( 0 0 0 R33 ) */ /* where */ /* C = diag( ALPHA(K+1), ... , ALPHA(M) ), */ /* S = diag( BETA(K+1), ... , BETA(M) ), */ /* C**2 + S**2 = I. */ /* R = ( R11 R12 R13 ) is stored in A(1:M, N-K-L+1:N) and R33 is stored */ /* ( 0 R22 R23 ) */ /* in B(M-K+1:L,N+M-K-L+1:N) on exit. */ /* The computation of the orthogonal transformation matrices U, V or Q */ /* is optional. These matrices may either be formed explicitly, or they */ /* may be postmultiplied into input matrices U1, V1, or Q1. */ /* Arguments */ /* ========= */ /* JOBU (input) CHARACTER*1 */ /* = 'U': U must contain an orthogonal matrix U1 on entry, and */ /* the product U1*U is returned; */ /* = 'I': U is initialized to the unit matrix, and the */ /* orthogonal matrix U is returned; */ /* = 'N': U is not computed. */ /* JOBV (input) CHARACTER*1 */ /* = 'V': V must contain an orthogonal matrix V1 on entry, and */ /* the product V1*V is returned; */ /* = 'I': V is initialized to the unit matrix, and the */ /* orthogonal matrix V is returned; */ /* = 'N': V is not computed. */ /* JOBQ (input) CHARACTER*1 */ /* = 'Q': Q must contain an orthogonal matrix Q1 on entry, and */ /* the product Q1*Q is returned; */ /* = 'I': Q is initialized to the unit matrix, and the */ /* orthogonal matrix Q is returned; */ /* = 'N': Q is not computed. */ /* M (input) INTEGER */ /* The number of rows of the matrix A. M >= 0. */ /* P (input) INTEGER */ /* The number of rows of the matrix B. P >= 0. */ /* N (input) INTEGER */ /* The number of columns of the matrices A and B. N >= 0. */ /* K (input) INTEGER */ /* L (input) INTEGER */ /* K and L specify the subblocks in the input matrices A and B: */ /* A23 = A(K+1:MIN(K+L,M),N-L+1:N) and B13 = B(1:L,N-L+1:N) */ /* of A and B, whose GSVD is going to be computed by DTGSJA. */ /* See Further details. */ /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */ /* On entry, the M-by-N matrix A. */ /* On exit, A(N-K+1:N,1:MIN(K+L,M) ) contains the triangular */ /* matrix R or part of R. See Purpose for details. */ /* LDA (input) INTEGER */ /* The leading dimension of the array A. LDA >= MAX(1,M). */ /* B (input/output) DOUBLE PRECISION array, dimension (LDB,N) */ /* On entry, the P-by-N matrix B. */ /* On exit, if necessary, B(M-K+1:L,N+M-K-L+1:N) contains */ /* a part of R. See Purpose for details. */ /* LDB (input) INTEGER */ /* The leading dimension of the array B. LDB >= MAX(1,P). */ /* TOLA (input) DOUBLE PRECISION */ /* TOLB (input) DOUBLE PRECISION */ /* TOLA and TOLB are the convergence criteria for the Jacobi- */ /* Kogbetliantz iteration procedure. Generally, they are the */ /* same as used in the preprocessing step, say */ /* TOLA = MAX(M,N)*norm(A)*MAZHEPS, */ /* TOLB = MAX(P,N)*norm(B)*MAZHEPS. */ /* ALPHA (output) DOUBLE PRECISION array, dimension (N) */ /* BETA (output) DOUBLE PRECISION array, dimension (N) */ /* On exit, ALPHA and BETA contain the generalized singular */ /* value pairs of A and B; */ /* ALPHA(1:K) = 1, */ /* BETA(1:K) = 0, */ /* and if M-K-L >= 0, */ /* ALPHA(K+1:K+L) = diag(C), */ /* BETA(K+1:K+L) = diag(S), */ /* or if M-K-L < 0, */ /* ALPHA(K+1:M)= C, ALPHA(M+1:K+L)= 0 */ /* BETA(K+1:M) = S, BETA(M+1:K+L) = 1. */ /* Furthermore, if K+L < N, */ /* ALPHA(K+L+1:N) = 0 and */ /* BETA(K+L+1:N) = 0. */ /* U (input/output) DOUBLE PRECISION array, dimension (LDU,M) */ /* On entry, if JOBU = 'U', U must contain a matrix U1 (usually */ /* the orthogonal matrix returned by DGGSVP). */ /* On exit, */ /* if JOBU = 'I', U contains the orthogonal matrix U; */ /* if JOBU = 'U', U contains the product U1*U. */ /* If JOBU = 'N', U is not referenced. */ /* LDU (input) INTEGER */ /* The leading dimension of the array U. LDU >= MAX(1,M) if */ /* JOBU = 'U'; LDU >= 1 otherwise. */ /* V (input/output) DOUBLE PRECISION array, dimension (LDV,P) */ /* On entry, if JOBV = 'V', V must contain a matrix V1 (usually */ /* the orthogonal matrix returned by DGGSVP). */ /* On exit, */ /* if JOBV = 'I', V contains the orthogonal matrix V; */ /* if JOBV = 'V', V contains the product V1*V. */ /* If JOBV = 'N', V is not referenced. */ /* LDV (input) INTEGER */ /* The leading dimension of the array V. LDV >= MAX(1,P) if */ /* JOBV = 'V'; LDV >= 1 otherwise. */ /* Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N) */ /* On entry, if JOBQ = 'Q', Q must contain a matrix Q1 (usually */ /* the orthogonal matrix returned by DGGSVP). */ /* On exit, */ /* if JOBQ = 'I', Q contains the orthogonal matrix Q; */ /* if JOBQ = 'Q', Q contains the product Q1*Q. */ /* If JOBQ = 'N', Q is not referenced. */ /* LDQ (input) INTEGER */ /* The leading dimension of the array Q. LDQ >= MAX(1,N) if */ /* JOBQ = 'Q'; LDQ >= 1 otherwise. */ /* WORK (workspace) DOUBLE PRECISION array, dimension (2*N) */ /* NCYCLE (output) INTEGER */ /* The number of cycles required for convergence. */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value. */ /* = 1: the procedure does not converge after MAXIT cycles. */ /* Internal Parameters */ /* =================== */ /* MAXIT INTEGER */ /* MAXIT specifies the total loops that the iterative procedure */ /* may take. If after MAXIT cycles, the routine fails to */ /* converge, we return INFO = 1. */ /* Further Details */ /* =============== */ /* DTGSJA essentially uses a variant of Kogbetliantz algorithm to reduce */ /* MIN(L,M-K)-by-L triangular (or trapezoidal) matrix A23 and L-by-L */ /* matrix B13 to the form: */ /* U1'*A13*Q1 = C1*R1; V1'*B13*Q1 = S1*R1, */ /* where U1, V1 and Q1 are orthogonal matrix, and Z' is the transpose */ /* of Z. C1 and S1 are diagonal matrices satisfying */ /* C1**2 + S1**2 = I, */ /* and R1 is an L-by-L nonsingular upper triangular matrix. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Decode and test the input parameters */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; --alpha; --beta; u_dim1 = *ldu; u_offset = 1 + u_dim1; u -= u_offset; v_dim1 = *ldv; v_offset = 1 + v_dim1; v -= v_offset; q_dim1 = *ldq; q_offset = 1 + q_dim1; q -= q_offset; --work; /* Function Body */ initu = lsame_(jobu, "I"); wantu = initu || lsame_(jobu, "U"); initv = lsame_(jobv, "I"); wantv = initv || lsame_(jobv, "V"); initq = lsame_(jobq, "I"); wantq = initq || lsame_(jobq, "Q"); *info = 0; if (! (initu || wantu || lsame_(jobu, "N"))) { *info = -1; } else if (! (initv || wantv || lsame_(jobv, "N"))) { *info = -2; } else if (! (initq || wantq || lsame_(jobq, "N"))) { *info = -3; } else if (*m < 0) { *info = -4; } else if (*p < 0) { *info = -5; } else if (*n < 0) { *info = -6; } else if (*lda < MAX(1,*m)) { *info = -10; } else if (*ldb < MAX(1,*p)) { *info = -12; } else if (*ldu < 1 || wantu && *ldu < *m) { *info = -18; } else if (*ldv < 1 || wantv && *ldv < *p) { *info = -20; } else if (*ldq < 1 || wantq && *ldq < *n) { *info = -22; } if (*info != 0) { i__1 = -(*info); xerbla_("DTGSJA", &i__1); return 0; } /* Initialize U, V and Q, if necessary */ if (initu) { dlaset_("Full", m, m, &c_b13, &c_b14, &u[u_offset], ldu); } if (initv) { dlaset_("Full", p, p, &c_b13, &c_b14, &v[v_offset], ldv); } if (initq) { dlaset_("Full", n, n, &c_b13, &c_b14, &q[q_offset], ldq); } /* Loop until convergence */ upper = FALSE; for (kcycle = 1; kcycle <= 40; ++kcycle) { upper = ! upper; i__1 = *l - 1; for (i__ = 1; i__ <= i__1; ++i__) { i__2 = *l; for (j = i__ + 1; j <= i__2; ++j) { a1 = 0.; a2 = 0.; a3 = 0.; if (*k + i__ <= *m) { a1 = a[*k + i__ + (*n - *l + i__) * a_dim1]; } if (*k + j <= *m) { a3 = a[*k + j + (*n - *l + j) * a_dim1]; } b1 = b[i__ + (*n - *l + i__) * b_dim1]; b3 = b[j + (*n - *l + j) * b_dim1]; if (upper) { if (*k + i__ <= *m) { a2 = a[*k + i__ + (*n - *l + j) * a_dim1]; } b2 = b[i__ + (*n - *l + j) * b_dim1]; } else { if (*k + j <= *m) { a2 = a[*k + j + (*n - *l + i__) * a_dim1]; } b2 = b[j + (*n - *l + i__) * b_dim1]; } dlags2_(&upper, &a1, &a2, &a3, &b1, &b2, &b3, &csu, &snu, & csv, &snv, &csq, &snq); /* Update (K+I)-th and (K+J)-th rows of matrix A: U'*A */ if (*k + j <= *m) { drot_(l, &a[*k + j + (*n - *l + 1) * a_dim1], lda, &a[*k + i__ + (*n - *l + 1) * a_dim1], lda, &csu, &snu); } /* Update I-th and J-th rows of matrix B: V'*B */ drot_(l, &b[j + (*n - *l + 1) * b_dim1], ldb, &b[i__ + (*n - * l + 1) * b_dim1], ldb, &csv, &snv); /* Update (N-L+I)-th and (N-L+J)-th columns of matrices */ /* A and B: A*Q and B*Q */ /* Computing MIN */ i__4 = *k + *l; i__3 = MIN(i__4,*m); drot_(&i__3, &a[(*n - *l + j) * a_dim1 + 1], &c__1, &a[(*n - * l + i__) * a_dim1 + 1], &c__1, &csq, &snq); drot_(l, &b[(*n - *l + j) * b_dim1 + 1], &c__1, &b[(*n - *l + i__) * b_dim1 + 1], &c__1, &csq, &snq); if (upper) { if (*k + i__ <= *m) { a[*k + i__ + (*n - *l + j) * a_dim1] = 0.; } b[i__ + (*n - *l + j) * b_dim1] = 0.; } else { if (*k + j <= *m) { a[*k + j + (*n - *l + i__) * a_dim1] = 0.; } b[j + (*n - *l + i__) * b_dim1] = 0.; } /* Update orthogonal matrices U, V, Q, if desired. */ if (wantu && *k + j <= *m) { drot_(m, &u[(*k + j) * u_dim1 + 1], &c__1, &u[(*k + i__) * u_dim1 + 1], &c__1, &csu, &snu); } if (wantv) { drot_(p, &v[j * v_dim1 + 1], &c__1, &v[i__ * v_dim1 + 1], &c__1, &csv, &snv); } if (wantq) { drot_(n, &q[(*n - *l + j) * q_dim1 + 1], &c__1, &q[(*n - * l + i__) * q_dim1 + 1], &c__1, &csq, &snq); } /* L10: */ } /* L20: */ } if (! upper) { /* The matrices A13 and B13 were lower triangular at the start */ /* of the cycle, and are now upper triangular. */ /* Convergence test: test the parallelism of the corresponding */ /* rows of A and B. */ error = 0.; /* Computing MIN */ i__2 = *l, i__3 = *m - *k; i__1 = MIN(i__2,i__3); for (i__ = 1; i__ <= i__1; ++i__) { i__2 = *l - i__ + 1; dcopy_(&i__2, &a[*k + i__ + (*n - *l + i__) * a_dim1], lda, & work[1], &c__1); i__2 = *l - i__ + 1; dcopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &work[* l + 1], &c__1); i__2 = *l - i__ + 1; dlapll_(&i__2, &work[1], &c__1, &work[*l + 1], &c__1, &ssmin); error = MAX(error,ssmin); /* L30: */ } if (ABS(error) <= MIN(*tola,*tolb)) { goto L50; } } /* End of cycle loop */ /* L40: */ } /* The algorithm has not converged after MAXIT cycles. */ *info = 1; goto L100; L50: /* If ERROR <= MIN(TOLA,TOLB), then the algorithm has converged. */ /* Compute the generalized singular value pairs (ALPHA, BETA), and */ /* set the triangular matrix R to array A. */ i__1 = *k; for (i__ = 1; i__ <= i__1; ++i__) { alpha[i__] = 1.; beta[i__] = 0.; /* L60: */ } /* Computing MIN */ i__2 = *l, i__3 = *m - *k; i__1 = MIN(i__2,i__3); for (i__ = 1; i__ <= i__1; ++i__) { a1 = a[*k + i__ + (*n - *l + i__) * a_dim1]; b1 = b[i__ + (*n - *l + i__) * b_dim1]; if (a1 != 0.) { gamma = b1 / a1; /* change sign if necessary */ if (gamma < 0.) { i__2 = *l - i__ + 1; dscal_(&i__2, &c_b43, &b[i__ + (*n - *l + i__) * b_dim1], ldb) ; if (wantv) { dscal_(p, &c_b43, &v[i__ * v_dim1 + 1], &c__1); } } d__1 = ABS(gamma); dlartg_(&d__1, &c_b14, &beta[*k + i__], &alpha[*k + i__], &rwk); if (alpha[*k + i__] >= beta[*k + i__]) { i__2 = *l - i__ + 1; d__1 = 1. / alpha[*k + i__]; dscal_(&i__2, &d__1, &a[*k + i__ + (*n - *l + i__) * a_dim1], lda); } else { i__2 = *l - i__ + 1; d__1 = 1. / beta[*k + i__]; dscal_(&i__2, &d__1, &b[i__ + (*n - *l + i__) * b_dim1], ldb); i__2 = *l - i__ + 1; dcopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k + i__ + (*n - *l + i__) * a_dim1], lda); } } else { alpha[*k + i__] = 0.; beta[*k + i__] = 1.; i__2 = *l - i__ + 1; dcopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k + i__ + (*n - *l + i__) * a_dim1], lda); } /* L70: */ } /* Post-assignment */ i__1 = *k + *l; for (i__ = *m + 1; i__ <= i__1; ++i__) { alpha[i__] = 0.; beta[i__] = 1.; /* L80: */ } if (*k + *l < *n) { i__1 = *n; for (i__ = *k + *l + 1; i__ <= i__1; ++i__) { alpha[i__] = 0.; beta[i__] = 0.; /* L90: */ } } L100: *ncycle = kcycle; return 0; /* End of DTGSJA */ } /* dtgsja_ */
/* Subroutine */ int dchktp_(logical *dotype, integer *nn, integer *nval, integer *nns, integer *nsval, doublereal *thresh, logical *tsterr, integer *nmax, doublereal *ap, doublereal *ainvp, doublereal *b, doublereal *x, doublereal *xact, doublereal *work, doublereal *rwork, integer *iwork, integer *nout) { /* Initialized data */ static integer iseedy[4] = { 1988,1989,1990,1991 }; static char uplos[1*2] = "U" "L"; static char transs[1*3] = "N" "T" "C"; /* Format strings */ static char fmt_9999[] = "(\002 UPLO='\002,a1,\002', DIAG='\002,a1,\002'" ", N=\002,i5,\002, type \002,i2,\002, test(\002,i2,\002)= \002,g1" "2.5)"; static char fmt_9998[] = "(\002 UPLO='\002,a1,\002', TRANS='\002,a1,\002" "', DIAG='\002,a1,\002', N=\002,i5,\002', NRHS=\002,i5,\002, type " "\002,i2,\002, test(\002,i2,\002)= \002,g12.5)"; static char fmt_9997[] = "(1x,a,\002( '\002,a1,\002', '\002,a1,\002', " "'\002,a1,\002',\002,i5,\002, ... ), type \002,i2,\002, test(\002" ",i2,\002)=\002,g12.5)"; static char fmt_9996[] = "(1x,a,\002( '\002,a1,\002', '\002,a1,\002', " "'\002,a1,\002', '\002,a1,\002',\002,i5,\002, ... ), type \002,i2," "\002, test(\002,i2,\002)=\002,g12.5)"; /* System generated locals */ address a__1[2], a__2[3], a__3[4]; integer i__1, i__2[2], i__3, i__4[3], i__5[4]; char ch__1[2], ch__2[3], ch__3[4]; /* Builtin functions */ /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen), s_cat(char *, char **, integer *, integer *, ftnlen); integer s_wsfe(cilist *), do_fio(integer *, char *, ftnlen), e_wsfe(void); /* Local variables */ integer i__, k, n, in, lda, lap; char diag[1]; integer imat, info; char path[3]; integer irhs, nrhs; char norm[1], uplo[1]; integer nrun; extern /* Subroutine */ int alahd_(integer *, char *); integer idiag; doublereal scale; extern /* Subroutine */ int dget04_(integer *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *); integer nfail, iseed[4]; extern logical lsame_(char *, char *); doublereal rcond, anorm; integer itran; extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, doublereal *, integer *), dtpt01_(char *, char *, integer *, doublereal *, doublereal *, doublereal *, doublereal *, doublereal *), dtpt02_(char *, char *, char *, integer *, integer *, doublereal *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *), dtpt03_(char *, char *, char *, integer *, integer *, doublereal *, doublereal *, doublereal *, doublereal *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *), dtpt05_(char *, char *, char *, integer *, integer *, doublereal *, doublereal *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *, doublereal *), dtpt06_( doublereal *, doublereal *, char *, char *, integer *, doublereal *, doublereal *, doublereal *); char trans[1]; integer iuplo, nerrs; char xtype[1]; extern /* Subroutine */ int alaerh_(char *, char *, integer *, integer *, char *, integer *, integer *, integer *, integer *, integer *, integer *, integer *, integer *, integer *); doublereal rcondc; extern /* Subroutine */ int dlacpy_(char *, integer *, integer *, doublereal *, integer *, doublereal *, integer *); doublereal rcondi; extern /* Subroutine */ int dlarhs_(char *, char *, char *, char *, integer *, integer *, integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, integer *, integer *, integer *); extern doublereal dlantp_(char *, char *, char *, integer *, doublereal *, doublereal *); doublereal rcondo; extern /* Subroutine */ int alasum_(char *, integer *, integer *, integer *, integer *), dlatps_(char *, char *, char *, char *, integer *, doublereal *, doublereal *, doublereal *, doublereal *, integer *); doublereal ainvnm; extern /* Subroutine */ int dlattp_(integer *, char *, char *, char *, integer *, integer *, doublereal *, doublereal *, doublereal *, integer *), dtpcon_(char *, char *, char * , integer *, doublereal *, doublereal *, doublereal *, integer *, integer *), derrtr_(char *, integer *), dtprfs_(char *, char *, char *, integer *, integer *, doublereal *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *, doublereal *, integer *, integer *), dtptri_(char *, char *, integer *, doublereal *, integer *); doublereal result[9]; extern /* Subroutine */ int dtptrs_(char *, char *, char *, integer *, integer *, doublereal *, doublereal *, integer *, integer *); /* Fortran I/O blocks */ static cilist io___26 = { 0, 0, 0, fmt_9999, 0 }; static cilist io___34 = { 0, 0, 0, fmt_9998, 0 }; static cilist io___36 = { 0, 0, 0, fmt_9997, 0 }; static cilist io___38 = { 0, 0, 0, fmt_9996, 0 }; static cilist io___39 = { 0, 0, 0, fmt_9996, 0 }; /* -- LAPACK test routine (version 3.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* DCHKTP tests DTPTRI, -TRS, -RFS, and -CON, and DLATPS */ /* Arguments */ /* ========= */ /* DOTYPE (input) LOGICAL array, dimension (NTYPES) */ /* The matrix types to be used for testing. Matrices of type j */ /* (for 1 <= j <= NTYPES) are used for testing if DOTYPE(j) = */ /* .TRUE.; if DOTYPE(j) = .FALSE., then type j is not used. */ /* NN (input) INTEGER */ /* The number of values of N contained in the vector NVAL. */ /* NVAL (input) INTEGER array, dimension (NN) */ /* The values of the matrix column dimension N. */ /* NNS (input) INTEGER */ /* The number of values of NRHS contained in the vector NSVAL. */ /* NSVAL (input) INTEGER array, dimension (NNS) */ /* The values of the number of right hand sides NRHS. */ /* THRESH (input) DOUBLE PRECISION */ /* The threshold value for the test ratios. A result is */ /* included in the output file if RESULT >= THRESH. To have */ /* every test ratio printed, use THRESH = 0. */ /* TSTERR (input) LOGICAL */ /* Flag that indicates whether error exits are to be tested. */ /* NMAX (input) INTEGER */ /* The leading dimension of the work arrays. NMAX >= the */ /* maximumm value of N in NVAL. */ /* AP (workspace) DOUBLE PRECISION array, dimension */ /* (NMAX*(NMAX+1)/2) */ /* AINVP (workspace) DOUBLE PRECISION array, dimension */ /* (NMAX*(NMAX+1)/2) */ /* B (workspace) DOUBLE PRECISION array, dimension (NMAX*NSMAX) */ /* where NSMAX is the largest entry in NSVAL. */ /* X (workspace) DOUBLE PRECISION array, dimension (NMAX*NSMAX) */ /* XACT (workspace) DOUBLE PRECISION array, dimension (NMAX*NSMAX) */ /* WORK (workspace) DOUBLE PRECISION array, dimension */ /* (NMAX*max(3,NSMAX)) */ /* IWORK (workspace) INTEGER array, dimension (NMAX) */ /* RWORK (workspace) DOUBLE PRECISION array, dimension */ /* (max(NMAX,2*NSMAX)) */ /* NOUT (input) INTEGER */ /* The unit number for output. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Scalars in Common .. */ /* .. */ /* .. Common blocks .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Data statements .. */ /* Parameter adjustments */ --iwork; --rwork; --work; --xact; --x; --b; --ainvp; --ap; --nsval; --nval; --dotype; /* Function Body */ /* .. */ /* .. Executable Statements .. */ /* Initialize constants and the random number seed. */ s_copy(path, "Double precision", (ftnlen)1, (ftnlen)16); s_copy(path + 1, "TP", (ftnlen)2, (ftnlen)2); nrun = 0; nfail = 0; nerrs = 0; for (i__ = 1; i__ <= 4; ++i__) { iseed[i__ - 1] = iseedy[i__ - 1]; /* L10: */ } /* Test the error exits */ if (*tsterr) { derrtr_(path, nout); } infoc_1.infot = 0; i__1 = *nn; for (in = 1; in <= i__1; ++in) { /* Do for each value of N in NVAL */ n = nval[in]; lda = max(1,n); lap = lda * (lda + 1) / 2; *(unsigned char *)xtype = 'N'; for (imat = 1; imat <= 10; ++imat) { /* Do the tests only if DOTYPE( IMAT ) is true. */ if (! dotype[imat]) { goto L70; } for (iuplo = 1; iuplo <= 2; ++iuplo) { /* Do first for UPLO = 'U', then for UPLO = 'L' */ *(unsigned char *)uplo = *(unsigned char *)&uplos[iuplo - 1]; /* Call DLATTP to generate a triangular test matrix. */ s_copy(srnamc_1.srnamt, "DLATTP", (ftnlen)32, (ftnlen)6); dlattp_(&imat, uplo, "No transpose", diag, iseed, &n, &ap[1], &x[1], &work[1], &info); /* Set IDIAG = 1 for non-unit matrices, 2 for unit. */ if (lsame_(diag, "N")) { idiag = 1; } else { idiag = 2; } /* + TEST 1 */ /* Form the inverse of A. */ if (n > 0) { dcopy_(&lap, &ap[1], &c__1, &ainvp[1], &c__1); } s_copy(srnamc_1.srnamt, "DTPTRI", (ftnlen)32, (ftnlen)6); dtptri_(uplo, diag, &n, &ainvp[1], &info); /* Check error code from DTPTRI. */ if (info != 0) { /* Writing concatenation */ i__2[0] = 1, a__1[0] = uplo; i__2[1] = 1, a__1[1] = diag; s_cat(ch__1, a__1, i__2, &c__2, (ftnlen)2); alaerh_(path, "DTPTRI", &info, &c__0, ch__1, &n, &n, & c_n1, &c_n1, &c_n1, &imat, &nfail, &nerrs, nout); } /* Compute the infinity-norm condition number of A. */ anorm = dlantp_("I", uplo, diag, &n, &ap[1], &rwork[1]); ainvnm = dlantp_("I", uplo, diag, &n, &ainvp[1], &rwork[1]); if (anorm <= 0. || ainvnm <= 0.) { rcondi = 1.; } else { rcondi = 1. / anorm / ainvnm; } /* Compute the residual for the triangular matrix times its */ /* inverse. Also compute the 1-norm condition number of A. */ dtpt01_(uplo, diag, &n, &ap[1], &ainvp[1], &rcondo, &rwork[1], result); /* Print the test ratio if it is .GE. THRESH. */ if (result[0] >= *thresh) { if (nfail == 0 && nerrs == 0) { alahd_(nout, path); } io___26.ciunit = *nout; s_wsfe(&io___26); do_fio(&c__1, uplo, (ftnlen)1); do_fio(&c__1, diag, (ftnlen)1); do_fio(&c__1, (char *)&n, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&imat, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&c__1, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&result[0], (ftnlen)sizeof( doublereal)); e_wsfe(); ++nfail; } ++nrun; i__3 = *nns; for (irhs = 1; irhs <= i__3; ++irhs) { nrhs = nsval[irhs]; *(unsigned char *)xtype = 'N'; for (itran = 1; itran <= 3; ++itran) { /* Do for op(A) = A, A**T, or A**H. */ *(unsigned char *)trans = *(unsigned char *)&transs[ itran - 1]; if (itran == 1) { *(unsigned char *)norm = 'O'; rcondc = rcondo; } else { *(unsigned char *)norm = 'I'; rcondc = rcondi; } /* + TEST 2 */ /* Solve and compute residual for op(A)*x = b. */ s_copy(srnamc_1.srnamt, "DLARHS", (ftnlen)32, (ftnlen) 6); dlarhs_(path, xtype, uplo, trans, &n, &n, &c__0, & idiag, &nrhs, &ap[1], &lap, &xact[1], &lda, & b[1], &lda, iseed, &info); *(unsigned char *)xtype = 'C'; dlacpy_("Full", &n, &nrhs, &b[1], &lda, &x[1], &lda); s_copy(srnamc_1.srnamt, "DTPTRS", (ftnlen)32, (ftnlen) 6); dtptrs_(uplo, trans, diag, &n, &nrhs, &ap[1], &x[1], & lda, &info); /* Check error code from DTPTRS. */ if (info != 0) { /* Writing concatenation */ i__4[0] = 1, a__2[0] = uplo; i__4[1] = 1, a__2[1] = trans; i__4[2] = 1, a__2[2] = diag; s_cat(ch__2, a__2, i__4, &c__3, (ftnlen)3); alaerh_(path, "DTPTRS", &info, &c__0, ch__2, &n, & n, &c_n1, &c_n1, &c_n1, &imat, &nfail, & nerrs, nout); } dtpt02_(uplo, trans, diag, &n, &nrhs, &ap[1], &x[1], & lda, &b[1], &lda, &work[1], &result[1]); /* + TEST 3 */ /* Check solution from generated exact solution. */ dget04_(&n, &nrhs, &x[1], &lda, &xact[1], &lda, & rcondc, &result[2]); /* + TESTS 4, 5, and 6 */ /* Use iterative refinement to improve the solution and */ /* compute error bounds. */ s_copy(srnamc_1.srnamt, "DTPRFS", (ftnlen)32, (ftnlen) 6); dtprfs_(uplo, trans, diag, &n, &nrhs, &ap[1], &b[1], & lda, &x[1], &lda, &rwork[1], &rwork[nrhs + 1], &work[1], &iwork[1], &info); /* Check error code from DTPRFS. */ if (info != 0) { /* Writing concatenation */ i__4[0] = 1, a__2[0] = uplo; i__4[1] = 1, a__2[1] = trans; i__4[2] = 1, a__2[2] = diag; s_cat(ch__2, a__2, i__4, &c__3, (ftnlen)3); alaerh_(path, "DTPRFS", &info, &c__0, ch__2, &n, & n, &c_n1, &c_n1, &nrhs, &imat, &nfail, & nerrs, nout); } dget04_(&n, &nrhs, &x[1], &lda, &xact[1], &lda, & rcondc, &result[3]); dtpt05_(uplo, trans, diag, &n, &nrhs, &ap[1], &b[1], & lda, &x[1], &lda, &xact[1], &lda, &rwork[1], & rwork[nrhs + 1], &result[4]); /* Print information about the tests that did not pass */ /* the threshold. */ for (k = 2; k <= 6; ++k) { if (result[k - 1] >= *thresh) { if (nfail == 0 && nerrs == 0) { alahd_(nout, path); } io___34.ciunit = *nout; s_wsfe(&io___34); do_fio(&c__1, uplo, (ftnlen)1); do_fio(&c__1, trans, (ftnlen)1); do_fio(&c__1, diag, (ftnlen)1); do_fio(&c__1, (char *)&n, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&nrhs, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&imat, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&k, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&result[k - 1], (ftnlen) sizeof(doublereal)); e_wsfe(); ++nfail; } /* L20: */ } nrun += 5; /* L30: */ } /* L40: */ } /* + TEST 7 */ /* Get an estimate of RCOND = 1/CNDNUM. */ for (itran = 1; itran <= 2; ++itran) { if (itran == 1) { *(unsigned char *)norm = 'O'; rcondc = rcondo; } else { *(unsigned char *)norm = 'I'; rcondc = rcondi; } s_copy(srnamc_1.srnamt, "DTPCON", (ftnlen)32, (ftnlen)6); dtpcon_(norm, uplo, diag, &n, &ap[1], &rcond, &work[1], & iwork[1], &info); /* Check error code from DTPCON. */ if (info != 0) { /* Writing concatenation */ i__4[0] = 1, a__2[0] = norm; i__4[1] = 1, a__2[1] = uplo; i__4[2] = 1, a__2[2] = diag; s_cat(ch__2, a__2, i__4, &c__3, (ftnlen)3); alaerh_(path, "DTPCON", &info, &c__0, ch__2, &n, &n, & c_n1, &c_n1, &c_n1, &imat, &nfail, &nerrs, nout); } dtpt06_(&rcond, &rcondc, uplo, diag, &n, &ap[1], &rwork[1] , &result[6]); /* Print the test ratio if it is .GE. THRESH. */ if (result[6] >= *thresh) { if (nfail == 0 && nerrs == 0) { alahd_(nout, path); } io___36.ciunit = *nout; s_wsfe(&io___36); do_fio(&c__1, "DTPCON", (ftnlen)6); do_fio(&c__1, norm, (ftnlen)1); do_fio(&c__1, uplo, (ftnlen)1); do_fio(&c__1, diag, (ftnlen)1); do_fio(&c__1, (char *)&n, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&imat, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&c__7, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&result[6], (ftnlen)sizeof( doublereal)); e_wsfe(); ++nfail; } ++nrun; /* L50: */ } /* L60: */ } L70: ; } /* Use pathological test matrices to test DLATPS. */ for (imat = 11; imat <= 18; ++imat) { /* Do the tests only if DOTYPE( IMAT ) is true. */ if (! dotype[imat]) { goto L100; } for (iuplo = 1; iuplo <= 2; ++iuplo) { /* Do first for UPLO = 'U', then for UPLO = 'L' */ *(unsigned char *)uplo = *(unsigned char *)&uplos[iuplo - 1]; for (itran = 1; itran <= 3; ++itran) { /* Do for op(A) = A, A**T, or A**H. */ *(unsigned char *)trans = *(unsigned char *)&transs[itran - 1]; /* Call DLATTP to generate a triangular test matrix. */ s_copy(srnamc_1.srnamt, "DLATTP", (ftnlen)32, (ftnlen)6); dlattp_(&imat, uplo, trans, diag, iseed, &n, &ap[1], &x[1] , &work[1], &info); /* + TEST 8 */ /* Solve the system op(A)*x = b. */ s_copy(srnamc_1.srnamt, "DLATPS", (ftnlen)32, (ftnlen)6); dcopy_(&n, &x[1], &c__1, &b[1], &c__1); dlatps_(uplo, trans, diag, "N", &n, &ap[1], &b[1], &scale, &rwork[1], &info); /* Check error code from DLATPS. */ if (info != 0) { /* Writing concatenation */ i__5[0] = 1, a__3[0] = uplo; i__5[1] = 1, a__3[1] = trans; i__5[2] = 1, a__3[2] = diag; i__5[3] = 1, a__3[3] = "N"; s_cat(ch__3, a__3, i__5, &c__4, (ftnlen)4); alaerh_(path, "DLATPS", &info, &c__0, ch__3, &n, &n, & c_n1, &c_n1, &c_n1, &imat, &nfail, &nerrs, nout); } dtpt03_(uplo, trans, diag, &n, &c__1, &ap[1], &scale, & rwork[1], &c_b103, &b[1], &lda, &x[1], &lda, & work[1], &result[7]); /* + TEST 9 */ /* Solve op(A)*x = b again with NORMIN = 'Y'. */ dcopy_(&n, &x[1], &c__1, &b[n + 1], &c__1); dlatps_(uplo, trans, diag, "Y", &n, &ap[1], &b[n + 1], & scale, &rwork[1], &info); /* Check error code from DLATPS. */ if (info != 0) { /* Writing concatenation */ i__5[0] = 1, a__3[0] = uplo; i__5[1] = 1, a__3[1] = trans; i__5[2] = 1, a__3[2] = diag; i__5[3] = 1, a__3[3] = "Y"; s_cat(ch__3, a__3, i__5, &c__4, (ftnlen)4); alaerh_(path, "DLATPS", &info, &c__0, ch__3, &n, &n, & c_n1, &c_n1, &c_n1, &imat, &nfail, &nerrs, nout); } dtpt03_(uplo, trans, diag, &n, &c__1, &ap[1], &scale, & rwork[1], &c_b103, &b[n + 1], &lda, &x[1], &lda, & work[1], &result[8]); /* Print information about the tests that did not pass */ /* the threshold. */ if (result[7] >= *thresh) { if (nfail == 0 && nerrs == 0) { alahd_(nout, path); } io___38.ciunit = *nout; s_wsfe(&io___38); do_fio(&c__1, "DLATPS", (ftnlen)6); do_fio(&c__1, uplo, (ftnlen)1); do_fio(&c__1, trans, (ftnlen)1); do_fio(&c__1, diag, (ftnlen)1); do_fio(&c__1, "N", (ftnlen)1); do_fio(&c__1, (char *)&n, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&imat, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&c__8, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&result[7], (ftnlen)sizeof( doublereal)); e_wsfe(); ++nfail; } if (result[8] >= *thresh) { if (nfail == 0 && nerrs == 0) { alahd_(nout, path); } io___39.ciunit = *nout; s_wsfe(&io___39); do_fio(&c__1, "DLATPS", (ftnlen)6); do_fio(&c__1, uplo, (ftnlen)1); do_fio(&c__1, trans, (ftnlen)1); do_fio(&c__1, diag, (ftnlen)1); do_fio(&c__1, "Y", (ftnlen)1); do_fio(&c__1, (char *)&n, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&imat, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&c__9, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&result[8], (ftnlen)sizeof( doublereal)); e_wsfe(); ++nfail; } nrun += 2; /* L80: */ } /* L90: */ } L100: ; } /* L110: */ } /* Print a summary of the results. */ alasum_(path, nout, &nfail, &nrun, &nerrs); return 0; /* End of DCHKTP */ } /* dchktp_ */
/* Subroutine */ int zpbtrf_(char *uplo, integer *n, integer *kd, doublecomplex *ab, integer *ldab, integer *info) { /* -- LAPACK routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University September 30, 1994 Purpose ======= ZPBTRF computes the Cholesky factorization of a complex Hermitian positive definite band matrix A. The factorization has the form A = U**H * U, if UPLO = 'U', or A = L * L**H, if UPLO = 'L', where U is an upper triangular matrix and L is lower triangular. Arguments ========= UPLO (input) CHARACTER*1 = 'U': Upper triangle of A is stored; = 'L': Lower triangle of A is stored. N (input) INTEGER The order of the matrix A. N >= 0. KD (input) INTEGER The number of superdiagonals of the matrix A if UPLO = 'U', or the number of subdiagonals if UPLO = 'L'. KD >= 0. AB (input/output) COMPLEX*16 array, dimension (LDAB,N) On entry, the upper or lower triangle of the Hermitian band matrix A, stored in the first KD+1 rows of the array. The j-th column of A is stored in the j-th column of the array AB as follows: if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). On exit, if INFO = 0, the triangular factor U or L from the Cholesky factorization A = U**H*U or A = L*L**H of the band matrix A, in the same storage format as A. LDAB (input) INTEGER The leading dimension of the array AB. LDAB >= KD+1. INFO (output) INTEGER = 0: successful exit < 0: if INFO = -i, the i-th argument had an illegal value > 0: if INFO = i, the leading minor of order i is not positive definite, and the factorization could not be completed. Further Details =============== The band storage scheme is illustrated by the following example, when N = 6, KD = 2, and UPLO = 'U': On entry: On exit: * * a13 a24 a35 a46 * * u13 u24 u35 u46 * a12 a23 a34 a45 a56 * u12 u23 u34 u45 u56 a11 a22 a33 a44 a55 a66 u11 u22 u33 u44 u55 u66 Similarly, if UPLO = 'L' the format of A is as follows: On entry: On exit: a11 a22 a33 a44 a55 a66 l11 l22 l33 l44 l55 l66 a21 a32 a43 a54 a65 * l21 l32 l43 l54 l65 * a31 a42 a53 a64 * * l31 l42 l53 l64 * * Array elements marked * are not used by the routine. Contributed by Peter Mayes and Giuseppe Radicati, IBM ECSEC, Rome, March 23, 1989 ===================================================================== Test the input parameters. Parameter adjustments */ /* Table of constant values */ static doublecomplex c_b1 = {1.,0.}; static integer c__1 = 1; static integer c_n1 = -1; static doublereal c_b21 = -1.; static doublereal c_b22 = 1.; static integer c__33 = 33; /* System generated locals */ integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4, i__5, i__6; doublecomplex z__1; /* Local variables */ static doublecomplex work[1056] /* was [33][32] */; static integer i__, j; extern logical lsame_(char *, char *); extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *), zherk_(char *, char *, integer *, integer *, doublereal *, doublecomplex *, integer *, doublereal *, doublecomplex *, integer *); static integer i2, i3; extern /* Subroutine */ int ztrsm_(char *, char *, char *, char *, integer *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *), zpbtf2_(char *, integer *, integer *, doublecomplex *, integer *, integer *); static integer ib, nb, ii, jj; extern /* Subroutine */ int zpotf2_(char *, integer *, doublecomplex *, integer *, integer *), xerbla_(char *, integer *); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *, ftnlen, ftnlen); #define work_subscr(a_1,a_2) (a_2)*33 + a_1 - 34 #define work_ref(a_1,a_2) work[work_subscr(a_1,a_2)] #define ab_subscr(a_1,a_2) (a_2)*ab_dim1 + a_1 #define ab_ref(a_1,a_2) ab[ab_subscr(a_1,a_2)] ab_dim1 = *ldab; ab_offset = 1 + ab_dim1 * 1; ab -= ab_offset; /* Function Body */ *info = 0; if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*kd < 0) { *info = -3; } else if (*ldab < *kd + 1) { *info = -5; } if (*info != 0) { i__1 = -(*info); xerbla_("ZPBTRF", &i__1); return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } /* Determine the block size for this environment */ nb = ilaenv_(&c__1, "ZPBTRF", uplo, n, kd, &c_n1, &c_n1, (ftnlen)6, ( ftnlen)1); /* The block size must not exceed the semi-bandwidth KD, and must not exceed the limit set by the size of the local array WORK. */ nb = min(nb,32); if (nb <= 1 || nb > *kd) { /* Use unblocked code */ zpbtf2_(uplo, n, kd, &ab[ab_offset], ldab, info); } else { /* Use blocked code */ if (lsame_(uplo, "U")) { /* Compute the Cholesky factorization of a Hermitian band matrix, given the upper triangle of the matrix in band storage. Zero the upper triangle of the work array. */ i__1 = nb; for (j = 1; j <= i__1; ++j) { i__2 = j - 1; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = work_subscr(i__, j); work[i__3].r = 0., work[i__3].i = 0.; /* L10: */ } /* L20: */ } /* Process the band matrix one diagonal block at a time. */ i__1 = *n; i__2 = nb; for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) { /* Computing MIN */ i__3 = nb, i__4 = *n - i__ + 1; ib = min(i__3,i__4); /* Factorize the diagonal block */ i__3 = *ldab - 1; zpotf2_(uplo, &ib, &ab_ref(*kd + 1, i__), &i__3, &ii); if (ii != 0) { *info = i__ + ii - 1; goto L150; } if (i__ + ib <= *n) { /* Update the relevant part of the trailing submatrix. If A11 denotes the diagonal block which has just been factorized, then we need to update the remaining blocks in the diagram: A11 A12 A13 A22 A23 A33 The numbers of rows and columns in the partitioning are IB, I2, I3 respectively. The blocks A12, A22 and A23 are empty if IB = KD. The upper triangle of A13 lies outside the band. Computing MIN */ i__3 = *kd - ib, i__4 = *n - i__ - ib + 1; i2 = min(i__3,i__4); /* Computing MIN */ i__3 = ib, i__4 = *n - i__ - *kd + 1; i3 = min(i__3,i__4); if (i2 > 0) { /* Update A12 */ i__3 = *ldab - 1; i__4 = *ldab - 1; ztrsm_("Left", "Upper", "Conjugate transpose", "Non-" "unit", &ib, &i2, &c_b1, &ab_ref(*kd + 1, i__), &i__3, &ab_ref(*kd + 1 - ib, i__ + ib), & i__4); /* Update A22 */ i__3 = *ldab - 1; i__4 = *ldab - 1; zherk_("Upper", "Conjugate transpose", &i2, &ib, & c_b21, &ab_ref(*kd + 1 - ib, i__ + ib), &i__3, &c_b22, &ab_ref(*kd + 1, i__ + ib), &i__4); } if (i3 > 0) { /* Copy the lower triangle of A13 into the work array. */ i__3 = i3; for (jj = 1; jj <= i__3; ++jj) { i__4 = ib; for (ii = jj; ii <= i__4; ++ii) { i__5 = work_subscr(ii, jj); i__6 = ab_subscr(ii - jj + 1, jj + i__ + *kd - 1); work[i__5].r = ab[i__6].r, work[i__5].i = ab[ i__6].i; /* L30: */ } /* L40: */ } /* Update A13 (in the work array). */ i__3 = *ldab - 1; ztrsm_("Left", "Upper", "Conjugate transpose", "Non-" "unit", &ib, &i3, &c_b1, &ab_ref(*kd + 1, i__), &i__3, work, &c__33); /* Update A23 */ if (i2 > 0) { z__1.r = -1., z__1.i = 0.; i__3 = *ldab - 1; i__4 = *ldab - 1; zgemm_("Conjugate transpose", "No transpose", &i2, &i3, &ib, &z__1, &ab_ref(*kd + 1 - ib, i__ + ib), &i__3, work, &c__33, &c_b1, & ab_ref(ib + 1, i__ + *kd), &i__4); } /* Update A33 */ i__3 = *ldab - 1; zherk_("Upper", "Conjugate transpose", &i3, &ib, & c_b21, work, &c__33, &c_b22, &ab_ref(*kd + 1, i__ + *kd), &i__3); /* Copy the lower triangle of A13 back into place. */ i__3 = i3; for (jj = 1; jj <= i__3; ++jj) { i__4 = ib; for (ii = jj; ii <= i__4; ++ii) { i__5 = ab_subscr(ii - jj + 1, jj + i__ + *kd - 1); i__6 = work_subscr(ii, jj); ab[i__5].r = work[i__6].r, ab[i__5].i = work[ i__6].i; /* L50: */ } /* L60: */ } } } /* L70: */ } } else { /* Compute the Cholesky factorization of a Hermitian band matrix, given the lower triangle of the matrix in band storage. Zero the lower triangle of the work array. */ i__2 = nb; for (j = 1; j <= i__2; ++j) { i__1 = nb; for (i__ = j + 1; i__ <= i__1; ++i__) { i__3 = work_subscr(i__, j); work[i__3].r = 0., work[i__3].i = 0.; /* L80: */ } /* L90: */ } /* Process the band matrix one diagonal block at a time. */ i__2 = *n; i__1 = nb; for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__1) { /* Computing MIN */ i__3 = nb, i__4 = *n - i__ + 1; ib = min(i__3,i__4); /* Factorize the diagonal block */ i__3 = *ldab - 1; zpotf2_(uplo, &ib, &ab_ref(1, i__), &i__3, &ii); if (ii != 0) { *info = i__ + ii - 1; goto L150; } if (i__ + ib <= *n) { /* Update the relevant part of the trailing submatrix. If A11 denotes the diagonal block which has just been factorized, then we need to update the remaining blocks in the diagram: A11 A21 A22 A31 A32 A33 The numbers of rows and columns in the partitioning are IB, I2, I3 respectively. The blocks A21, A22 and A32 are empty if IB = KD. The lower triangle of A31 lies outside the band. Computing MIN */ i__3 = *kd - ib, i__4 = *n - i__ - ib + 1; i2 = min(i__3,i__4); /* Computing MIN */ i__3 = ib, i__4 = *n - i__ - *kd + 1; i3 = min(i__3,i__4); if (i2 > 0) { /* Update A21 */ i__3 = *ldab - 1; i__4 = *ldab - 1; ztrsm_("Right", "Lower", "Conjugate transpose", "Non" "-unit", &i2, &ib, &c_b1, &ab_ref(1, i__), & i__3, &ab_ref(ib + 1, i__), &i__4); /* Update A22 */ i__3 = *ldab - 1; i__4 = *ldab - 1; zherk_("Lower", "No transpose", &i2, &ib, &c_b21, & ab_ref(ib + 1, i__), &i__3, &c_b22, &ab_ref(1, i__ + ib), &i__4); } if (i3 > 0) { /* Copy the upper triangle of A31 into the work array. */ i__3 = ib; for (jj = 1; jj <= i__3; ++jj) { i__4 = min(jj,i3); for (ii = 1; ii <= i__4; ++ii) { i__5 = work_subscr(ii, jj); i__6 = ab_subscr(*kd + 1 - jj + ii, jj + i__ - 1); work[i__5].r = ab[i__6].r, work[i__5].i = ab[ i__6].i; /* L100: */ } /* L110: */ } /* Update A31 (in the work array). */ i__3 = *ldab - 1; ztrsm_("Right", "Lower", "Conjugate transpose", "Non" "-unit", &i3, &ib, &c_b1, &ab_ref(1, i__), & i__3, work, &c__33); /* Update A32 */ if (i2 > 0) { z__1.r = -1., z__1.i = 0.; i__3 = *ldab - 1; i__4 = *ldab - 1; zgemm_("No transpose", "Conjugate transpose", &i3, &i2, &ib, &z__1, work, &c__33, &ab_ref( ib + 1, i__), &i__3, &c_b1, &ab_ref(*kd + 1 - ib, i__ + ib), &i__4); } /* Update A33 */ i__3 = *ldab - 1; zherk_("Lower", "No transpose", &i3, &ib, &c_b21, work, &c__33, &c_b22, &ab_ref(1, i__ + *kd), & i__3); /* Copy the upper triangle of A31 back into place. */ i__3 = ib; for (jj = 1; jj <= i__3; ++jj) { i__4 = min(jj,i3); for (ii = 1; ii <= i__4; ++ii) { i__5 = ab_subscr(*kd + 1 - jj + ii, jj + i__ - 1); i__6 = work_subscr(ii, jj); ab[i__5].r = work[i__6].r, ab[i__5].i = work[ i__6].i; /* L120: */ } /* L130: */ } } } /* L140: */ } } } return 0; L150: return 0; /* End of ZPBTRF */ } /* zpbtrf_ */
/* Subroutine */ int csycon_(char *uplo, integer *n, complex *a, integer *lda, integer *ipiv, real *anorm, real *rcond, complex *work, integer * info) { /* -- LAPACK routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University March 31, 1993 Purpose ======= CSYCON estimates the reciprocal of the condition number (in the 1-norm) of a complex symmetric matrix A using the factorization A = U*D*U**T or A = L*D*L**T computed by CSYTRF. An estimate is obtained for norm(inv(A)), and the reciprocal of the condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). Arguments ========= UPLO (input) CHARACTER*1 Specifies whether the details of the factorization are stored as an upper or lower triangular matrix. = 'U': Upper triangular, form is A = U*D*U**T; = 'L': Lower triangular, form is A = L*D*L**T. N (input) INTEGER The order of the matrix A. N >= 0. A (input) COMPLEX array, dimension (LDA,N) The block diagonal matrix D and the multipliers used to obtain the factor U or L as computed by CSYTRF. LDA (input) INTEGER The leading dimension of the array A. LDA >= max(1,N). IPIV (input) INTEGER array, dimension (N) Details of the interchanges and the block structure of D as determined by CSYTRF. ANORM (input) REAL The 1-norm of the original matrix A. RCOND (output) REAL The reciprocal of the condition number of the matrix A, computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an estimate of the 1-norm of inv(A) computed in this routine. WORK (workspace) COMPLEX array, dimension (2*N) INFO (output) INTEGER = 0: successful exit < 0: if INFO = -i, the i-th argument had an illegal value ===================================================================== Test the input parameters. Parameter adjustments */ /* Table of constant values */ static integer c__1 = 1; /* System generated locals */ integer a_dim1, a_offset, i__1, i__2; /* Local variables */ static integer kase, i__; extern logical lsame_(char *, char *); static logical upper; extern /* Subroutine */ int clacon_(integer *, complex *, complex *, real *, integer *), xerbla_(char *, integer *); static real ainvnm; extern /* Subroutine */ int csytrs_(char *, integer *, integer *, complex *, integer *, integer *, complex *, integer *, integer *); #define a_subscr(a_1,a_2) (a_2)*a_dim1 + a_1 #define a_ref(a_1,a_2) a[a_subscr(a_1,a_2)] a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; --ipiv; --work; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*lda < max(1,*n)) { *info = -4; } else if (*anorm < 0.f) { *info = -6; } if (*info != 0) { i__1 = -(*info); xerbla_("CSYCON", &i__1); return 0; } /* Quick return if possible */ *rcond = 0.f; if (*n == 0) { *rcond = 1.f; return 0; } else if (*anorm <= 0.f) { return 0; } /* Check that the diagonal matrix D is nonsingular. */ if (upper) { /* Upper triangular storage: examine D from bottom to top */ for (i__ = *n; i__ >= 1; --i__) { i__1 = a_subscr(i__, i__); if (ipiv[i__] > 0 && (a[i__1].r == 0.f && a[i__1].i == 0.f)) { return 0; } /* L10: */ } } else { /* Lower triangular storage: examine D from top to bottom. */ i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { i__2 = a_subscr(i__, i__); if (ipiv[i__] > 0 && (a[i__2].r == 0.f && a[i__2].i == 0.f)) { return 0; } /* L20: */ } } /* Estimate the 1-norm of the inverse. */ kase = 0; L30: clacon_(n, &work[*n + 1], &work[1], &ainvnm, &kase); if (kase != 0) { /* Multiply by inv(L*D*L') or inv(U*D*U'). */ csytrs_(uplo, n, &c__1, &a[a_offset], lda, &ipiv[1], &work[1], n, info); goto L30; } /* Compute the estimate of the reciprocal condition number. */ if (ainvnm != 0.f) { *rcond = 1.f / ainvnm / *anorm; } return 0; /* End of CSYCON */ } /* csycon_ */
doublereal dopgb_(char *subnam, integer *m, integer *n, integer *kl, integer * ku, integer *ipiv) { /* System generated locals */ integer i__1, i__2, i__3, i__4; doublereal ret_val; /* Builtin functions Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen); /* Local variables */ static doublereal adds; static logical sord, corz; static integer i__, j; extern logical lsame_(char *, char *); static char c1[1], c2[2], c3[3]; static doublereal mults, addfac; static integer km, jp, ju; static doublereal mulfac; extern logical lsamen_(integer *, char *, char *); /* -- LAPACK timing routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University June 30, 1999 Purpose ======= DOPGB counts operations for the LU factorization of a band matrix xGBTRF. Arguments ========= SUBNAM (input) CHARACTER*6 The name of the subroutine. M (input) INTEGER The number of rows of the coefficient matrix. M >= 0. N (input) INTEGER The number of columns of the coefficient matrix. N >= 0. KL (input) INTEGER The number of subdiagonals of the matrix. KL >= 0. KU (input) INTEGER The number of superdiagonals of the matrix. KU >= 0. IPIV (input) INTEGER array, dimension (min(M,N)) The vector of pivot indices from DGBTRF or ZGBTRF. ===================================================================== Parameter adjustments */ --ipiv; /* Function Body */ ret_val = 0.; mults = 0.; adds = 0.; *(unsigned char *)c1 = *(unsigned char *)subnam; s_copy(c2, subnam + 1, (ftnlen)2, (ftnlen)2); s_copy(c3, subnam + 3, (ftnlen)3, (ftnlen)3); sord = lsame_(c1, "S") || lsame_(c1, "D"); corz = lsame_(c1, "C") || lsame_(c1, "Z"); if (! (sord || corz)) { return ret_val; } if (lsame_(c1, "S") || lsame_(c1, "D")) { addfac = 1.; mulfac = 1.; } else { addfac = 2.; mulfac = 6.; } /* -------------------------- GB: General Band matrices -------------------------- */ if (lsamen_(&c__2, c2, "GB")) { /* xGBTRF: M, N, KL, KU => M, N, KL, KU */ if (lsamen_(&c__3, c3, "TRF")) { ju = 1; i__1 = min(*m,*n); for (j = 1; j <= i__1; ++j) { /* Computing MIN */ i__2 = *kl, i__3 = *m - j; km = min(i__2,i__3); jp = ipiv[j]; /* Computing MAX Computing MIN */ i__4 = jp + *ku; i__2 = ju, i__3 = min(i__4,*n); ju = max(i__2,i__3); if (km > 0) { mults += km * (ju + 1 - j); adds += km * (ju - j); } /* L10: */ } } /* --------------------------------- GT: General Tridiagonal matrices --------------------------------- */ } else if (lsamen_(&c__2, c2, "GT")) { /* xGTTRF: N => M */ if (lsamen_(&c__3, c3, "TRF")) { mults = (doublereal) (*m - 1 << 1); adds = (doublereal) (*m - 1); i__1 = *m - 2; for (i__ = 1; i__ <= i__1; ++i__) { if (ipiv[i__] != i__) { mults += 1; } /* L20: */ } /* xGTTRS: N, NRHS => M, N */ } else if (lsamen_(&c__3, c3, "TRS")) { mults = (doublereal) ((*n << 2) * (*m - 1)); adds = (doublereal) (*n * 3 * (*m - 1)); /* xGTSV: N, NRHS => M, N */ } else if (lsamen_(&c__3, c3, "SV ")) { mults = (doublereal) (((*n << 2) + 2) * (*m - 1)); adds = (doublereal) ((*n * 3 + 1) * (*m - 1)); i__1 = *m - 2; for (i__ = 1; i__ <= i__1; ++i__) { if (ipiv[i__] != i__) { mults += 1; } /* L30: */ } } } ret_val = mulfac * mults + addfac * adds; return ret_val; /* End of DOPGB */ } /* dopgb_ */
/* Subroutine */ int dtpmv_(char *uplo, char *trans, char *diag, integer *n, doublereal *ap, doublereal *x, integer *incx, ftnlen uplo_len, ftnlen trans_len, ftnlen diag_len) { /* System generated locals */ integer i__1, i__2; /* Local variables */ integer info; doublereal temp; integer i__, j, k; extern logical lsame_(char *, char *, ftnlen, ftnlen); integer kk, ix, jx, kx; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); logical nounit; /* .. Scalar Arguments .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* DTPMV performs one of the matrix-vector operations */ /* x := A*x, or x := A'*x, */ /* where x is an n element vector and A is an n by n unit, or non-unit, */ /* upper or lower triangular matrix, supplied in packed form. */ /* Parameters */ /* ========== */ /* UPLO - CHARACTER*1. */ /* On entry, UPLO specifies whether the matrix is an upper or */ /* lower triangular matrix as follows: */ /* UPLO = 'U' or 'u' A is an upper triangular matrix. */ /* UPLO = 'L' or 'l' A is a lower triangular matrix. */ /* Unchanged on exit. */ /* TRANS - CHARACTER*1. */ /* On entry, TRANS specifies the operation to be performed as */ /* follows: */ /* TRANS = 'N' or 'n' x := A*x. */ /* TRANS = 'T' or 't' x := A'*x. */ /* TRANS = 'C' or 'c' x := A'*x. */ /* Unchanged on exit. */ /* DIAG - CHARACTER*1. */ /* On entry, DIAG specifies whether or not A is unit */ /* triangular as follows: */ /* DIAG = 'U' or 'u' A is assumed to be unit triangular. */ /* DIAG = 'N' or 'n' A is not assumed to be unit */ /* triangular. */ /* Unchanged on exit. */ /* N - INTEGER. */ /* On entry, N specifies the order of the matrix A. */ /* N must be at least zero. */ /* Unchanged on exit. */ /* AP - DOUBLE PRECISION array of DIMENSION at least */ /* ( ( n*( n + 1 ) )/2 ). */ /* Before entry with UPLO = 'U' or 'u', the array AP must */ /* contain the upper triangular matrix packed sequentially, */ /* column by column, so that AP( 1 ) contains a( 1, 1 ), */ /* AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 ) */ /* respectively, and so on. */ /* Before entry with UPLO = 'L' or 'l', the array AP must */ /* contain the lower triangular matrix packed sequentially, */ /* column by column, so that AP( 1 ) contains a( 1, 1 ), */ /* AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 ) */ /* respectively, and so on. */ /* Note that when DIAG = 'U' or 'u', the diagonal elements of */ /* A are not referenced, but are assumed to be unity. */ /* Unchanged on exit. */ /* X - DOUBLE PRECISION array of dimension at least */ /* ( 1 + ( n - 1 )*abs( INCX ) ). */ /* Before entry, the incremented array X must contain the n */ /* element vector x. On exit, X is overwritten with the */ /* tranformed vector x. */ /* INCX - INTEGER. */ /* On entry, INCX specifies the increment for the elements of */ /* X. INCX must not be zero. */ /* Unchanged on exit. */ /* Level 2 Blas routine. */ /* -- Written on 22-October-1986. */ /* Jack Dongarra, Argonne National Lab. */ /* Jeremy Du Croz, Nag Central Office. */ /* Sven Hammarling, Nag Central Office. */ /* Richard Hanson, Sandia National Labs. */ /* .. Parameters .. */ /* .. Local Scalars .. */ /* .. External Functions .. */ /* .. External Subroutines .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input parameters. */ /* Parameter adjustments */ --x; --ap; /* Function Body */ info = 0; if (! lsame_(uplo, "U", (ftnlen)1, (ftnlen)1) && ! lsame_(uplo, "L", ( ftnlen)1, (ftnlen)1)) { info = 1; } else if (! lsame_(trans, "N", (ftnlen)1, (ftnlen)1) && ! lsame_(trans, "T", (ftnlen)1, (ftnlen)1) && ! lsame_(trans, "C", (ftnlen)1, ( ftnlen)1)) { info = 2; } else if (! lsame_(diag, "U", (ftnlen)1, (ftnlen)1) && ! lsame_(diag, "N", (ftnlen)1, (ftnlen)1)) { info = 3; } else if (*n < 0) { info = 4; } else if (*incx == 0) { info = 7; } if (info != 0) { xerbla_("DTPMV ", &info, (ftnlen)6); return 0; } /* Quick return if possible. */ if (*n == 0) { return 0; } nounit = lsame_(diag, "N", (ftnlen)1, (ftnlen)1); /* Set up the start point in X if the increment is not unity. This */ /* will be ( N - 1 )*INCX too small for descending loops. */ if (*incx <= 0) { kx = 1 - (*n - 1) * *incx; } else if (*incx != 1) { kx = 1; } /* Start the operations. In this version the elements of AP are */ /* accessed sequentially with one pass through AP. */ if (lsame_(trans, "N", (ftnlen)1, (ftnlen)1)) { /* Form x:= A*x. */ if (lsame_(uplo, "U", (ftnlen)1, (ftnlen)1)) { kk = 1; if (*incx == 1) { i__1 = *n; for (j = 1; j <= i__1; ++j) { if (x[j] != 0.) { temp = x[j]; k = kk; i__2 = j - 1; for (i__ = 1; i__ <= i__2; ++i__) { x[i__] += temp * ap[k]; ++k; /* L10: */ } if (nounit) { x[j] *= ap[kk + j - 1]; } } kk += j; /* L20: */ } } else { jx = kx; i__1 = *n; for (j = 1; j <= i__1; ++j) { if (x[jx] != 0.) { temp = x[jx]; ix = kx; i__2 = kk + j - 2; for (k = kk; k <= i__2; ++k) { x[ix] += temp * ap[k]; ix += *incx; /* L30: */ } if (nounit) { x[jx] *= ap[kk + j - 1]; } } jx += *incx; kk += j; /* L40: */ } } } else { kk = *n * (*n + 1) / 2; if (*incx == 1) { for (j = *n; j >= 1; --j) { if (x[j] != 0.) { temp = x[j]; k = kk; i__1 = j + 1; for (i__ = *n; i__ >= i__1; --i__) { x[i__] += temp * ap[k]; --k; /* L50: */ } if (nounit) { x[j] *= ap[kk - *n + j]; } } kk -= *n - j + 1; /* L60: */ } } else { kx += (*n - 1) * *incx; jx = kx; for (j = *n; j >= 1; --j) { if (x[jx] != 0.) { temp = x[jx]; ix = kx; i__1 = kk - (*n - (j + 1)); for (k = kk; k >= i__1; --k) { x[ix] += temp * ap[k]; ix -= *incx; /* L70: */ } if (nounit) { x[jx] *= ap[kk - *n + j]; } } jx -= *incx; kk -= *n - j + 1; /* L80: */ } } } } else { /* Form x := A'*x. */ if (lsame_(uplo, "U", (ftnlen)1, (ftnlen)1)) { kk = *n * (*n + 1) / 2; if (*incx == 1) { for (j = *n; j >= 1; --j) { temp = x[j]; if (nounit) { temp *= ap[kk]; } k = kk - 1; for (i__ = j - 1; i__ >= 1; --i__) { temp += ap[k] * x[i__]; --k; /* L90: */ } x[j] = temp; kk -= j; /* L100: */ } } else { jx = kx + (*n - 1) * *incx; for (j = *n; j >= 1; --j) { temp = x[jx]; ix = jx; if (nounit) { temp *= ap[kk]; } i__1 = kk - j + 1; for (k = kk - 1; k >= i__1; --k) { ix -= *incx; temp += ap[k] * x[ix]; /* L110: */ } x[jx] = temp; jx -= *incx; kk -= j; /* L120: */ } } } else { kk = 1; if (*incx == 1) { i__1 = *n; for (j = 1; j <= i__1; ++j) { temp = x[j]; if (nounit) { temp *= ap[kk]; } k = kk + 1; i__2 = *n; for (i__ = j + 1; i__ <= i__2; ++i__) { temp += ap[k] * x[i__]; ++k; /* L130: */ } x[j] = temp; kk += *n - j + 1; /* L140: */ } } else { jx = kx; i__1 = *n; for (j = 1; j <= i__1; ++j) { temp = x[jx]; ix = jx; if (nounit) { temp *= ap[kk]; } i__2 = kk + *n - j; for (k = kk + 1; k <= i__2; ++k) { ix += *incx; temp += ap[k] * x[ix]; /* L150: */ } x[jx] = temp; jx += *incx; kk += *n - j + 1; /* L160: */ } } } } return 0; /* End of DTPMV . */ } /* dtpmv_ */
void zgscon(char *norm, SuperMatrix *L, SuperMatrix *U, double anorm, double *rcond, SuperLUStat_t *stat, int *info) { /* Local variables */ int kase, kase1, onenrm, i; double ainvnm; doublecomplex *work; extern int zrscl_(int *, doublecomplex *, doublecomplex *, int *); extern int zlacon_(int *, doublecomplex *, doublecomplex *, double *, int *); /* Test the input parameters. */ *info = 0; onenrm = *(unsigned char *)norm == '1' || lsame_(norm, "O"); if (! onenrm && ! lsame_(norm, "I")) *info = -1; else if (L->nrow < 0 || L->nrow != L->ncol || L->Stype != SLU_SC || L->Dtype != SLU_Z || L->Mtype != SLU_TRLU) *info = -2; else if (U->nrow < 0 || U->nrow != U->ncol || U->Stype != SLU_NC || U->Dtype != SLU_Z || U->Mtype != SLU_TRU) *info = -3; if (*info != 0) { i = -(*info); xerbla_("zgscon", &i); return; } /* Quick return if possible */ *rcond = 0.; if ( L->nrow == 0 || U->nrow == 0) { *rcond = 1.; return; } work = doublecomplexCalloc( 3*L->nrow ); if ( !work ) ABORT("Malloc fails for work arrays in zgscon."); /* Estimate the norm of inv(A). */ ainvnm = 0.; if ( onenrm ) kase1 = 1; else kase1 = 2; kase = 0; do { zlacon_(&L->nrow, &work[L->nrow], &work[0], &ainvnm, &kase); if (kase == 0) break; if (kase == kase1) { /* Multiply by inv(L). */ sp_ztrsv("L", "No trans", "Unit", L, U, &work[0], stat, info); /* Multiply by inv(U). */ sp_ztrsv("U", "No trans", "Non-unit", L, U, &work[0], stat, info); } else { /* Multiply by inv(U'). */ sp_ztrsv("U", "Transpose", "Non-unit", L, U, &work[0], stat, info); /* Multiply by inv(L'). */ sp_ztrsv("L", "Transpose", "Unit", L, U, &work[0], stat, info); } } while ( kase != 0 ); /* Compute the estimate of the reciprocal condition number. */ if (ainvnm != 0.) *rcond = (1. / ainvnm) / anorm; SUPERLU_FREE (work); return; } /* zgscon */
/* Subroutine */ int dspmv_(char *uplo, integer *n, doublereal *alpha, doublereal *ap, doublereal *x, integer *incx, doublereal *beta, doublereal *y, integer *incy, ftnlen uplo_len) { /* System generated locals */ integer i__1, i__2; /* Local variables */ integer info; doublereal temp1, temp2; integer i__, j, k; extern logical lsame_(char *, char *, ftnlen, ftnlen); integer kk, ix, iy, jx, jy, kx, ky; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); /* .. Scalar Arguments .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* DSPMV performs the matrix-vector operation */ /* y := alpha*A*x + beta*y, */ /* where alpha and beta are scalars, x and y are n element vectors and */ /* A is an n by n symmetric matrix, supplied in packed form. */ /* Parameters */ /* ========== */ /* UPLO - CHARACTER*1. */ /* On entry, UPLO specifies whether the upper or lower */ /* triangular part of the matrix A is supplied in the packed */ /* array AP as follows: */ /* UPLO = 'U' or 'u' The upper triangular part of A is */ /* supplied in AP. */ /* UPLO = 'L' or 'l' The lower triangular part of A is */ /* supplied in AP. */ /* Unchanged on exit. */ /* N - INTEGER. */ /* On entry, N specifies the order of the matrix A. */ /* N must be at least zero. */ /* Unchanged on exit. */ /* ALPHA - DOUBLE PRECISION. */ /* On entry, ALPHA specifies the scalar alpha. */ /* Unchanged on exit. */ /* AP - DOUBLE PRECISION array of DIMENSION at least */ /* ( ( n*( n + 1 ) )/2 ). */ /* Before entry with UPLO = 'U' or 'u', the array AP must */ /* contain the upper triangular part of the symmetric matrix */ /* packed sequentially, column by column, so that AP( 1 ) */ /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 ) */ /* and a( 2, 2 ) respectively, and so on. */ /* Before entry with UPLO = 'L' or 'l', the array AP must */ /* contain the lower triangular part of the symmetric matrix */ /* packed sequentially, column by column, so that AP( 1 ) */ /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 ) */ /* and a( 3, 1 ) respectively, and so on. */ /* Unchanged on exit. */ /* X - DOUBLE PRECISION array of dimension at least */ /* ( 1 + ( n - 1 )*abs( INCX ) ). */ /* Before entry, the incremented array X must contain the n */ /* element vector x. */ /* Unchanged on exit. */ /* INCX - INTEGER. */ /* On entry, INCX specifies the increment for the elements of */ /* X. INCX must not be zero. */ /* Unchanged on exit. */ /* BETA - DOUBLE PRECISION. */ /* On entry, BETA specifies the scalar beta. When BETA is */ /* supplied as zero then Y need not be set on input. */ /* Unchanged on exit. */ /* Y - DOUBLE PRECISION array of dimension at least */ /* ( 1 + ( n - 1 )*abs( INCY ) ). */ /* Before entry, the incremented array Y must contain the n */ /* element vector y. On exit, Y is overwritten by the updated */ /* vector y. */ /* INCY - INTEGER. */ /* On entry, INCY specifies the increment for the elements of */ /* Y. INCY must not be zero. */ /* Unchanged on exit. */ /* Level 2 Blas routine. */ /* -- Written on 22-October-1986. */ /* Jack Dongarra, Argonne National Lab. */ /* Jeremy Du Croz, Nag Central Office. */ /* Sven Hammarling, Nag Central Office. */ /* Richard Hanson, Sandia National Labs. */ /* .. Parameters .. */ /* .. Local Scalars .. */ /* .. External Functions .. */ /* .. External Subroutines .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input parameters. */ /* Parameter adjustments */ --y; --x; --ap; /* Function Body */ info = 0; if (! lsame_(uplo, "U", (ftnlen)1, (ftnlen)1) && ! lsame_(uplo, "L", ( ftnlen)1, (ftnlen)1)) { info = 1; } else if (*n < 0) { info = 2; } else if (*incx == 0) { info = 6; } else if (*incy == 0) { info = 9; } if (info != 0) { xerbla_("DSPMV ", &info, (ftnlen)6); return 0; } /* Quick return if possible. */ if (*n == 0 || *alpha == 0. && *beta == 1.) { return 0; } /* Set up the start points in X and Y. */ if (*incx > 0) { kx = 1; } else { kx = 1 - (*n - 1) * *incx; } if (*incy > 0) { ky = 1; } else { ky = 1 - (*n - 1) * *incy; } /* Start the operations. In this version the elements of the array AP */ /* are accessed sequentially with one pass through AP. */ /* First form y := beta*y. */ if (*beta != 1.) { if (*incy == 1) { if (*beta == 0.) { i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { y[i__] = 0.; /* L10: */ } } else { i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { y[i__] = *beta * y[i__]; /* L20: */ } } } else { iy = ky; if (*beta == 0.) { i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { y[iy] = 0.; iy += *incy; /* L30: */ } } else { i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { y[iy] = *beta * y[iy]; iy += *incy; /* L40: */ } } } } if (*alpha == 0.) { return 0; } kk = 1; if (lsame_(uplo, "U", (ftnlen)1, (ftnlen)1)) { /* Form y when AP contains the upper triangle. */ if (*incx == 1 && *incy == 1) { i__1 = *n; for (j = 1; j <= i__1; ++j) { temp1 = *alpha * x[j]; temp2 = 0.; k = kk; i__2 = j - 1; for (i__ = 1; i__ <= i__2; ++i__) { y[i__] += temp1 * ap[k]; temp2 += ap[k] * x[i__]; ++k; /* L50: */ } y[j] = y[j] + temp1 * ap[kk + j - 1] + *alpha * temp2; kk += j; /* L60: */ } } else { jx = kx; jy = ky; i__1 = *n; for (j = 1; j <= i__1; ++j) { temp1 = *alpha * x[jx]; temp2 = 0.; ix = kx; iy = ky; i__2 = kk + j - 2; for (k = kk; k <= i__2; ++k) { y[iy] += temp1 * ap[k]; temp2 += ap[k] * x[ix]; ix += *incx; iy += *incy; /* L70: */ } y[jy] = y[jy] + temp1 * ap[kk + j - 1] + *alpha * temp2; jx += *incx; jy += *incy; kk += j; /* L80: */ } } } else { /* Form y when AP contains the lower triangle. */ if (*incx == 1 && *incy == 1) { i__1 = *n; for (j = 1; j <= i__1; ++j) { temp1 = *alpha * x[j]; temp2 = 0.; y[j] += temp1 * ap[kk]; k = kk + 1; i__2 = *n; for (i__ = j + 1; i__ <= i__2; ++i__) { y[i__] += temp1 * ap[k]; temp2 += ap[k] * x[i__]; ++k; /* L90: */ } y[j] += *alpha * temp2; kk += *n - j + 1; /* L100: */ } } else { jx = kx; jy = ky; i__1 = *n; for (j = 1; j <= i__1; ++j) { temp1 = *alpha * x[jx]; temp2 = 0.; y[jy] += temp1 * ap[kk]; ix = jx; iy = jy; i__2 = kk + *n - j; for (k = kk + 1; k <= i__2; ++k) { ix += *incx; iy += *incy; y[iy] += temp1 * ap[k]; temp2 += ap[k] * x[ix]; /* L110: */ } y[jy] += *alpha * temp2; jx += *incx; jy += *incy; kk += *n - j + 1; /* L120: */ } } } return 0; /* End of DSPMV . */ } /* dspmv_ */
/* Subroutine */ int zhbgv_(char *jobz, char *uplo, integer *n, integer *ka, integer *kb, doublecomplex *ab, integer *ldab, doublecomplex *bb, integer *ldbb, doublereal *w, doublecomplex *z__, integer *ldz, doublecomplex *work, doublereal *rwork, integer *info) { /* -- LAPACK driver routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University September 30, 1994 Purpose ======= ZHBGV computes all the eigenvalues, and optionally, the eigenvectors of a complex generalized Hermitian-definite banded eigenproblem, of the form A*x=(lambda)*B*x. Here A and B are assumed to be Hermitian and banded, and B is also positive definite. Arguments ========= JOBZ (input) CHARACTER*1 = 'N': Compute eigenvalues only; = 'V': Compute eigenvalues and eigenvectors. UPLO (input) CHARACTER*1 = 'U': Upper triangles of A and B are stored; = 'L': Lower triangles of A and B are stored. N (input) INTEGER The order of the matrices A and B. N >= 0. KA (input) INTEGER The number of superdiagonals of the matrix A if UPLO = 'U', or the number of subdiagonals if UPLO = 'L'. KA >= 0. KB (input) INTEGER The number of superdiagonals of the matrix B if UPLO = 'U', or the number of subdiagonals if UPLO = 'L'. KB >= 0. AB (input/output) COMPLEX*16 array, dimension (LDAB, N) On entry, the upper or lower triangle of the Hermitian band matrix A, stored in the first ka+1 rows of the array. The j-th column of A is stored in the j-th column of the array AB as follows: if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for max(1,j-ka)<=i<=j; if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+ka). On exit, the contents of AB are destroyed. LDAB (input) INTEGER The leading dimension of the array AB. LDAB >= KA+1. BB (input/output) COMPLEX*16 array, dimension (LDBB, N) On entry, the upper or lower triangle of the Hermitian band matrix B, stored in the first kb+1 rows of the array. The j-th column of B is stored in the j-th column of the array BB as follows: if UPLO = 'U', BB(kb+1+i-j,j) = B(i,j) for max(1,j-kb)<=i<=j; if UPLO = 'L', BB(1+i-j,j) = B(i,j) for j<=i<=min(n,j+kb). On exit, the factor S from the split Cholesky factorization B = S**H*S, as returned by ZPBSTF. LDBB (input) INTEGER The leading dimension of the array BB. LDBB >= KB+1. W (output) DOUBLE PRECISION array, dimension (N) If INFO = 0, the eigenvalues in ascending order. Z (output) COMPLEX*16 array, dimension (LDZ, N) If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of eigenvectors, with the i-th column of Z holding the eigenvector associated with W(i). The eigenvectors are normalized so that Z**H*B*Z = I. If JOBZ = 'N', then Z is not referenced. LDZ (input) INTEGER The leading dimension of the array Z. LDZ >= 1, and if JOBZ = 'V', LDZ >= N. WORK (workspace) COMPLEX*16 array, dimension (N) RWORK (workspace) DOUBLE PRECISION array, dimension (3*N) INFO (output) INTEGER = 0: successful exit < 0: if INFO = -i, the i-th argument had an illegal value > 0: if INFO = i, and i is: <= N: the algorithm failed to converge: i off-diagonal elements of an intermediate tridiagonal form did not converge to zero; > N: if INFO = N + i, for 1 <= i <= N, then ZPBSTF returned INFO = i: B is not positive definite. The factorization of B could not be completed and no eigenvalues or eigenvectors were computed. ===================================================================== Test the input parameters. Parameter adjustments */ /* System generated locals */ integer ab_dim1, ab_offset, bb_dim1, bb_offset, z_dim1, z_offset, i__1; /* Local variables */ static integer inde; static char vect[1]; extern logical lsame_(char *, char *); static integer iinfo; static logical upper, wantz; extern /* Subroutine */ int xerbla_(char *, integer *), dsterf_( integer *, doublereal *, doublereal *, integer *), zhbtrd_(char *, char *, integer *, integer *, doublecomplex *, integer *, doublereal *, doublereal *, doublecomplex *, integer *, doublecomplex *, integer *); static integer indwrk; extern /* Subroutine */ int zhbgst_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublereal *, integer *), zpbstf_(char *, integer *, integer *, doublecomplex *, integer *, integer *), zsteqr_(char *, integer *, doublereal *, doublereal *, doublecomplex *, integer *, doublereal *, integer *); ab_dim1 = *ldab; ab_offset = 1 + ab_dim1 * 1; ab -= ab_offset; bb_dim1 = *ldbb; bb_offset = 1 + bb_dim1 * 1; bb -= bb_offset; --w; z_dim1 = *ldz; z_offset = 1 + z_dim1 * 1; z__ -= z_offset; --work; --rwork; /* Function Body */ wantz = lsame_(jobz, "V"); upper = lsame_(uplo, "U"); *info = 0; if (! (wantz || lsame_(jobz, "N"))) { *info = -1; } else if (! (upper || lsame_(uplo, "L"))) { *info = -2; } else if (*n < 0) { *info = -3; } else if (*ka < 0) { *info = -4; } else if (*kb < 0 || *kb > *ka) { *info = -5; } else if (*ldab < *ka + 1) { *info = -7; } else if (*ldbb < *kb + 1) { *info = -9; } else if (*ldz < 1 || wantz && *ldz < *n) { *info = -12; } if (*info != 0) { i__1 = -(*info); xerbla_("ZHBGV ", &i__1); return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } /* Form a split Cholesky factorization of B. */ zpbstf_(uplo, n, kb, &bb[bb_offset], ldbb, info); if (*info != 0) { *info = *n + *info; return 0; } /* Transform problem to standard eigenvalue problem. */ inde = 1; indwrk = inde + *n; zhbgst_(jobz, uplo, n, ka, kb, &ab[ab_offset], ldab, &bb[bb_offset], ldbb, &z__[z_offset], ldz, &work[1], &rwork[indwrk], &iinfo); /* Reduce to tridiagonal form. */ if (wantz) { *(unsigned char *)vect = 'U'; } else { *(unsigned char *)vect = 'N'; } zhbtrd_(vect, uplo, n, ka, &ab[ab_offset], ldab, &w[1], &rwork[inde], & z__[z_offset], ldz, &work[1], &iinfo); /* For eigenvalues only, call DSTERF. For eigenvectors, call ZSTEQR. */ if (! wantz) { dsterf_(n, &w[1], &rwork[inde], info); } else { zsteqr_(jobz, n, &w[1], &rwork[inde], &z__[z_offset], ldz, &rwork[ indwrk], info); } return 0; /* End of ZHBGV */ } /* zhbgv_ */
main(int argc, char *argv[]) { /* * Purpose * ======= * * ZDRIVE is the main test program for the DOUBLE COMPLEX linear * equation driver routines ZGSSV and ZGSSVX. * * The program is invoked by a shell script file -- ztest.csh. * The output from the tests are written into a file -- ztest.out. * * ===================================================================== */ doublecomplex *a, *a_save; int *asub, *asub_save; int *xa, *xa_save; SuperMatrix A, B, X, L, U; SuperMatrix ASAV, AC; mem_usage_t mem_usage; int *perm_r; /* row permutation from partial pivoting */ int *perm_c, *pc_save; /* column permutation */ int *etree; doublecomplex zero = {0.0, 0.0}; double *R, *C; double *ferr, *berr; double *rwork; doublecomplex *wwork; void *work; int info, lwork, nrhs, panel_size, relax; int m, n, nnz; doublecomplex *xact; doublecomplex *rhsb, *solx, *bsav; int ldb, ldx; double rpg, rcond; int i, j, k1; double rowcnd, colcnd, amax; int maxsuper, rowblk, colblk; int prefact, nofact, equil, iequed; int nt, nrun, nfail, nerrs, imat, fimat, nimat; int nfact, ifact, itran; int kl, ku, mode, lda; int zerot, izero, ioff; double u; double anorm, cndnum; doublecomplex *Afull; double result[NTESTS]; superlu_options_t options; fact_t fact; trans_t trans; SuperLUStat_t stat; static char matrix_type[8]; static char equed[1], path[3], sym[1], dist[1]; /* Fixed set of parameters */ int iseed[] = {1988, 1989, 1990, 1991}; static char equeds[] = {'N', 'R', 'C', 'B'}; static fact_t facts[] = {FACTORED, DOFACT, SamePattern, SamePattern_SameRowPerm}; static trans_t transs[] = {NOTRANS, TRANS, CONJ}; /* Some function prototypes */ extern int zgst01(int, int, SuperMatrix *, SuperMatrix *, SuperMatrix *, int *, int *, double *); extern int zgst02(trans_t, int, int, int, SuperMatrix *, doublecomplex *, int, doublecomplex *, int, double *resid); extern int zgst04(int, int, doublecomplex *, int, doublecomplex *, int, double rcond, double *resid); extern int zgst07(trans_t, int, int, SuperMatrix *, doublecomplex *, int, doublecomplex *, int, doublecomplex *, int, double *, double *, double *); extern int zlatb4_(char *, int *, int *, int *, char *, int *, int *, double *, int *, double *, char *); extern int zlatms_(int *, int *, char *, int *, char *, double *d, int *, double *, double *, int *, int *, char *, doublecomplex *, int *, doublecomplex *, int *); extern int sp_zconvert(int, int, doublecomplex *, int, int, int, doublecomplex *a, int *, int *, int *); /* Executable statements */ strcpy(path, "ZGE"); nrun = 0; nfail = 0; nerrs = 0; /* Defaults */ lwork = 0; n = 1; nrhs = 1; panel_size = sp_ienv(1); relax = sp_ienv(2); u = 1.0; strcpy(matrix_type, "LA"); parse_command_line(argc, argv, matrix_type, &n, &panel_size, &relax, &nrhs, &maxsuper, &rowblk, &colblk, &lwork, &u); if ( lwork > 0 ) { work = SUPERLU_MALLOC(lwork); if ( !work ) { fprintf(stderr, "expert: cannot allocate %d bytes\n", lwork); exit (-1); } } /* Set the default input options. */ set_default_options(&options); options.DiagPivotThresh = u; options.PrintStat = NO; options.PivotGrowth = YES; options.ConditionNumber = YES; options.IterRefine = DOUBLE; if ( strcmp(matrix_type, "LA") == 0 ) { /* Test LAPACK matrix suite. */ m = n; lda = SUPERLU_MAX(n, 1); nnz = n * n; /* upper bound */ fimat = 1; nimat = NTYPES; Afull = doublecomplexCalloc(lda * n); zallocateA(n, nnz, &a, &asub, &xa); } else { /* Read a sparse matrix */ fimat = nimat = 0; zreadhb(&m, &n, &nnz, &a, &asub, &xa); } zallocateA(n, nnz, &a_save, &asub_save, &xa_save); rhsb = doublecomplexMalloc(m * nrhs); bsav = doublecomplexMalloc(m * nrhs); solx = doublecomplexMalloc(n * nrhs); ldb = m; ldx = n; zCreate_Dense_Matrix(&B, m, nrhs, rhsb, ldb, SLU_DN, SLU_Z, SLU_GE); zCreate_Dense_Matrix(&X, n, nrhs, solx, ldx, SLU_DN, SLU_Z, SLU_GE); xact = doublecomplexMalloc(n * nrhs); etree = intMalloc(n); perm_r = intMalloc(n); perm_c = intMalloc(n); pc_save = intMalloc(n); R = (double *) SUPERLU_MALLOC(m*sizeof(double)); C = (double *) SUPERLU_MALLOC(n*sizeof(double)); ferr = (double *) SUPERLU_MALLOC(nrhs*sizeof(double)); berr = (double *) SUPERLU_MALLOC(nrhs*sizeof(double)); j = SUPERLU_MAX(m,n) * SUPERLU_MAX(4,nrhs); rwork = (double *) SUPERLU_MALLOC(j*sizeof(double)); for (i = 0; i < j; ++i) rwork[i] = 0.; if ( !R ) ABORT("SUPERLU_MALLOC fails for R"); if ( !C ) ABORT("SUPERLU_MALLOC fails for C"); if ( !ferr ) ABORT("SUPERLU_MALLOC fails for ferr"); if ( !berr ) ABORT("SUPERLU_MALLOC fails for berr"); if ( !rwork ) ABORT("SUPERLU_MALLOC fails for rwork"); wwork = doublecomplexCalloc( SUPERLU_MAX(m,n) * SUPERLU_MAX(4,nrhs) ); for (i = 0; i < n; ++i) perm_c[i] = pc_save[i] = i; options.ColPerm = MY_PERMC; for (imat = fimat; imat <= nimat; ++imat) { /* All matrix types */ if ( imat ) { /* Skip types 5, 6, or 7 if the matrix size is too small. */ zerot = (imat >= 5 && imat <= 7); if ( zerot && n < imat-4 ) continue; /* Set up parameters with ZLATB4 and generate a test matrix with ZLATMS. */ zlatb4_(path, &imat, &n, &n, sym, &kl, &ku, &anorm, &mode, &cndnum, dist); zlatms_(&n, &n, dist, iseed, sym, &rwork[0], &mode, &cndnum, &anorm, &kl, &ku, "No packing", Afull, &lda, &wwork[0], &info); if ( info ) { printf(FMT3, "ZLATMS", info, izero, n, nrhs, imat, nfail); continue; } /* For types 5-7, zero one or more columns of the matrix to test that INFO is returned correctly. */ if ( zerot ) { if ( imat == 5 ) izero = 1; else if ( imat == 6 ) izero = n; else izero = n / 2 + 1; ioff = (izero - 1) * lda; if ( imat < 7 ) { for (i = 0; i < n; ++i) Afull[ioff + i] = zero; } else { for (j = 0; j < n - izero + 1; ++j) for (i = 0; i < n; ++i) Afull[ioff + i + j*lda] = zero; } } else { izero = 0; } /* Convert to sparse representation. */ sp_zconvert(n, n, Afull, lda, kl, ku, a, asub, xa, &nnz); } else { izero = 0; zerot = 0; } zCreate_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, SLU_Z, SLU_GE); /* Save a copy of matrix A in ASAV */ zCreate_CompCol_Matrix(&ASAV, m, n, nnz, a_save, asub_save, xa_save, SLU_NC, SLU_Z, SLU_GE); zCopy_CompCol_Matrix(&A, &ASAV); /* Form exact solution. */ zGenXtrue(n, nrhs, xact, ldx); StatInit(&stat); for (iequed = 0; iequed < 4; ++iequed) { *equed = equeds[iequed]; if (iequed == 0) nfact = 4; else nfact = 1; /* Only test factored, pre-equilibrated matrix */ for (ifact = 0; ifact < nfact; ++ifact) { fact = facts[ifact]; options.Fact = fact; for (equil = 0; equil < 2; ++equil) { options.Equil = equil; prefact = ( options.Fact == FACTORED || options.Fact == SamePattern_SameRowPerm ); /* Need a first factor */ nofact = (options.Fact != FACTORED); /* Not factored */ /* Restore the matrix A. */ zCopy_CompCol_Matrix(&ASAV, &A); if ( zerot ) { if ( prefact ) continue; } else if ( options.Fact == FACTORED ) { if ( equil || iequed ) { /* Compute row and column scale factors to equilibrate matrix A. */ zgsequ(&A, R, C, &rowcnd, &colcnd, &amax, &info); /* Force equilibration. */ if ( !info && n > 0 ) { if ( lsame_(equed, "R") ) { rowcnd = 0.; colcnd = 1.; } else if ( lsame_(equed, "C") ) { rowcnd = 1.; colcnd = 0.; } else if ( lsame_(equed, "B") ) { rowcnd = 0.; colcnd = 0.; } } /* Equilibrate the matrix. */ zlaqgs(&A, R, C, rowcnd, colcnd, amax, equed); } } if ( prefact ) { /* Need a factor for the first time */ /* Save Fact option. */ fact = options.Fact; options.Fact = DOFACT; /* Preorder the matrix, obtain the column etree. */ sp_preorder(&options, &A, perm_c, etree, &AC); /* Factor the matrix AC. */ zgstrf(&options, &AC, relax, panel_size, etree, work, lwork, perm_c, perm_r, &L, &U, &stat, &info); if ( info ) { printf("** First factor: info %d, equed %c\n", info, *equed); if ( lwork == -1 ) { printf("** Estimated memory: %d bytes\n", info - n); exit(0); } } Destroy_CompCol_Permuted(&AC); /* Restore Fact option. */ options.Fact = fact; } /* if .. first time factor */ for (itran = 0; itran < NTRAN; ++itran) { trans = transs[itran]; options.Trans = trans; /* Restore the matrix A. */ zCopy_CompCol_Matrix(&ASAV, &A); /* Set the right hand side. */ zFillRHS(trans, nrhs, xact, ldx, &A, &B); zCopy_Dense_Matrix(m, nrhs, rhsb, ldb, bsav, ldb); /*---------------- * Test zgssv *----------------*/ if ( options.Fact == DOFACT && itran == 0) { /* Not yet factored, and untransposed */ zCopy_Dense_Matrix(m, nrhs, rhsb, ldb, solx, ldx); zgssv(&options, &A, perm_c, perm_r, &L, &U, &X, &stat, &info); if ( info && info != izero ) { printf(FMT3, "zgssv", info, izero, n, nrhs, imat, nfail); } else { /* Reconstruct matrix from factors and compute residual. */ zgst01(m, n, &A, &L, &U, perm_c, perm_r, &result[0]); nt = 1; if ( izero == 0 ) { /* Compute residual of the computed solution. */ zCopy_Dense_Matrix(m, nrhs, rhsb, ldb, wwork, ldb); zgst02(trans, m, n, nrhs, &A, solx, ldx, wwork,ldb, &result[1]); nt = 2; } /* Print information about the tests that did not pass the threshold. */ for (i = 0; i < nt; ++i) { if ( result[i] >= THRESH ) { printf(FMT1, "zgssv", n, i, result[i]); ++nfail; } } nrun += nt; } /* else .. info == 0 */ /* Restore perm_c. */ for (i = 0; i < n; ++i) perm_c[i] = pc_save[i]; if (lwork == 0) { Destroy_SuperNode_Matrix(&L); Destroy_CompCol_Matrix(&U); } } /* if .. end of testing zgssv */ /*---------------- * Test zgssvx *----------------*/ /* Equilibrate the matrix if fact = FACTORED and equed = 'R', 'C', or 'B'. */ if ( options.Fact == FACTORED && (equil || iequed) && n > 0 ) { zlaqgs(&A, R, C, rowcnd, colcnd, amax, equed); } /* Solve the system and compute the condition number and error bounds using zgssvx. */ zgssvx(&options, &A, perm_c, perm_r, etree, equed, R, C, &L, &U, work, lwork, &B, &X, &rpg, &rcond, ferr, berr, &mem_usage, &stat, &info); if ( info && info != izero ) { printf(FMT3, "zgssvx", info, izero, n, nrhs, imat, nfail); if ( lwork == -1 ) { printf("** Estimated memory: %.0f bytes\n", mem_usage.total_needed); exit(0); } } else { if ( !prefact ) { /* Reconstruct matrix from factors and compute residual. */ zgst01(m, n, &A, &L, &U, perm_c, perm_r, &result[0]); k1 = 0; } else { k1 = 1; } if ( !info ) { /* Compute residual of the computed solution.*/ zCopy_Dense_Matrix(m, nrhs, bsav, ldb, wwork, ldb); zgst02(trans, m, n, nrhs, &ASAV, solx, ldx, wwork, ldb, &result[1]); /* Check solution from generated exact solution. */ zgst04(n, nrhs, solx, ldx, xact, ldx, rcond, &result[2]); /* Check the error bounds from iterative refinement. */ zgst07(trans, n, nrhs, &ASAV, bsav, ldb, solx, ldx, xact, ldx, ferr, berr, &result[3]); /* Print information about the tests that did not pass the threshold. */ for (i = k1; i < NTESTS; ++i) { if ( result[i] >= THRESH ) { printf(FMT2, "zgssvx", options.Fact, trans, *equed, n, imat, i, result[i]); ++nfail; } } nrun += NTESTS; } /* if .. info == 0 */ } /* else .. end of testing zgssvx */ } /* for itran ... */ if ( lwork == 0 ) { Destroy_SuperNode_Matrix(&L); Destroy_CompCol_Matrix(&U); } } /* for equil ... */ } /* for ifact ... */ } /* for iequed ... */ #if 0 if ( !info ) { PrintPerf(&L, &U, &mem_usage, rpg, rcond, ferr, berr, equed); } #endif } /* for imat ... */ /* Print a summary of the results. */ PrintSumm("ZGE", nfail, nrun, nerrs); SUPERLU_FREE (rhsb); SUPERLU_FREE (bsav); SUPERLU_FREE (solx); SUPERLU_FREE (xact); SUPERLU_FREE (etree); SUPERLU_FREE (perm_r); SUPERLU_FREE (perm_c); SUPERLU_FREE (pc_save); SUPERLU_FREE (R); SUPERLU_FREE (C); SUPERLU_FREE (ferr); SUPERLU_FREE (berr); SUPERLU_FREE (rwork); SUPERLU_FREE (wwork); Destroy_SuperMatrix_Store(&B); Destroy_SuperMatrix_Store(&X); Destroy_CompCol_Matrix(&A); Destroy_CompCol_Matrix(&ASAV); if ( lwork > 0 ) { SUPERLU_FREE (work); Destroy_SuperMatrix_Store(&L); Destroy_SuperMatrix_Store(&U); } StatFree(&stat); return 0; }
/* Subroutine */ int cpptrf_(char *uplo, integer *n, complex *ap, integer * info) { /* -- LAPACK routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University September 30, 1994 Purpose ======= CPPTRF computes the Cholesky factorization of a complex Hermitian positive definite matrix A stored in packed format. The factorization has the form A = U**H * U, if UPLO = 'U', or A = L * L**H, if UPLO = 'L', where U is an upper triangular matrix and L is lower triangular. Arguments ========= UPLO (input) CHARACTER*1 = 'U': Upper triangle of A is stored; = 'L': Lower triangle of A is stored. N (input) INTEGER The order of the matrix A. N >= 0. AP (input/output) COMPLEX array, dimension (N*(N+1)/2) On entry, the upper or lower triangle of the Hermitian matrix A, packed columnwise in a linear array. The j-th column of A is stored in the array AP as follows: if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. See below for further details. On exit, if INFO = 0, the triangular factor U or L from the Cholesky factorization A = U**H*U or A = L*L**H, in the same storage format as A. INFO (output) INTEGER = 0: successful exit < 0: if INFO = -i, the i-th argument had an illegal value > 0: if INFO = i, the leading minor of order i is not positive definite, and the factorization could not be completed. Further Details =============== The packed storage scheme is illustrated by the following example when N = 4, UPLO = 'U': Two-dimensional storage of the Hermitian matrix A: a11 a12 a13 a14 a22 a23 a24 a33 a34 (aij = conjg(aji)) a44 Packed storage of the upper triangle of A: AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ] ===================================================================== Test the input parameters. Parameter adjustments */ /* Table of constant values */ static integer c__1 = 1; static real c_b16 = -1.f; /* System generated locals */ integer i__1, i__2, i__3; real r__1; complex q__1, q__2; /* Builtin functions */ double sqrt(doublereal); /* Local variables */ extern /* Subroutine */ int chpr_(char *, integer *, real *, complex *, integer *, complex *); static integer j; extern /* Complex */ VOID cdotc_(complex *, integer *, complex *, integer *, complex *, integer *); extern logical lsame_(char *, char *); static logical upper; extern /* Subroutine */ int ctpsv_(char *, char *, char *, integer *, complex *, complex *, integer *); static integer jc, jj; extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer *), xerbla_(char *, integer *); static real ajj; --ap; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } if (*info != 0) { i__1 = -(*info); xerbla_("CPPTRF", &i__1); return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } if (upper) { /* Compute the Cholesky factorization A = U'*U. */ jj = 0; i__1 = *n; for (j = 1; j <= i__1; ++j) { jc = jj + 1; jj += j; /* Compute elements 1:J-1 of column J. */ if (j > 1) { i__2 = j - 1; ctpsv_("Upper", "Conjugate transpose", "Non-unit", &i__2, &ap[ 1], &ap[jc], &c__1); } /* Compute U(J,J) and test for non-positive-definiteness. */ i__2 = jj; r__1 = ap[i__2].r; i__3 = j - 1; cdotc_(&q__2, &i__3, &ap[jc], &c__1, &ap[jc], &c__1); q__1.r = r__1 - q__2.r, q__1.i = -q__2.i; ajj = q__1.r; if (ajj <= 0.f) { i__2 = jj; ap[i__2].r = ajj, ap[i__2].i = 0.f; goto L30; } i__2 = jj; r__1 = sqrt(ajj); ap[i__2].r = r__1, ap[i__2].i = 0.f; /* L10: */ } } else { /* Compute the Cholesky factorization A = L*L'. */ jj = 1; i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Compute L(J,J) and test for non-positive-definiteness. */ i__2 = jj; ajj = ap[i__2].r; if (ajj <= 0.f) { i__2 = jj; ap[i__2].r = ajj, ap[i__2].i = 0.f; goto L30; } ajj = sqrt(ajj); i__2 = jj; ap[i__2].r = ajj, ap[i__2].i = 0.f; /* Compute elements J+1:N of column J and update the trailing submatrix. */ if (j < *n) { i__2 = *n - j; r__1 = 1.f / ajj; csscal_(&i__2, &r__1, &ap[jj + 1], &c__1); i__2 = *n - j; chpr_("Lower", &i__2, &c_b16, &ap[jj + 1], &c__1, &ap[jj + *n - j + 1]); jj = jj + *n - j + 1; } /* L20: */ } } goto L40; L30: *info = j; L40: return 0; /* End of CPPTRF */ } /* cpptrf_ */
/* Subroutine */ int claqhb_(char *uplo, integer *n, integer *kd, complex *ab, integer *ldab, real *s, real *scond, real *amax, char *equed) { /* System generated locals */ integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4; real r__1; complex q__1; /* Local variables */ integer i__, j; real cj, large; extern logical lsame_(char *, char *); real small; extern doublereal slamch_(char *); /* -- LAPACK auxiliary routine (version 3.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* CLAQHB equilibrates an Hermitian band matrix A using the scaling */ /* factors in the vector S. */ /* Arguments */ /* ========= */ /* UPLO (input) CHARACTER*1 */ /* Specifies whether the upper or lower triangular part of the */ /* symmetric matrix A is stored. */ /* = 'U': Upper triangular */ /* = 'L': Lower triangular */ /* N (input) INTEGER */ /* The order of the matrix A. N >= 0. */ /* KD (input) INTEGER */ /* The number of super-diagonals of the matrix A if UPLO = 'U', */ /* or the number of sub-diagonals if UPLO = 'L'. KD >= 0. */ /* AB (input/output) COMPLEX array, dimension (LDAB,N) */ /* On entry, the upper or lower triangle of the symmetric band */ /* matrix A, stored in the first KD+1 rows of the array. The */ /* j-th column of A is stored in the j-th column of the array AB */ /* as follows: */ /* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */ /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */ /* On exit, if INFO = 0, the triangular factor U or L from the */ /* Cholesky factorization A = U'*U or A = L*L' of the band */ /* matrix A, in the same storage format as A. */ /* LDAB (input) INTEGER */ /* The leading dimension of the array AB. LDAB >= KD+1. */ /* S (output) REAL array, dimension (N) */ /* The scale factors for A. */ /* SCOND (input) REAL */ /* Ratio of the smallest S(i) to the largest S(i). */ /* AMAX (input) REAL */ /* Absolute value of largest matrix entry. */ /* EQUED (output) CHARACTER*1 */ /* Specifies whether or not equilibration was done. */ /* = 'N': No equilibration. */ /* = 'Y': Equilibration was done, i.e., A has been replaced by */ /* diag(S) * A * diag(S). */ /* Internal Parameters */ /* =================== */ /* THRESH is a threshold value used to decide if scaling should be done */ /* based on the ratio of the scaling factors. If SCOND < THRESH, */ /* scaling is done. */ /* LARGE and SMALL are threshold values used to decide if scaling should */ /* be done based on the absolute size of the largest matrix element. */ /* If AMAX > LARGE or AMAX < SMALL, scaling is done. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Quick return if possible */ /* Parameter adjustments */ ab_dim1 = *ldab; ab_offset = 1 + ab_dim1; ab -= ab_offset; --s; /* Function Body */ if (*n <= 0) { *(unsigned char *)equed = 'N'; return 0; } /* Initialize LARGE and SMALL. */ small = slamch_("Safe minimum") / slamch_("Precision"); large = 1.f / small; if (*scond >= .1f && *amax >= small && *amax <= large) { /* No equilibration */ *(unsigned char *)equed = 'N'; } else { /* Replace A by diag(S) * A * diag(S). */ if (lsame_(uplo, "U")) { /* Upper triangle of A is stored in band format. */ i__1 = *n; for (j = 1; j <= i__1; ++j) { cj = s[j]; /* Computing MAX */ i__2 = 1, i__3 = j - *kd; i__4 = j - 1; for (i__ = max(i__2,i__3); i__ <= i__4; ++i__) { i__2 = *kd + 1 + i__ - j + j * ab_dim1; r__1 = cj * s[i__]; i__3 = *kd + 1 + i__ - j + j * ab_dim1; q__1.r = r__1 * ab[i__3].r, q__1.i = r__1 * ab[i__3].i; ab[i__2].r = q__1.r, ab[i__2].i = q__1.i; /* L10: */ } i__4 = *kd + 1 + j * ab_dim1; i__2 = *kd + 1 + j * ab_dim1; r__1 = cj * cj * ab[i__2].r; ab[i__4].r = r__1, ab[i__4].i = 0.f; /* L20: */ } } else { /* Lower triangle of A is stored. */ i__1 = *n; for (j = 1; j <= i__1; ++j) { cj = s[j]; i__4 = j * ab_dim1 + 1; i__2 = j * ab_dim1 + 1; r__1 = cj * cj * ab[i__2].r; ab[i__4].r = r__1, ab[i__4].i = 0.f; /* Computing MIN */ i__2 = *n, i__3 = j + *kd; i__4 = min(i__2,i__3); for (i__ = j + 1; i__ <= i__4; ++i__) { i__2 = i__ + 1 - j + j * ab_dim1; r__1 = cj * s[i__]; i__3 = i__ + 1 - j + j * ab_dim1; q__1.r = r__1 * ab[i__3].r, q__1.i = r__1 * ab[i__3].i; ab[i__2].r = q__1.r, ab[i__2].i = q__1.i; /* L30: */ } /* L40: */ } } *(unsigned char *)equed = 'Y'; } return 0; /* End of CLAQHB */ } /* claqhb_ */
/* Subroutine */ int dgbsvx_(char *fact, char *trans, integer *n, integer *kl, integer *ku, integer *nrhs, doublereal *ab, integer *ldab, doublereal *afb, integer *ldafb, integer *ipiv, char *equed, doublereal *r__, doublereal *c__, doublereal *b, integer *ldb, doublereal *x, integer *ldx, doublereal *rcond, doublereal *ferr, doublereal *berr, doublereal *work, integer *iwork, integer *info) { /* System generated locals */ integer ab_dim1, ab_offset, afb_dim1, afb_offset, b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5; doublereal d__1, d__2, d__3; /* Local variables */ integer i__, j, j1, j2; doublereal amax; char norm[1]; extern logical lsame_(char *, char *); doublereal rcmin, rcmax, anorm; extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, doublereal *, integer *); logical equil; extern doublereal dlangb_(char *, integer *, integer *, integer *, doublereal *, integer *, doublereal *), dlamch_(char *); extern /* Subroutine */ int dlaqgb_(integer *, integer *, integer *, integer *, doublereal *, integer *, doublereal *, doublereal *, doublereal *, doublereal *, doublereal *, char *), dgbcon_(char *, integer *, integer *, integer *, doublereal *, integer *, integer *, doublereal *, doublereal *, doublereal *, integer *, integer *); doublereal colcnd; extern doublereal dlantb_(char *, char *, char *, integer *, integer *, doublereal *, integer *, doublereal *); extern /* Subroutine */ int dgbequ_(integer *, integer *, integer *, integer *, doublereal *, integer *, doublereal *, doublereal *, doublereal *, doublereal *, doublereal *, integer *), dgbrfs_( char *, integer *, integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *, doublereal *, integer *, integer *), dgbtrf_(integer *, integer *, integer *, integer *, doublereal *, integer *, integer *, integer *); logical nofact; extern /* Subroutine */ int dlacpy_(char *, integer *, integer *, doublereal *, integer *, doublereal *, integer *), xerbla_(char *, integer *); doublereal bignum; extern /* Subroutine */ int dgbtrs_(char *, integer *, integer *, integer *, integer *, doublereal *, integer *, integer *, doublereal *, integer *, integer *); integer infequ; logical colequ; doublereal rowcnd; logical notran; doublereal smlnum; logical rowequ; doublereal rpvgrw; /* -- LAPACK driver routine (version 3.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* DGBSVX uses the LU factorization to compute the solution to a real */ /* system of linear equations A * X = B, A**T * X = B, or A**H * X = B, */ /* where A is a band matrix of order N with KL subdiagonals and KU */ /* superdiagonals, and X and B are N-by-NRHS matrices. */ /* Error bounds on the solution and a condition estimate are also */ /* provided. */ /* Description */ /* =========== */ /* The following steps are performed by this subroutine: */ /* 1. If FACT = 'E', real scaling factors are computed to equilibrate */ /* the system: */ /* TRANS = 'N': diag(R)*A*diag(C) *inv(diag(C))*X = diag(R)*B */ /* TRANS = 'T': (diag(R)*A*diag(C))**T *inv(diag(R))*X = diag(C)*B */ /* TRANS = 'C': (diag(R)*A*diag(C))**H *inv(diag(R))*X = diag(C)*B */ /* Whether or not the system will be equilibrated depends on the */ /* scaling of the matrix A, but if equilibration is used, A is */ /* overwritten by diag(R)*A*diag(C) and B by diag(R)*B (if TRANS='N') */ /* or diag(C)*B (if TRANS = 'T' or 'C'). */ /* 2. If FACT = 'N' or 'E', the LU decomposition is used to factor the */ /* matrix A (after equilibration if FACT = 'E') as */ /* A = L * U, */ /* where L is a product of permutation and unit lower triangular */ /* matrices with KL subdiagonals, and U is upper triangular with */ /* KL+KU superdiagonals. */ /* 3. If some U(i,i)=0, so that U is exactly singular, then the routine */ /* returns with INFO = i. Otherwise, the factored form of A is used */ /* to estimate the condition number of the matrix A. If the */ /* reciprocal of the condition number is less than machine precision, */ /* INFO = N+1 is returned as a warning, but the routine still goes on */ /* to solve for X and compute error bounds as described below. */ /* 4. The system of equations is solved for X using the factored form */ /* of A. */ /* 5. Iterative refinement is applied to improve the computed solution */ /* matrix and calculate error bounds and backward error estimates */ /* for it. */ /* 6. If equilibration was used, the matrix X is premultiplied by */ /* diag(C) (if TRANS = 'N') or diag(R) (if TRANS = 'T' or 'C') so */ /* that it solves the original system before equilibration. */ /* Arguments */ /* ========= */ /* FACT (input) CHARACTER*1 */ /* Specifies whether or not the factored form of the matrix A is */ /* supplied on entry, and if not, whether the matrix A should be */ /* equilibrated before it is factored. */ /* = 'F': On entry, AFB and IPIV contain the factored form of */ /* A. If EQUED is not 'N', the matrix A has been */ /* equilibrated with scaling factors given by R and C. */ /* AB, AFB, and IPIV are not modified. */ /* = 'N': The matrix A will be copied to AFB and factored. */ /* = 'E': The matrix A will be equilibrated if necessary, then */ /* copied to AFB and factored. */ /* TRANS (input) CHARACTER*1 */ /* Specifies the form of the system of equations. */ /* = 'N': A * X = B (No transpose) */ /* = 'T': A**T * X = B (Transpose) */ /* = 'C': A**H * X = B (Transpose) */ /* N (input) INTEGER */ /* The number of linear equations, i.e., the order of the */ /* matrix A. N >= 0. */ /* KL (input) INTEGER */ /* The number of subdiagonals within the band of A. KL >= 0. */ /* KU (input) INTEGER */ /* The number of superdiagonals within the band of A. KU >= 0. */ /* NRHS (input) INTEGER */ /* The number of right hand sides, i.e., the number of columns */ /* of the matrices B and X. NRHS >= 0. */ /* AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N) */ /* On entry, the matrix A in band storage, in rows 1 to KL+KU+1. */ /* The j-th column of A is stored in the j-th column of the */ /* array AB as follows: */ /* AB(KU+1+i-j,j) = A(i,j) for max(1,j-KU)<=i<=min(N,j+kl) */ /* If FACT = 'F' and EQUED is not 'N', then A must have been */ /* equilibrated by the scaling factors in R and/or C. AB is not */ /* modified if FACT = 'F' or 'N', or if FACT = 'E' and */ /* EQUED = 'N' on exit. */ /* On exit, if EQUED .ne. 'N', A is scaled as follows: */ /* EQUED = 'R': A := diag(R) * A */ /* EQUED = 'C': A := A * diag(C) */ /* EQUED = 'B': A := diag(R) * A * diag(C). */ /* LDAB (input) INTEGER */ /* The leading dimension of the array AB. LDAB >= KL+KU+1. */ /* AFB (input or output) DOUBLE PRECISION array, dimension (LDAFB,N) */ /* If FACT = 'F', then AFB is an input argument and on entry */ /* contains details of the LU factorization of the band matrix */ /* A, as computed by DGBTRF. U is stored as an upper triangular */ /* band matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, */ /* and the multipliers used during the factorization are stored */ /* in rows KL+KU+2 to 2*KL+KU+1. If EQUED .ne. 'N', then AFB is */ /* the factored form of the equilibrated matrix A. */ /* If FACT = 'N', then AFB is an output argument and on exit */ /* returns details of the LU factorization of A. */ /* If FACT = 'E', then AFB is an output argument and on exit */ /* returns details of the LU factorization of the equilibrated */ /* matrix A (see the description of AB for the form of the */ /* equilibrated matrix). */ /* LDAFB (input) INTEGER */ /* The leading dimension of the array AFB. LDAFB >= 2*KL+KU+1. */ /* IPIV (input or output) INTEGER array, dimension (N) */ /* If FACT = 'F', then IPIV is an input argument and on entry */ /* contains the pivot indices from the factorization A = L*U */ /* as computed by DGBTRF; row i of the matrix was interchanged */ /* with row IPIV(i). */ /* If FACT = 'N', then IPIV is an output argument and on exit */ /* contains the pivot indices from the factorization A = L*U */ /* of the original matrix A. */ /* If FACT = 'E', then IPIV is an output argument and on exit */ /* contains the pivot indices from the factorization A = L*U */ /* of the equilibrated matrix A. */ /* EQUED (input or output) CHARACTER*1 */ /* Specifies the form of equilibration that was done. */ /* = 'N': No equilibration (always true if FACT = 'N'). */ /* = 'R': Row equilibration, i.e., A has been premultiplied by */ /* diag(R). */ /* = 'C': Column equilibration, i.e., A has been postmultiplied */ /* by diag(C). */ /* = 'B': Both row and column equilibration, i.e., A has been */ /* replaced by diag(R) * A * diag(C). */ /* EQUED is an input argument if FACT = 'F'; otherwise, it is an */ /* output argument. */ /* R (input or output) DOUBLE PRECISION array, dimension (N) */ /* The row scale factors for A. If EQUED = 'R' or 'B', A is */ /* multiplied on the left by diag(R); if EQUED = 'N' or 'C', R */ /* is not accessed. R is an input argument if FACT = 'F'; */ /* otherwise, R is an output argument. If FACT = 'F' and */ /* EQUED = 'R' or 'B', each element of R must be positive. */ /* C (input or output) DOUBLE PRECISION array, dimension (N) */ /* The column scale factors for A. If EQUED = 'C' or 'B', A is */ /* multiplied on the right by diag(C); if EQUED = 'N' or 'R', C */ /* is not accessed. C is an input argument if FACT = 'F'; */ /* otherwise, C is an output argument. If FACT = 'F' and */ /* EQUED = 'C' or 'B', each element of C must be positive. */ /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */ /* On entry, the right hand side matrix B. */ /* On exit, */ /* if EQUED = 'N', B is not modified; */ /* if TRANS = 'N' and EQUED = 'R' or 'B', B is overwritten by */ /* diag(R)*B; */ /* if TRANS = 'T' or 'C' and EQUED = 'C' or 'B', B is */ /* overwritten by diag(C)*B. */ /* LDB (input) INTEGER */ /* The leading dimension of the array B. LDB >= max(1,N). */ /* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */ /* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X */ /* to the original system of equations. Note that A and B are */ /* modified on exit if EQUED .ne. 'N', and the solution to the */ /* equilibrated system is inv(diag(C))*X if TRANS = 'N' and */ /* EQUED = 'C' or 'B', or inv(diag(R))*X if TRANS = 'T' or 'C' */ /* and EQUED = 'R' or 'B'. */ /* LDX (input) INTEGER */ /* The leading dimension of the array X. LDX >= max(1,N). */ /* RCOND (output) DOUBLE PRECISION */ /* The estimate of the reciprocal condition number of the matrix */ /* A after equilibration (if done). If RCOND is less than the */ /* machine precision (in particular, if RCOND = 0), the matrix */ /* is singular to working precision. This condition is */ /* indicated by a return code of INFO > 0. */ /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */ /* The estimated forward error bound for each solution vector */ /* X(j) (the j-th column of the solution matrix X). */ /* If XTRUE is the true solution corresponding to X(j), FERR(j) */ /* is an estimated upper bound for the magnitude of the largest */ /* element in (X(j) - XTRUE) divided by the magnitude of the */ /* largest element in X(j). The estimate is as reliable as */ /* the estimate for RCOND, and is almost always a slight */ /* overestimate of the true error. */ /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */ /* The componentwise relative backward error of each solution */ /* vector X(j) (i.e., the smallest relative change in */ /* any element of A or B that makes X(j) an exact solution). */ /* WORK (workspace/output) DOUBLE PRECISION array, dimension (3*N) */ /* On exit, WORK(1) contains the reciprocal pivot growth */ /* factor norm(A)/norm(U). The "max absolute element" norm is */ /* used. If WORK(1) is much less than 1, then the stability */ /* of the LU factorization of the (equilibrated) matrix A */ /* could be poor. This also means that the solution X, condition */ /* estimator RCOND, and forward error bound FERR could be */ /* unreliable. If factorization fails with 0<INFO<=N, then */ /* WORK(1) contains the reciprocal pivot growth factor for the */ /* leading INFO columns of A. */ /* IWORK (workspace) INTEGER array, dimension (N) */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value */ /* > 0: if INFO = i, and i is */ /* <= N: U(i,i) is exactly zero. The factorization */ /* has been completed, but the factor U is exactly */ /* singular, so the solution and error bounds */ /* could not be computed. RCOND = 0 is returned. */ /* = N+1: U is nonsingular, but RCOND is less than machine */ /* precision, meaning that the matrix is singular */ /* to working precision. Nevertheless, the */ /* solution and error bounds are computed because */ /* there are a number of situations where the */ /* computed solution can be more accurate than the */ /* value of RCOND would suggest. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Parameter adjustments */ ab_dim1 = *ldab; ab_offset = 1 + ab_dim1; ab -= ab_offset; afb_dim1 = *ldafb; afb_offset = 1 + afb_dim1; afb -= afb_offset; --ipiv; --r__; --c__; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; x_dim1 = *ldx; x_offset = 1 + x_dim1; x -= x_offset; --ferr; --berr; --work; --iwork; /* Function Body */ *info = 0; nofact = lsame_(fact, "N"); equil = lsame_(fact, "E"); notran = lsame_(trans, "N"); if (nofact || equil) { *(unsigned char *)equed = 'N'; rowequ = FALSE_; colequ = FALSE_; } else { rowequ = lsame_(equed, "R") || lsame_(equed, "B"); colequ = lsame_(equed, "C") || lsame_(equed, "B"); smlnum = dlamch_("Safe minimum"); bignum = 1. / smlnum; } /* Test the input parameters. */ if (! nofact && ! equil && ! lsame_(fact, "F")) { *info = -1; } else if (! notran && ! lsame_(trans, "T") && ! lsame_(trans, "C")) { *info = -2; } else if (*n < 0) { *info = -3; } else if (*kl < 0) { *info = -4; } else if (*ku < 0) { *info = -5; } else if (*nrhs < 0) { *info = -6; } else if (*ldab < *kl + *ku + 1) { *info = -8; } else if (*ldafb < (*kl << 1) + *ku + 1) { *info = -10; } else if (lsame_(fact, "F") && ! (rowequ || colequ || lsame_(equed, "N"))) { *info = -12; } else { if (rowequ) { rcmin = bignum; rcmax = 0.; i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Computing MIN */ d__1 = rcmin, d__2 = r__[j]; rcmin = min(d__1,d__2); /* Computing MAX */ d__1 = rcmax, d__2 = r__[j]; rcmax = max(d__1,d__2); /* L10: */ } if (rcmin <= 0.) { *info = -13; } else if (*n > 0) { rowcnd = max(rcmin,smlnum) / min(rcmax,bignum); } else { rowcnd = 1.; } } if (colequ && *info == 0) { rcmin = bignum; rcmax = 0.; i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Computing MIN */ d__1 = rcmin, d__2 = c__[j]; rcmin = min(d__1,d__2); /* Computing MAX */ d__1 = rcmax, d__2 = c__[j]; rcmax = max(d__1,d__2); /* L20: */ } if (rcmin <= 0.) { *info = -14; } else if (*n > 0) { colcnd = max(rcmin,smlnum) / min(rcmax,bignum); } else { colcnd = 1.; } } if (*info == 0) { if (*ldb < max(1,*n)) { *info = -16; } else if (*ldx < max(1,*n)) { *info = -18; } } } if (*info != 0) { i__1 = -(*info); xerbla_("DGBSVX", &i__1); return 0; } if (equil) { /* Compute row and column scalings to equilibrate the matrix A. */ dgbequ_(n, n, kl, ku, &ab[ab_offset], ldab, &r__[1], &c__[1], &rowcnd, &colcnd, &amax, &infequ); if (infequ == 0) { /* Equilibrate the matrix. */ dlaqgb_(n, n, kl, ku, &ab[ab_offset], ldab, &r__[1], &c__[1], & rowcnd, &colcnd, &amax, equed); rowequ = lsame_(equed, "R") || lsame_(equed, "B"); colequ = lsame_(equed, "C") || lsame_(equed, "B"); } } /* Scale the right hand side. */ if (notran) { if (rowequ) { i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { b[i__ + j * b_dim1] = r__[i__] * b[i__ + j * b_dim1]; /* L30: */ } /* L40: */ } } } else if (colequ) { i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { b[i__ + j * b_dim1] = c__[i__] * b[i__ + j * b_dim1]; /* L50: */ } /* L60: */ } } if (nofact || equil) { /* Compute the LU factorization of the band matrix A. */ i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Computing MAX */ i__2 = j - *ku; j1 = max(i__2,1); /* Computing MIN */ i__2 = j + *kl; j2 = min(i__2,*n); i__2 = j2 - j1 + 1; dcopy_(&i__2, &ab[*ku + 1 - j + j1 + j * ab_dim1], &c__1, &afb[* kl + *ku + 1 - j + j1 + j * afb_dim1], &c__1); /* L70: */ } dgbtrf_(n, n, kl, ku, &afb[afb_offset], ldafb, &ipiv[1], info); /* Return if INFO is non-zero. */ if (*info > 0) { /* Compute the reciprocal pivot growth factor of the */ /* leading rank-deficient INFO columns of A. */ anorm = 0.; i__1 = *info; for (j = 1; j <= i__1; ++j) { /* Computing MAX */ i__2 = *ku + 2 - j; /* Computing MIN */ i__4 = *n + *ku + 1 - j, i__5 = *kl + *ku + 1; i__3 = min(i__4,i__5); for (i__ = max(i__2,1); i__ <= i__3; ++i__) { /* Computing MAX */ d__2 = anorm, d__3 = (d__1 = ab[i__ + j * ab_dim1], abs( d__1)); anorm = max(d__2,d__3); /* L80: */ } /* L90: */ } /* Computing MIN */ i__3 = *info - 1, i__2 = *kl + *ku; i__1 = min(i__3,i__2); /* Computing MAX */ i__4 = 1, i__5 = *kl + *ku + 2 - *info; rpvgrw = dlantb_("M", "U", "N", info, &i__1, &afb[max(i__4, i__5) + afb_dim1], ldafb, &work[1]); if (rpvgrw == 0.) { rpvgrw = 1.; } else { rpvgrw = anorm / rpvgrw; } work[1] = rpvgrw; *rcond = 0.; return 0; } } /* Compute the norm of the matrix A and the */ /* reciprocal pivot growth factor RPVGRW. */ if (notran) { *(unsigned char *)norm = '1'; } else { *(unsigned char *)norm = 'I'; } anorm = dlangb_(norm, n, kl, ku, &ab[ab_offset], ldab, &work[1]); i__1 = *kl + *ku; rpvgrw = dlantb_("M", "U", "N", n, &i__1, &afb[afb_offset], ldafb, &work[ 1]); if (rpvgrw == 0.) { rpvgrw = 1.; } else { rpvgrw = dlangb_("M", n, kl, ku, &ab[ab_offset], ldab, &work[1]) / rpvgrw; } /* Compute the reciprocal of the condition number of A. */ dgbcon_(norm, n, kl, ku, &afb[afb_offset], ldafb, &ipiv[1], &anorm, rcond, &work[1], &iwork[1], info); /* Compute the solution matrix X. */ dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx); dgbtrs_(trans, n, kl, ku, nrhs, &afb[afb_offset], ldafb, &ipiv[1], &x[ x_offset], ldx, info); /* Use iterative refinement to improve the computed solution and */ /* compute error bounds and backward error estimates for it. */ dgbrfs_(trans, n, kl, ku, nrhs, &ab[ab_offset], ldab, &afb[afb_offset], ldafb, &ipiv[1], &b[b_offset], ldb, &x[x_offset], ldx, &ferr[1], & berr[1], &work[1], &iwork[1], info); /* Transform the solution matrix X to a solution of the original */ /* system. */ if (notran) { if (colequ) { i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { i__3 = *n; for (i__ = 1; i__ <= i__3; ++i__) { x[i__ + j * x_dim1] = c__[i__] * x[i__ + j * x_dim1]; /* L100: */ } /* L110: */ } i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { ferr[j] /= colcnd; /* L120: */ } } } else if (rowequ) { i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { i__3 = *n; for (i__ = 1; i__ <= i__3; ++i__) { x[i__ + j * x_dim1] = r__[i__] * x[i__ + j * x_dim1]; /* L130: */ } /* L140: */ } i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { ferr[j] /= rowcnd; /* L150: */ } } /* Set INFO = N+1 if the matrix is singular to working precision. */ if (*rcond < dlamch_("Epsilon")) { *info = *n + 1; } work[1] = rpvgrw; return 0; /* End of DGBSVX */ } /* dgbsvx_ */
/* Subroutine */ int zlaset_(char *uplo, integer *m, integer *n, doublecomplex *alpha, doublecomplex *beta, doublecomplex *a, integer * lda) { /* System generated locals */ integer a_dim1, a_offset, i__1, i__2, i__3; /* Local variables */ integer i__, j; /* -- LAPACK auxiliary routine (version 3.2) -- */ /* November 2006 */ /* Purpose */ /* ======= */ /* ZLASET initializes a 2-D array A to BETA on the diagonal and */ /* ALPHA on the offdiagonals. */ /* Arguments */ /* ========= */ /* UPLO (input) CHARACTER*1 */ /* Specifies the part of the matrix A to be set. */ /* = 'U': Upper triangular part is set. The lower triangle */ /* is unchanged. */ /* = 'L': Lower triangular part is set. The upper triangle */ /* is unchanged. */ /* Otherwise: All of the matrix A is set. */ /* M (input) INTEGER */ /* On entry, M specifies the number of rows of A. */ /* N (input) INTEGER */ /* On entry, N specifies the number of columns of A. */ /* ALPHA (input) COMPLEX*16 */ /* All the offdiagonal array elements are set to ALPHA. */ /* BETA (input) COMPLEX*16 */ /* All the diagonal array elements are set to BETA. */ /* A (input/output) COMPLEX*16 array, dimension (LDA,N) */ /* On entry, the m by n matrix A. */ /* On exit, A(i,j) = ALPHA, 1 <= i <= m, 1 <= j <= n, i.ne.j; */ /* A(i,i) = BETA , 1 <= i <= min(m,n) */ /* LDA (input) INTEGER */ /* The leading dimension of the array A. LDA >= max(1,M). */ /* ===================================================================== */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; /* Function Body */ if (lsame_(uplo, "U")) { /* Set the diagonal to BETA and the strictly upper triangular */ /* part of the array to ALPHA. */ i__1 = *n; for (j = 2; j <= i__1; ++j) { /* Computing MIN */ i__3 = j - 1; i__2 = min(i__3,*m); for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__ + j * a_dim1; a[i__3].r = alpha->r, a[i__3].i = alpha->i; } } i__1 = min(*n,*m); for (i__ = 1; i__ <= i__1; ++i__) { i__2 = i__ + i__ * a_dim1; a[i__2].r = beta->r, a[i__2].i = beta->i; } } else if (lsame_(uplo, "L")) { /* Set the diagonal to BETA and the strictly lower triangular */ /* part of the array to ALPHA. */ i__1 = min(*m,*n); for (j = 1; j <= i__1; ++j) { i__2 = *m; for (i__ = j + 1; i__ <= i__2; ++i__) { i__3 = i__ + j * a_dim1; a[i__3].r = alpha->r, a[i__3].i = alpha->i; } } i__1 = min(*n,*m); for (i__ = 1; i__ <= i__1; ++i__) { i__2 = i__ + i__ * a_dim1; a[i__2].r = beta->r, a[i__2].i = beta->i; } } else { /* Set the array to BETA on the diagonal and ALPHA on the */ /* offdiagonal. */ i__1 = *n; for (j = 1; j <= i__1; ++j) { i__2 = *m; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__ + j * a_dim1; a[i__3].r = alpha->r, a[i__3].i = alpha->i; } } i__1 = min(*m,*n); for (i__ = 1; i__ <= i__1; ++i__) { i__2 = i__ + i__ * a_dim1; a[i__2].r = beta->r, a[i__2].i = beta->i; } } return 0; /* End of ZLASET */ } /* zlaset_ */
int zlahef_(char *uplo, int *n, int *nb, int *kb, doublecomplex *a, int *lda, int *ipiv, doublecomplex *w, int *ldw, int *info) { /* System generated locals */ int a_dim1, a_offset, w_dim1, w_offset, i__1, i__2, i__3, i__4, i__5; double d__1, d__2, d__3, d__4; doublecomplex z__1, z__2, z__3, z__4; /* Builtin functions */ double sqrt(double), d_imag(doublecomplex *); void d_cnjg(doublecomplex *, doublecomplex *), z_div(doublecomplex *, doublecomplex *, doublecomplex *); /* Local variables */ int j, k; double t, r1; doublecomplex d11, d21, d22; int jb, jj, kk, jp, kp, kw, kkw, imax, jmax; double alpha; extern int lsame_(char *, char *); extern int zgemm_(char *, char *, int *, int *, int *, doublecomplex *, doublecomplex *, int *, doublecomplex *, int *, doublecomplex *, doublecomplex *, int *); int kstep; extern int zgemv_(char *, int *, int *, doublecomplex *, doublecomplex *, int *, doublecomplex *, int *, doublecomplex *, doublecomplex *, int *), zcopy_(int *, doublecomplex *, int *, doublecomplex *, int *), zswap_(int *, doublecomplex *, int *, doublecomplex *, int *); double absakk; extern int zdscal_(int *, double *, doublecomplex *, int *); double colmax; extern int zlacgv_(int *, doublecomplex *, int *) ; extern int izamax_(int *, doublecomplex *, int *); double rowmax; /* -- LAPACK routine (version 3.2) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZLAHEF computes a partial factorization of a complex Hermitian */ /* matrix A using the Bunch-Kaufman diagonal pivoting method. The */ /* partial factorization has the form: */ /* A = ( I U12 ) ( A11 0 ) ( I 0 ) if UPLO = 'U', or: */ /* ( 0 U22 ) ( 0 D ) ( U12' U22' ) */ /* A = ( L11 0 ) ( D 0 ) ( L11' L21' ) if UPLO = 'L' */ /* ( L21 I ) ( 0 A22 ) ( 0 I ) */ /* where the order of D is at most NB. The actual order is returned in */ /* the argument KB, and is either NB or NB-1, or N if N <= NB. */ /* Note that U' denotes the conjugate transpose of U. */ /* ZLAHEF is an auxiliary routine called by ZHETRF. It uses blocked code */ /* (calling Level 3 BLAS) to update the submatrix A11 (if UPLO = 'U') or */ /* A22 (if UPLO = 'L'). */ /* Arguments */ /* ========= */ /* UPLO (input) CHARACTER*1 */ /* Specifies whether the upper or lower triangular part of the */ /* Hermitian matrix A is stored: */ /* = 'U': Upper triangular */ /* = 'L': Lower triangular */ /* N (input) INTEGER */ /* The order of the matrix A. N >= 0. */ /* NB (input) INTEGER */ /* The maximum number of columns of the matrix A that should be */ /* factored. NB should be at least 2 to allow for 2-by-2 pivot */ /* blocks. */ /* KB (output) INTEGER */ /* The number of columns of A that were actually factored. */ /* KB is either NB-1 or NB, or N if N <= NB. */ /* A (input/output) COMPLEX*16 array, dimension (LDA,N) */ /* On entry, the Hermitian matrix A. If UPLO = 'U', the leading */ /* n-by-n upper triangular part of A contains the upper */ /* triangular part of the matrix A, and the strictly lower */ /* triangular part of A is not referenced. If UPLO = 'L', the */ /* leading n-by-n lower triangular part of A contains the lower */ /* triangular part of the matrix A, and the strictly upper */ /* triangular part of A is not referenced. */ /* On exit, A contains details of the partial factorization. */ /* LDA (input) INTEGER */ /* The leading dimension of the array A. LDA >= MAX(1,N). */ /* IPIV (output) INTEGER array, dimension (N) */ /* Details of the interchanges and the block structure of D. */ /* If UPLO = 'U', only the last KB elements of IPIV are set; */ /* if UPLO = 'L', only the first KB elements are set. */ /* If IPIV(k) > 0, then rows and columns k and IPIV(k) were */ /* interchanged and D(k,k) is a 1-by-1 diagonal block. */ /* If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */ /* columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */ /* is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = */ /* IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */ /* interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */ /* W (workspace) COMPLEX*16 array, dimension (LDW,NB) */ /* LDW (input) INTEGER */ /* The leading dimension of the array W. LDW >= MAX(1,N). */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* > 0: if INFO = k, D(k,k) is exactly zero. The factorization */ /* has been completed, but the block diagonal matrix D is */ /* exactly singular. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Statement Functions .. */ /* .. */ /* .. Statement Function definitions .. */ /* .. */ /* .. Executable Statements .. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; --ipiv; w_dim1 = *ldw; w_offset = 1 + w_dim1; w -= w_offset; /* Function Body */ *info = 0; /* Initialize ALPHA for use in choosing pivot block size. */ alpha = (sqrt(17.) + 1.) / 8.; if (lsame_(uplo, "U")) { /* Factorize the trailing columns of A using the upper triangle */ /* of A and working backwards, and compute the matrix W = U12*D */ /* for use in updating A11 (note that conjg(W) is actually stored) */ /* K is the main loop index, decreasing from N in steps of 1 or 2 */ /* KW is the column of W which corresponds to column K of A */ k = *n; L10: kw = *nb + k - *n; /* Exit from loop */ if (k <= *n - *nb + 1 && *nb < *n || k < 1) { goto L30; } /* Copy column K of A to column KW of W and update it */ i__1 = k - 1; zcopy_(&i__1, &a[k * a_dim1 + 1], &c__1, &w[kw * w_dim1 + 1], &c__1); i__1 = k + kw * w_dim1; i__2 = k + k * a_dim1; d__1 = a[i__2].r; w[i__1].r = d__1, w[i__1].i = 0.; if (k < *n) { i__1 = *n - k; z__1.r = -1., z__1.i = -0.; zgemv_("No transpose", &k, &i__1, &z__1, &a[(k + 1) * a_dim1 + 1], lda, &w[k + (kw + 1) * w_dim1], ldw, &c_b1, &w[kw * w_dim1 + 1], &c__1); i__1 = k + kw * w_dim1; i__2 = k + kw * w_dim1; d__1 = w[i__2].r; w[i__1].r = d__1, w[i__1].i = 0.; } kstep = 1; /* Determine rows and columns to be interchanged and whether */ /* a 1-by-1 or 2-by-2 pivot block will be used */ i__1 = k + kw * w_dim1; absakk = (d__1 = w[i__1].r, ABS(d__1)); /* IMAX is the row-index of the largest off-diagonal element in */ /* column K, and COLMAX is its absolute value */ if (k > 1) { i__1 = k - 1; imax = izamax_(&i__1, &w[kw * w_dim1 + 1], &c__1); i__1 = imax + kw * w_dim1; colmax = (d__1 = w[i__1].r, ABS(d__1)) + (d__2 = d_imag(&w[imax + kw * w_dim1]), ABS(d__2)); } else { colmax = 0.; } if (MAX(absakk,colmax) == 0.) { /* Column K is zero: set INFO and continue */ if (*info == 0) { *info = k; } kp = k; i__1 = k + k * a_dim1; i__2 = k + k * a_dim1; d__1 = a[i__2].r; a[i__1].r = d__1, a[i__1].i = 0.; } else { if (absakk >= alpha * colmax) { /* no interchange, use 1-by-1 pivot block */ kp = k; } else { /* Copy column IMAX to column KW-1 of W and update it */ i__1 = imax - 1; zcopy_(&i__1, &a[imax * a_dim1 + 1], &c__1, &w[(kw - 1) * w_dim1 + 1], &c__1); i__1 = imax + (kw - 1) * w_dim1; i__2 = imax + imax * a_dim1; d__1 = a[i__2].r; w[i__1].r = d__1, w[i__1].i = 0.; i__1 = k - imax; zcopy_(&i__1, &a[imax + (imax + 1) * a_dim1], lda, &w[imax + 1 + (kw - 1) * w_dim1], &c__1); i__1 = k - imax; zlacgv_(&i__1, &w[imax + 1 + (kw - 1) * w_dim1], &c__1); if (k < *n) { i__1 = *n - k; z__1.r = -1., z__1.i = -0.; zgemv_("No transpose", &k, &i__1, &z__1, &a[(k + 1) * a_dim1 + 1], lda, &w[imax + (kw + 1) * w_dim1], ldw, &c_b1, &w[(kw - 1) * w_dim1 + 1], &c__1); i__1 = imax + (kw - 1) * w_dim1; i__2 = imax + (kw - 1) * w_dim1; d__1 = w[i__2].r; w[i__1].r = d__1, w[i__1].i = 0.; } /* JMAX is the column-index of the largest off-diagonal */ /* element in row IMAX, and ROWMAX is its absolute value */ i__1 = k - imax; jmax = imax + izamax_(&i__1, &w[imax + 1 + (kw - 1) * w_dim1], &c__1); i__1 = jmax + (kw - 1) * w_dim1; rowmax = (d__1 = w[i__1].r, ABS(d__1)) + (d__2 = d_imag(&w[ jmax + (kw - 1) * w_dim1]), ABS(d__2)); if (imax > 1) { i__1 = imax - 1; jmax = izamax_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1); /* Computing MAX */ i__1 = jmax + (kw - 1) * w_dim1; d__3 = rowmax, d__4 = (d__1 = w[i__1].r, ABS(d__1)) + ( d__2 = d_imag(&w[jmax + (kw - 1) * w_dim1]), ABS( d__2)); rowmax = MAX(d__3,d__4); } if (absakk >= alpha * colmax * (colmax / rowmax)) { /* no interchange, use 1-by-1 pivot block */ kp = k; } else /* if(complicated condition) */ { i__1 = imax + (kw - 1) * w_dim1; if ((d__1 = w[i__1].r, ABS(d__1)) >= alpha * rowmax) { /* interchange rows and columns K and IMAX, use 1-by-1 */ /* pivot block */ kp = imax; /* copy column KW-1 of W to column KW */ zcopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw * w_dim1 + 1], &c__1); } else { /* interchange rows and columns K-1 and IMAX, use 2-by-2 */ /* pivot block */ kp = imax; kstep = 2; } } } kk = k - kstep + 1; kkw = *nb + kk - *n; /* Updated column KP is already stored in column KKW of W */ if (kp != kk) { /* Copy non-updated column KK to column KP */ i__1 = kp + kp * a_dim1; i__2 = kk + kk * a_dim1; d__1 = a[i__2].r; a[i__1].r = d__1, a[i__1].i = 0.; i__1 = kk - 1 - kp; zcopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + (kp + 1) * a_dim1], lda); i__1 = kk - 1 - kp; zlacgv_(&i__1, &a[kp + (kp + 1) * a_dim1], lda); i__1 = kp - 1; zcopy_(&i__1, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1 + 1], &c__1); /* Interchange rows KK and KP in last KK columns of A and W */ if (kk < *n) { i__1 = *n - kk; zswap_(&i__1, &a[kk + (kk + 1) * a_dim1], lda, &a[kp + ( kk + 1) * a_dim1], lda); } i__1 = *n - kk + 1; zswap_(&i__1, &w[kk + kkw * w_dim1], ldw, &w[kp + kkw * w_dim1], ldw); } if (kstep == 1) { /* 1-by-1 pivot block D(k): column KW of W now holds */ /* W(k) = U(k)*D(k) */ /* where U(k) is the k-th column of U */ /* Store U(k) in column k of A */ zcopy_(&k, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1], & c__1); i__1 = k + k * a_dim1; r1 = 1. / a[i__1].r; i__1 = k - 1; zdscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1); /* Conjugate W(k) */ i__1 = k - 1; zlacgv_(&i__1, &w[kw * w_dim1 + 1], &c__1); } else { /* 2-by-2 pivot block D(k): columns KW and KW-1 of W now */ /* hold */ /* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */ /* where U(k) and U(k-1) are the k-th and (k-1)-th columns */ /* of U */ if (k > 2) { /* Store U(k) and U(k-1) in columns k and k-1 of A */ i__1 = k - 1 + kw * w_dim1; d21.r = w[i__1].r, d21.i = w[i__1].i; d_cnjg(&z__2, &d21); z_div(&z__1, &w[k + kw * w_dim1], &z__2); d11.r = z__1.r, d11.i = z__1.i; z_div(&z__1, &w[k - 1 + (kw - 1) * w_dim1], &d21); d22.r = z__1.r, d22.i = z__1.i; z__1.r = d11.r * d22.r - d11.i * d22.i, z__1.i = d11.r * d22.i + d11.i * d22.r; t = 1. / (z__1.r - 1.); z__2.r = t, z__2.i = 0.; z_div(&z__1, &z__2, &d21); d21.r = z__1.r, d21.i = z__1.i; i__1 = k - 2; for (j = 1; j <= i__1; ++j) { i__2 = j + (k - 1) * a_dim1; i__3 = j + (kw - 1) * w_dim1; z__3.r = d11.r * w[i__3].r - d11.i * w[i__3].i, z__3.i = d11.r * w[i__3].i + d11.i * w[i__3] .r; i__4 = j + kw * w_dim1; z__2.r = z__3.r - w[i__4].r, z__2.i = z__3.i - w[i__4] .i; z__1.r = d21.r * z__2.r - d21.i * z__2.i, z__1.i = d21.r * z__2.i + d21.i * z__2.r; a[i__2].r = z__1.r, a[i__2].i = z__1.i; i__2 = j + k * a_dim1; d_cnjg(&z__2, &d21); i__3 = j + kw * w_dim1; z__4.r = d22.r * w[i__3].r - d22.i * w[i__3].i, z__4.i = d22.r * w[i__3].i + d22.i * w[i__3] .r; i__4 = j + (kw - 1) * w_dim1; z__3.r = z__4.r - w[i__4].r, z__3.i = z__4.i - w[i__4] .i; z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i = z__2.r * z__3.i + z__2.i * z__3.r; a[i__2].r = z__1.r, a[i__2].i = z__1.i; /* L20: */ } } /* Copy D(k) to A */ i__1 = k - 1 + (k - 1) * a_dim1; i__2 = k - 1 + (kw - 1) * w_dim1; a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i; i__1 = k - 1 + k * a_dim1; i__2 = k - 1 + kw * w_dim1; a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i; i__1 = k + k * a_dim1; i__2 = k + kw * w_dim1; a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i; /* Conjugate W(k) and W(k-1) */ i__1 = k - 1; zlacgv_(&i__1, &w[kw * w_dim1 + 1], &c__1); i__1 = k - 2; zlacgv_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1); } } /* Store details of the interchanges in IPIV */ if (kstep == 1) { ipiv[k] = kp; } else { ipiv[k] = -kp; ipiv[k - 1] = -kp; } /* Decrease K and return to the start of the main loop */ k -= kstep; goto L10; L30: /* Update the upper triangle of A11 (= A(1:k,1:k)) as */ /* A11 := A11 - U12*D*U12' = A11 - U12*W' */ /* computing blocks of NB columns at a time (note that conjg(W) is */ /* actually stored) */ i__1 = -(*nb); for (j = (k - 1) / *nb * *nb + 1; i__1 < 0 ? j >= 1 : j <= 1; j += i__1) { /* Computing MIN */ i__2 = *nb, i__3 = k - j + 1; jb = MIN(i__2,i__3); /* Update the upper triangle of the diagonal block */ i__2 = j + jb - 1; for (jj = j; jj <= i__2; ++jj) { i__3 = jj + jj * a_dim1; i__4 = jj + jj * a_dim1; d__1 = a[i__4].r; a[i__3].r = d__1, a[i__3].i = 0.; i__3 = jj - j + 1; i__4 = *n - k; z__1.r = -1., z__1.i = -0.; zgemv_("No transpose", &i__3, &i__4, &z__1, &a[j + (k + 1) * a_dim1], lda, &w[jj + (kw + 1) * w_dim1], ldw, &c_b1, &a[j + jj * a_dim1], &c__1); i__3 = jj + jj * a_dim1; i__4 = jj + jj * a_dim1; d__1 = a[i__4].r; a[i__3].r = d__1, a[i__3].i = 0.; /* L40: */ } /* Update the rectangular superdiagonal block */ i__2 = j - 1; i__3 = *n - k; z__1.r = -1., z__1.i = -0.; zgemm_("No transpose", "Transpose", &i__2, &jb, &i__3, &z__1, &a[( k + 1) * a_dim1 + 1], lda, &w[j + (kw + 1) * w_dim1], ldw, &c_b1, &a[j * a_dim1 + 1], lda); /* L50: */ } /* Put U12 in standard form by partially undoing the interchanges */ /* in columns k+1:n */ j = k + 1; L60: jj = j; jp = ipiv[j]; if (jp < 0) { jp = -jp; ++j; } ++j; if (jp != jj && j <= *n) { i__1 = *n - j + 1; zswap_(&i__1, &a[jp + j * a_dim1], lda, &a[jj + j * a_dim1], lda); } if (j <= *n) { goto L60; } /* Set KB to the number of columns factorized */ *kb = *n - k; } else { /* Factorize the leading columns of A using the lower triangle */ /* of A and working forwards, and compute the matrix W = L21*D */ /* for use in updating A22 (note that conjg(W) is actually stored) */ /* K is the main loop index, increasing from 1 in steps of 1 or 2 */ k = 1; L70: /* Exit from loop */ if (k >= *nb && *nb < *n || k > *n) { goto L90; } /* Copy column K of A to column K of W and update it */ i__1 = k + k * w_dim1; i__2 = k + k * a_dim1; d__1 = a[i__2].r; w[i__1].r = d__1, w[i__1].i = 0.; if (k < *n) { i__1 = *n - k; zcopy_(&i__1, &a[k + 1 + k * a_dim1], &c__1, &w[k + 1 + k * w_dim1], &c__1); } i__1 = *n - k + 1; i__2 = k - 1; z__1.r = -1., z__1.i = -0.; zgemv_("No transpose", &i__1, &i__2, &z__1, &a[k + a_dim1], lda, &w[k + w_dim1], ldw, &c_b1, &w[k + k * w_dim1], &c__1); i__1 = k + k * w_dim1; i__2 = k + k * w_dim1; d__1 = w[i__2].r; w[i__1].r = d__1, w[i__1].i = 0.; kstep = 1; /* Determine rows and columns to be interchanged and whether */ /* a 1-by-1 or 2-by-2 pivot block will be used */ i__1 = k + k * w_dim1; absakk = (d__1 = w[i__1].r, ABS(d__1)); /* IMAX is the row-index of the largest off-diagonal element in */ /* column K, and COLMAX is its absolute value */ if (k < *n) { i__1 = *n - k; imax = k + izamax_(&i__1, &w[k + 1 + k * w_dim1], &c__1); i__1 = imax + k * w_dim1; colmax = (d__1 = w[i__1].r, ABS(d__1)) + (d__2 = d_imag(&w[imax + k * w_dim1]), ABS(d__2)); } else { colmax = 0.; } if (MAX(absakk,colmax) == 0.) { /* Column K is zero: set INFO and continue */ if (*info == 0) { *info = k; } kp = k; i__1 = k + k * a_dim1; i__2 = k + k * a_dim1; d__1 = a[i__2].r; a[i__1].r = d__1, a[i__1].i = 0.; } else { if (absakk >= alpha * colmax) { /* no interchange, use 1-by-1 pivot block */ kp = k; } else { /* Copy column IMAX to column K+1 of W and update it */ i__1 = imax - k; zcopy_(&i__1, &a[imax + k * a_dim1], lda, &w[k + (k + 1) * w_dim1], &c__1); i__1 = imax - k; zlacgv_(&i__1, &w[k + (k + 1) * w_dim1], &c__1); i__1 = imax + (k + 1) * w_dim1; i__2 = imax + imax * a_dim1; d__1 = a[i__2].r; w[i__1].r = d__1, w[i__1].i = 0.; if (imax < *n) { i__1 = *n - imax; zcopy_(&i__1, &a[imax + 1 + imax * a_dim1], &c__1, &w[ imax + 1 + (k + 1) * w_dim1], &c__1); } i__1 = *n - k + 1; i__2 = k - 1; z__1.r = -1., z__1.i = -0.; zgemv_("No transpose", &i__1, &i__2, &z__1, &a[k + a_dim1], lda, &w[imax + w_dim1], ldw, &c_b1, &w[k + (k + 1) * w_dim1], &c__1); i__1 = imax + (k + 1) * w_dim1; i__2 = imax + (k + 1) * w_dim1; d__1 = w[i__2].r; w[i__1].r = d__1, w[i__1].i = 0.; /* JMAX is the column-index of the largest off-diagonal */ /* element in row IMAX, and ROWMAX is its absolute value */ i__1 = imax - k; jmax = k - 1 + izamax_(&i__1, &w[k + (k + 1) * w_dim1], &c__1) ; i__1 = jmax + (k + 1) * w_dim1; rowmax = (d__1 = w[i__1].r, ABS(d__1)) + (d__2 = d_imag(&w[ jmax + (k + 1) * w_dim1]), ABS(d__2)); if (imax < *n) { i__1 = *n - imax; jmax = imax + izamax_(&i__1, &w[imax + 1 + (k + 1) * w_dim1], &c__1); /* Computing MAX */ i__1 = jmax + (k + 1) * w_dim1; d__3 = rowmax, d__4 = (d__1 = w[i__1].r, ABS(d__1)) + ( d__2 = d_imag(&w[jmax + (k + 1) * w_dim1]), ABS( d__2)); rowmax = MAX(d__3,d__4); } if (absakk >= alpha * colmax * (colmax / rowmax)) { /* no interchange, use 1-by-1 pivot block */ kp = k; } else /* if(complicated condition) */ { i__1 = imax + (k + 1) * w_dim1; if ((d__1 = w[i__1].r, ABS(d__1)) >= alpha * rowmax) { /* interchange rows and columns K and IMAX, use 1-by-1 */ /* pivot block */ kp = imax; /* copy column K+1 of W to column K */ i__1 = *n - k + 1; zcopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k + k * w_dim1], &c__1); } else { /* interchange rows and columns K+1 and IMAX, use 2-by-2 */ /* pivot block */ kp = imax; kstep = 2; } } } kk = k + kstep - 1; /* Updated column KP is already stored in column KK of W */ if (kp != kk) { /* Copy non-updated column KK to column KP */ i__1 = kp + kp * a_dim1; i__2 = kk + kk * a_dim1; d__1 = a[i__2].r; a[i__1].r = d__1, a[i__1].i = 0.; i__1 = kp - kk - 1; zcopy_(&i__1, &a[kk + 1 + kk * a_dim1], &c__1, &a[kp + (kk + 1) * a_dim1], lda); i__1 = kp - kk - 1; zlacgv_(&i__1, &a[kp + (kk + 1) * a_dim1], lda); if (kp < *n) { i__1 = *n - kp; zcopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + 1 + kp * a_dim1], &c__1); } /* Interchange rows KK and KP in first KK columns of A and W */ i__1 = kk - 1; zswap_(&i__1, &a[kk + a_dim1], lda, &a[kp + a_dim1], lda); zswap_(&kk, &w[kk + w_dim1], ldw, &w[kp + w_dim1], ldw); } if (kstep == 1) { /* 1-by-1 pivot block D(k): column k of W now holds */ /* W(k) = L(k)*D(k) */ /* where L(k) is the k-th column of L */ /* Store L(k) in column k of A */ i__1 = *n - k + 1; zcopy_(&i__1, &w[k + k * w_dim1], &c__1, &a[k + k * a_dim1], & c__1); if (k < *n) { i__1 = k + k * a_dim1; r1 = 1. / a[i__1].r; i__1 = *n - k; zdscal_(&i__1, &r1, &a[k + 1 + k * a_dim1], &c__1); /* Conjugate W(k) */ i__1 = *n - k; zlacgv_(&i__1, &w[k + 1 + k * w_dim1], &c__1); } } else { /* 2-by-2 pivot block D(k): columns k and k+1 of W now hold */ /* ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */ /* where L(k) and L(k+1) are the k-th and (k+1)-th columns */ /* of L */ if (k < *n - 1) { /* Store L(k) and L(k+1) in columns k and k+1 of A */ i__1 = k + 1 + k * w_dim1; d21.r = w[i__1].r, d21.i = w[i__1].i; z_div(&z__1, &w[k + 1 + (k + 1) * w_dim1], &d21); d11.r = z__1.r, d11.i = z__1.i; d_cnjg(&z__2, &d21); z_div(&z__1, &w[k + k * w_dim1], &z__2); d22.r = z__1.r, d22.i = z__1.i; z__1.r = d11.r * d22.r - d11.i * d22.i, z__1.i = d11.r * d22.i + d11.i * d22.r; t = 1. / (z__1.r - 1.); z__2.r = t, z__2.i = 0.; z_div(&z__1, &z__2, &d21); d21.r = z__1.r, d21.i = z__1.i; i__1 = *n; for (j = k + 2; j <= i__1; ++j) { i__2 = j + k * a_dim1; d_cnjg(&z__2, &d21); i__3 = j + k * w_dim1; z__4.r = d11.r * w[i__3].r - d11.i * w[i__3].i, z__4.i = d11.r * w[i__3].i + d11.i * w[i__3] .r; i__4 = j + (k + 1) * w_dim1; z__3.r = z__4.r - w[i__4].r, z__3.i = z__4.i - w[i__4] .i; z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i = z__2.r * z__3.i + z__2.i * z__3.r; a[i__2].r = z__1.r, a[i__2].i = z__1.i; i__2 = j + (k + 1) * a_dim1; i__3 = j + (k + 1) * w_dim1; z__3.r = d22.r * w[i__3].r - d22.i * w[i__3].i, z__3.i = d22.r * w[i__3].i + d22.i * w[i__3] .r; i__4 = j + k * w_dim1; z__2.r = z__3.r - w[i__4].r, z__2.i = z__3.i - w[i__4] .i; z__1.r = d21.r * z__2.r - d21.i * z__2.i, z__1.i = d21.r * z__2.i + d21.i * z__2.r; a[i__2].r = z__1.r, a[i__2].i = z__1.i; /* L80: */ } } /* Copy D(k) to A */ i__1 = k + k * a_dim1; i__2 = k + k * w_dim1; a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i; i__1 = k + 1 + k * a_dim1; i__2 = k + 1 + k * w_dim1; a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i; i__1 = k + 1 + (k + 1) * a_dim1; i__2 = k + 1 + (k + 1) * w_dim1; a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i; /* Conjugate W(k) and W(k+1) */ i__1 = *n - k; zlacgv_(&i__1, &w[k + 1 + k * w_dim1], &c__1); i__1 = *n - k - 1; zlacgv_(&i__1, &w[k + 2 + (k + 1) * w_dim1], &c__1); } } /* Store details of the interchanges in IPIV */ if (kstep == 1) { ipiv[k] = kp; } else { ipiv[k] = -kp; ipiv[k + 1] = -kp; } /* Increase K and return to the start of the main loop */ k += kstep; goto L70; L90: /* Update the lower triangle of A22 (= A(k:n,k:n)) as */ /* A22 := A22 - L21*D*L21' = A22 - L21*W' */ /* computing blocks of NB columns at a time (note that conjg(W) is */ /* actually stored) */ i__1 = *n; i__2 = *nb; for (j = k; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) { /* Computing MIN */ i__3 = *nb, i__4 = *n - j + 1; jb = MIN(i__3,i__4); /* Update the lower triangle of the diagonal block */ i__3 = j + jb - 1; for (jj = j; jj <= i__3; ++jj) { i__4 = jj + jj * a_dim1; i__5 = jj + jj * a_dim1; d__1 = a[i__5].r; a[i__4].r = d__1, a[i__4].i = 0.; i__4 = j + jb - jj; i__5 = k - 1; z__1.r = -1., z__1.i = -0.; zgemv_("No transpose", &i__4, &i__5, &z__1, &a[jj + a_dim1], lda, &w[jj + w_dim1], ldw, &c_b1, &a[jj + jj * a_dim1] , &c__1); i__4 = jj + jj * a_dim1; i__5 = jj + jj * a_dim1; d__1 = a[i__5].r; a[i__4].r = d__1, a[i__4].i = 0.; /* L100: */ } /* Update the rectangular subdiagonal block */ if (j + jb <= *n) { i__3 = *n - j - jb + 1; i__4 = k - 1; z__1.r = -1., z__1.i = -0.; zgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, &z__1, &a[j + jb + a_dim1], lda, &w[j + w_dim1], ldw, &c_b1, &a[j + jb + j * a_dim1], lda); } /* L110: */ } /* Put L21 in standard form by partially undoing the interchanges */ /* in columns 1:k-1 */ j = k - 1; L120: jj = j; jp = ipiv[j]; if (jp < 0) { jp = -jp; --j; } --j; if (jp != jj && j >= 1) { zswap_(&j, &a[jp + a_dim1], lda, &a[jj + a_dim1], lda); } if (j >= 1) { goto L120; } /* Set KB to the number of columns factorized */ *kb = k - 1; } return 0; /* End of ZLAHEF */ } /* zlahef_ */
/* Subroutine */ int ztrmm_(char *side, char *uplo, char *transa, char *diag, integer *m, integer *n, doublecomplex *alpha, doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, ftnlen side_len, ftnlen uplo_len, ftnlen transa_len, ftnlen diag_len) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3, i__4, i__5, i__6; doublecomplex z__1, z__2, z__3; /* Builtin functions */ void d_cnjg(doublecomplex *, doublecomplex *); /* Local variables */ static integer i__, j, k, info; static doublecomplex temp; static logical lside; extern logical lsame_(char *, char *, ftnlen, ftnlen); static integer nrowa; static logical upper; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); static logical noconj, nounit; /* .. Scalar Arguments .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZTRMM performs one of the matrix-matrix operations */ /* B := alpha*op( A )*B, or B := alpha*B*op( A ) */ /* where alpha is a scalar, B is an m by n matrix, A is a unit, or */ /* non-unit, upper or lower triangular matrix and op( A ) is one of */ /* op( A ) = A or op( A ) = A' or op( A ) = conjg( A' ). */ /* Parameters */ /* ========== */ /* SIDE - CHARACTER*1. */ /* On entry, SIDE specifies whether op( A ) multiplies B from */ /* the left or right as follows: */ /* SIDE = 'L' or 'l' B := alpha*op( A )*B. */ /* SIDE = 'R' or 'r' B := alpha*B*op( A ). */ /* Unchanged on exit. */ /* UPLO - CHARACTER*1. */ /* On entry, UPLO specifies whether the matrix A is an upper or */ /* lower triangular matrix as follows: */ /* UPLO = 'U' or 'u' A is an upper triangular matrix. */ /* UPLO = 'L' or 'l' A is a lower triangular matrix. */ /* Unchanged on exit. */ /* TRANSA - CHARACTER*1. */ /* On entry, TRANSA specifies the form of op( A ) to be used in */ /* the matrix multiplication as follows: */ /* TRANSA = 'N' or 'n' op( A ) = A. */ /* TRANSA = 'T' or 't' op( A ) = A'. */ /* TRANSA = 'C' or 'c' op( A ) = conjg( A' ). */ /* Unchanged on exit. */ /* DIAG - CHARACTER*1. */ /* On entry, DIAG specifies whether or not A is unit triangular */ /* as follows: */ /* DIAG = 'U' or 'u' A is assumed to be unit triangular. */ /* DIAG = 'N' or 'n' A is not assumed to be unit */ /* triangular. */ /* Unchanged on exit. */ /* M - INTEGER. */ /* On entry, M specifies the number of rows of B. M must be at */ /* least zero. */ /* Unchanged on exit. */ /* N - INTEGER. */ /* On entry, N specifies the number of columns of B. N must be */ /* at least zero. */ /* Unchanged on exit. */ /* ALPHA - COMPLEX*16 . */ /* On entry, ALPHA specifies the scalar alpha. When alpha is */ /* zero then A is not referenced and B need not be set before */ /* entry. */ /* Unchanged on exit. */ /* A - COMPLEX*16 array of DIMENSION ( LDA, k ), where k is m */ /* when SIDE = 'L' or 'l' and is n when SIDE = 'R' or 'r'. */ /* Before entry with UPLO = 'U' or 'u', the leading k by k */ /* upper triangular part of the array A must contain the upper */ /* triangular matrix and the strictly lower triangular part of */ /* A is not referenced. */ /* Before entry with UPLO = 'L' or 'l', the leading k by k */ /* lower triangular part of the array A must contain the lower */ /* triangular matrix and the strictly upper triangular part of */ /* A is not referenced. */ /* Note that when DIAG = 'U' or 'u', the diagonal elements of */ /* A are not referenced either, but are assumed to be unity. */ /* Unchanged on exit. */ /* LDA - INTEGER. */ /* On entry, LDA specifies the first dimension of A as declared */ /* in the calling (sub) program. When SIDE = 'L' or 'l' then */ /* LDA must be at least max( 1, m ), when SIDE = 'R' or 'r' */ /* then LDA must be at least max( 1, n ). */ /* Unchanged on exit. */ /* B - COMPLEX*16 array of DIMENSION ( LDB, n ). */ /* Before entry, the leading m by n part of the array B must */ /* contain the matrix B, and on exit is overwritten by the */ /* transformed matrix. */ /* LDB - INTEGER. */ /* On entry, LDB specifies the first dimension of B as declared */ /* in the calling (sub) program. LDB must be at least */ /* max( 1, m ). */ /* Unchanged on exit. */ /* Level 3 Blas routine. */ /* -- Written on 8-February-1989. */ /* Jack Dongarra, Argonne National Laboratory. */ /* Iain Duff, AERE Harwell. */ /* Jeremy Du Croz, Numerical Algorithms Group Ltd. */ /* Sven Hammarling, Numerical Algorithms Group Ltd. */ /* .. External Functions .. */ /* .. External Subroutines .. */ /* .. Intrinsic Functions .. */ /* .. Local Scalars .. */ /* .. Parameters .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input parameters. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; /* Function Body */ lside = lsame_(side, "L", (ftnlen)1, (ftnlen)1); if (lside) { nrowa = *m; } else { nrowa = *n; } noconj = lsame_(transa, "T", (ftnlen)1, (ftnlen)1); nounit = lsame_(diag, "N", (ftnlen)1, (ftnlen)1); upper = lsame_(uplo, "U", (ftnlen)1, (ftnlen)1); info = 0; if (! lside && ! lsame_(side, "R", (ftnlen)1, (ftnlen)1)) { info = 1; } else if (! upper && ! lsame_(uplo, "L", (ftnlen)1, (ftnlen)1)) { info = 2; } else if (! lsame_(transa, "N", (ftnlen)1, (ftnlen)1) && ! lsame_(transa, "T", (ftnlen)1, (ftnlen)1) && ! lsame_(transa, "C", (ftnlen)1, ( ftnlen)1)) { info = 3; } else if (! lsame_(diag, "U", (ftnlen)1, (ftnlen)1) && ! lsame_(diag, "N", (ftnlen)1, (ftnlen)1)) { info = 4; } else if (*m < 0) { info = 5; } else if (*n < 0) { info = 6; } else if (*lda < max(1,nrowa)) { info = 9; } else if (*ldb < max(1,*m)) { info = 11; } if (info != 0) { xerbla_("ZTRMM ", &info, (ftnlen)6); return 0; } /* Quick return if possible. */ if (*n == 0) { return 0; } /* And when alpha.eq.zero. */ if (alpha->r == 0. && alpha->i == 0.) { i__1 = *n; for (j = 1; j <= i__1; ++j) { i__2 = *m; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__ + j * b_dim1; b[i__3].r = 0., b[i__3].i = 0.; /* L10: */ } /* L20: */ } return 0; } /* Start the operations. */ if (lside) { if (lsame_(transa, "N", (ftnlen)1, (ftnlen)1)) { /* Form B := alpha*A*B. */ if (upper) { i__1 = *n; for (j = 1; j <= i__1; ++j) { i__2 = *m; for (k = 1; k <= i__2; ++k) { i__3 = k + j * b_dim1; if (b[i__3].r != 0. || b[i__3].i != 0.) { i__3 = k + j * b_dim1; z__1.r = alpha->r * b[i__3].r - alpha->i * b[i__3] .i, z__1.i = alpha->r * b[i__3].i + alpha->i * b[i__3].r; temp.r = z__1.r, temp.i = z__1.i; i__3 = k - 1; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = i__ + j * b_dim1; i__5 = i__ + j * b_dim1; i__6 = i__ + k * a_dim1; z__2.r = temp.r * a[i__6].r - temp.i * a[i__6] .i, z__2.i = temp.r * a[i__6].i + temp.i * a[i__6].r; z__1.r = b[i__5].r + z__2.r, z__1.i = b[i__5] .i + z__2.i; b[i__4].r = z__1.r, b[i__4].i = z__1.i; /* L30: */ } if (nounit) { i__3 = k + k * a_dim1; z__1.r = temp.r * a[i__3].r - temp.i * a[i__3] .i, z__1.i = temp.r * a[i__3].i + temp.i * a[i__3].r; temp.r = z__1.r, temp.i = z__1.i; } i__3 = k + j * b_dim1; b[i__3].r = temp.r, b[i__3].i = temp.i; } /* L40: */ } /* L50: */ } } else { i__1 = *n; for (j = 1; j <= i__1; ++j) { for (k = *m; k >= 1; --k) { i__2 = k + j * b_dim1; if (b[i__2].r != 0. || b[i__2].i != 0.) { i__2 = k + j * b_dim1; z__1.r = alpha->r * b[i__2].r - alpha->i * b[i__2] .i, z__1.i = alpha->r * b[i__2].i + alpha->i * b[i__2].r; temp.r = z__1.r, temp.i = z__1.i; i__2 = k + j * b_dim1; b[i__2].r = temp.r, b[i__2].i = temp.i; if (nounit) { i__2 = k + j * b_dim1; i__3 = k + j * b_dim1; i__4 = k + k * a_dim1; z__1.r = b[i__3].r * a[i__4].r - b[i__3].i * a[i__4].i, z__1.i = b[i__3].r * a[ i__4].i + b[i__3].i * a[i__4].r; b[i__2].r = z__1.r, b[i__2].i = z__1.i; } i__2 = *m; for (i__ = k + 1; i__ <= i__2; ++i__) { i__3 = i__ + j * b_dim1; i__4 = i__ + j * b_dim1; i__5 = i__ + k * a_dim1; z__2.r = temp.r * a[i__5].r - temp.i * a[i__5] .i, z__2.i = temp.r * a[i__5].i + temp.i * a[i__5].r; z__1.r = b[i__4].r + z__2.r, z__1.i = b[i__4] .i + z__2.i; b[i__3].r = z__1.r, b[i__3].i = z__1.i; /* L60: */ } } /* L70: */ } /* L80: */ } } } else { /* Form B := alpha*B*A' or B := alpha*B*conjg( A' ). */ if (upper) { i__1 = *n; for (j = 1; j <= i__1; ++j) { for (i__ = *m; i__ >= 1; --i__) { i__2 = i__ + j * b_dim1; temp.r = b[i__2].r, temp.i = b[i__2].i; if (noconj) { if (nounit) { i__2 = i__ + i__ * a_dim1; z__1.r = temp.r * a[i__2].r - temp.i * a[i__2] .i, z__1.i = temp.r * a[i__2].i + temp.i * a[i__2].r; temp.r = z__1.r, temp.i = z__1.i; } i__2 = i__ - 1; for (k = 1; k <= i__2; ++k) { i__3 = k + i__ * a_dim1; i__4 = k + j * b_dim1; z__2.r = a[i__3].r * b[i__4].r - a[i__3].i * b[i__4].i, z__2.i = a[i__3].r * b[ i__4].i + a[i__3].i * b[i__4].r; z__1.r = temp.r + z__2.r, z__1.i = temp.i + z__2.i; temp.r = z__1.r, temp.i = z__1.i; /* L90: */ } } else { if (nounit) { d_cnjg(&z__2, &a[i__ + i__ * a_dim1]); z__1.r = temp.r * z__2.r - temp.i * z__2.i, z__1.i = temp.r * z__2.i + temp.i * z__2.r; temp.r = z__1.r, temp.i = z__1.i; } i__2 = i__ - 1; for (k = 1; k <= i__2; ++k) { d_cnjg(&z__3, &a[k + i__ * a_dim1]); i__3 = k + j * b_dim1; z__2.r = z__3.r * b[i__3].r - z__3.i * b[i__3] .i, z__2.i = z__3.r * b[i__3].i + z__3.i * b[i__3].r; z__1.r = temp.r + z__2.r, z__1.i = temp.i + z__2.i; temp.r = z__1.r, temp.i = z__1.i; /* L100: */ } } i__2 = i__ + j * b_dim1; z__1.r = alpha->r * temp.r - alpha->i * temp.i, z__1.i = alpha->r * temp.i + alpha->i * temp.r; b[i__2].r = z__1.r, b[i__2].i = z__1.i; /* L110: */ } /* L120: */ } } else { i__1 = *n; for (j = 1; j <= i__1; ++j) { i__2 = *m; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__ + j * b_dim1; temp.r = b[i__3].r, temp.i = b[i__3].i; if (noconj) { if (nounit) { i__3 = i__ + i__ * a_dim1; z__1.r = temp.r * a[i__3].r - temp.i * a[i__3] .i, z__1.i = temp.r * a[i__3].i + temp.i * a[i__3].r; temp.r = z__1.r, temp.i = z__1.i; } i__3 = *m; for (k = i__ + 1; k <= i__3; ++k) { i__4 = k + i__ * a_dim1; i__5 = k + j * b_dim1; z__2.r = a[i__4].r * b[i__5].r - a[i__4].i * b[i__5].i, z__2.i = a[i__4].r * b[ i__5].i + a[i__4].i * b[i__5].r; z__1.r = temp.r + z__2.r, z__1.i = temp.i + z__2.i; temp.r = z__1.r, temp.i = z__1.i; /* L130: */ } } else { if (nounit) { d_cnjg(&z__2, &a[i__ + i__ * a_dim1]); z__1.r = temp.r * z__2.r - temp.i * z__2.i, z__1.i = temp.r * z__2.i + temp.i * z__2.r; temp.r = z__1.r, temp.i = z__1.i; } i__3 = *m; for (k = i__ + 1; k <= i__3; ++k) { d_cnjg(&z__3, &a[k + i__ * a_dim1]); i__4 = k + j * b_dim1; z__2.r = z__3.r * b[i__4].r - z__3.i * b[i__4] .i, z__2.i = z__3.r * b[i__4].i + z__3.i * b[i__4].r; z__1.r = temp.r + z__2.r, z__1.i = temp.i + z__2.i; temp.r = z__1.r, temp.i = z__1.i; /* L140: */ } } i__3 = i__ + j * b_dim1; z__1.r = alpha->r * temp.r - alpha->i * temp.i, z__1.i = alpha->r * temp.i + alpha->i * temp.r; b[i__3].r = z__1.r, b[i__3].i = z__1.i; /* L150: */ } /* L160: */ } } } } else { if (lsame_(transa, "N", (ftnlen)1, (ftnlen)1)) { /* Form B := alpha*B*A. */ if (upper) { for (j = *n; j >= 1; --j) { temp.r = alpha->r, temp.i = alpha->i; if (nounit) { i__1 = j + j * a_dim1; z__1.r = temp.r * a[i__1].r - temp.i * a[i__1].i, z__1.i = temp.r * a[i__1].i + temp.i * a[i__1] .r; temp.r = z__1.r, temp.i = z__1.i; } i__1 = *m; for (i__ = 1; i__ <= i__1; ++i__) { i__2 = i__ + j * b_dim1; i__3 = i__ + j * b_dim1; z__1.r = temp.r * b[i__3].r - temp.i * b[i__3].i, z__1.i = temp.r * b[i__3].i + temp.i * b[i__3] .r; b[i__2].r = z__1.r, b[i__2].i = z__1.i; /* L170: */ } i__1 = j - 1; for (k = 1; k <= i__1; ++k) { i__2 = k + j * a_dim1; if (a[i__2].r != 0. || a[i__2].i != 0.) { i__2 = k + j * a_dim1; z__1.r = alpha->r * a[i__2].r - alpha->i * a[i__2] .i, z__1.i = alpha->r * a[i__2].i + alpha->i * a[i__2].r; temp.r = z__1.r, temp.i = z__1.i; i__2 = *m; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__ + j * b_dim1; i__4 = i__ + j * b_dim1; i__5 = i__ + k * b_dim1; z__2.r = temp.r * b[i__5].r - temp.i * b[i__5] .i, z__2.i = temp.r * b[i__5].i + temp.i * b[i__5].r; z__1.r = b[i__4].r + z__2.r, z__1.i = b[i__4] .i + z__2.i; b[i__3].r = z__1.r, b[i__3].i = z__1.i; /* L180: */ } } /* L190: */ } /* L200: */ } } else { i__1 = *n; for (j = 1; j <= i__1; ++j) { temp.r = alpha->r, temp.i = alpha->i; if (nounit) { i__2 = j + j * a_dim1; z__1.r = temp.r * a[i__2].r - temp.i * a[i__2].i, z__1.i = temp.r * a[i__2].i + temp.i * a[i__2] .r; temp.r = z__1.r, temp.i = z__1.i; } i__2 = *m; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__ + j * b_dim1; i__4 = i__ + j * b_dim1; z__1.r = temp.r * b[i__4].r - temp.i * b[i__4].i, z__1.i = temp.r * b[i__4].i + temp.i * b[i__4] .r; b[i__3].r = z__1.r, b[i__3].i = z__1.i; /* L210: */ } i__2 = *n; for (k = j + 1; k <= i__2; ++k) { i__3 = k + j * a_dim1; if (a[i__3].r != 0. || a[i__3].i != 0.) { i__3 = k + j * a_dim1; z__1.r = alpha->r * a[i__3].r - alpha->i * a[i__3] .i, z__1.i = alpha->r * a[i__3].i + alpha->i * a[i__3].r; temp.r = z__1.r, temp.i = z__1.i; i__3 = *m; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = i__ + j * b_dim1; i__5 = i__ + j * b_dim1; i__6 = i__ + k * b_dim1; z__2.r = temp.r * b[i__6].r - temp.i * b[i__6] .i, z__2.i = temp.r * b[i__6].i + temp.i * b[i__6].r; z__1.r = b[i__5].r + z__2.r, z__1.i = b[i__5] .i + z__2.i; b[i__4].r = z__1.r, b[i__4].i = z__1.i; /* L220: */ } } /* L230: */ } /* L240: */ } } } else { /* Form B := alpha*B*A' or B := alpha*B*conjg( A' ). */ if (upper) { i__1 = *n; for (k = 1; k <= i__1; ++k) { i__2 = k - 1; for (j = 1; j <= i__2; ++j) { i__3 = j + k * a_dim1; if (a[i__3].r != 0. || a[i__3].i != 0.) { if (noconj) { i__3 = j + k * a_dim1; z__1.r = alpha->r * a[i__3].r - alpha->i * a[ i__3].i, z__1.i = alpha->r * a[i__3] .i + alpha->i * a[i__3].r; temp.r = z__1.r, temp.i = z__1.i; } else { d_cnjg(&z__2, &a[j + k * a_dim1]); z__1.r = alpha->r * z__2.r - alpha->i * z__2.i, z__1.i = alpha->r * z__2.i + alpha->i * z__2.r; temp.r = z__1.r, temp.i = z__1.i; } i__3 = *m; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = i__ + j * b_dim1; i__5 = i__ + j * b_dim1; i__6 = i__ + k * b_dim1; z__2.r = temp.r * b[i__6].r - temp.i * b[i__6] .i, z__2.i = temp.r * b[i__6].i + temp.i * b[i__6].r; z__1.r = b[i__5].r + z__2.r, z__1.i = b[i__5] .i + z__2.i; b[i__4].r = z__1.r, b[i__4].i = z__1.i; /* L250: */ } } /* L260: */ } temp.r = alpha->r, temp.i = alpha->i; if (nounit) { if (noconj) { i__2 = k + k * a_dim1; z__1.r = temp.r * a[i__2].r - temp.i * a[i__2].i, z__1.i = temp.r * a[i__2].i + temp.i * a[ i__2].r; temp.r = z__1.r, temp.i = z__1.i; } else { d_cnjg(&z__2, &a[k + k * a_dim1]); z__1.r = temp.r * z__2.r - temp.i * z__2.i, z__1.i = temp.r * z__2.i + temp.i * z__2.r; temp.r = z__1.r, temp.i = z__1.i; } } if (temp.r != 1. || temp.i != 0.) { i__2 = *m; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__ + k * b_dim1; i__4 = i__ + k * b_dim1; z__1.r = temp.r * b[i__4].r - temp.i * b[i__4].i, z__1.i = temp.r * b[i__4].i + temp.i * b[ i__4].r; b[i__3].r = z__1.r, b[i__3].i = z__1.i; /* L270: */ } } /* L280: */ } } else { for (k = *n; k >= 1; --k) { i__1 = *n; for (j = k + 1; j <= i__1; ++j) { i__2 = j + k * a_dim1; if (a[i__2].r != 0. || a[i__2].i != 0.) { if (noconj) { i__2 = j + k * a_dim1; z__1.r = alpha->r * a[i__2].r - alpha->i * a[ i__2].i, z__1.i = alpha->r * a[i__2] .i + alpha->i * a[i__2].r; temp.r = z__1.r, temp.i = z__1.i; } else { d_cnjg(&z__2, &a[j + k * a_dim1]); z__1.r = alpha->r * z__2.r - alpha->i * z__2.i, z__1.i = alpha->r * z__2.i + alpha->i * z__2.r; temp.r = z__1.r, temp.i = z__1.i; } i__2 = *m; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__ + j * b_dim1; i__4 = i__ + j * b_dim1; i__5 = i__ + k * b_dim1; z__2.r = temp.r * b[i__5].r - temp.i * b[i__5] .i, z__2.i = temp.r * b[i__5].i + temp.i * b[i__5].r; z__1.r = b[i__4].r + z__2.r, z__1.i = b[i__4] .i + z__2.i; b[i__3].r = z__1.r, b[i__3].i = z__1.i; /* L290: */ } } /* L300: */ } temp.r = alpha->r, temp.i = alpha->i; if (nounit) { if (noconj) { i__1 = k + k * a_dim1; z__1.r = temp.r * a[i__1].r - temp.i * a[i__1].i, z__1.i = temp.r * a[i__1].i + temp.i * a[ i__1].r; temp.r = z__1.r, temp.i = z__1.i; } else { d_cnjg(&z__2, &a[k + k * a_dim1]); z__1.r = temp.r * z__2.r - temp.i * z__2.i, z__1.i = temp.r * z__2.i + temp.i * z__2.r; temp.r = z__1.r, temp.i = z__1.i; } } if (temp.r != 1. || temp.i != 0.) { i__1 = *m; for (i__ = 1; i__ <= i__1; ++i__) { i__2 = i__ + k * b_dim1; i__3 = i__ + k * b_dim1; z__1.r = temp.r * b[i__3].r - temp.i * b[i__3].i, z__1.i = temp.r * b[i__3].i + temp.i * b[ i__3].r; b[i__2].r = z__1.r, b[i__2].i = z__1.i; /* L310: */ } } /* L320: */ } } } } return 0; /* End of ZTRMM . */ } /* ztrmm_ */