dtrt03.c
Go to the documentation of this file.
00001 /* dtrt03.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__1 = 1;
00019 
00020 /* Subroutine */ int dtrt03_(char *uplo, char *trans, char *diag, integer *n, 
00021         integer *nrhs, doublereal *a, integer *lda, doublereal *scale, 
00022         doublereal *cnorm, doublereal *tscal, doublereal *x, integer *ldx, 
00023         doublereal *b, integer *ldb, doublereal *work, doublereal *resid)
00024 {
00025     /* System generated locals */
00026     integer a_dim1, a_offset, b_dim1, b_offset, x_dim1, x_offset, i__1;
00027     doublereal d__1, d__2, d__3;
00028 
00029     /* Local variables */
00030     integer j, ix;
00031     doublereal eps, err;
00032     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00033             integer *);
00034     extern logical lsame_(char *, char *);
00035     doublereal xscal;
00036     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00037             doublereal *, integer *), daxpy_(integer *, doublereal *, 
00038             doublereal *, integer *, doublereal *, integer *), dtrmv_(char *, 
00039             char *, char *, integer *, doublereal *, integer *, doublereal *, 
00040             integer *);
00041     doublereal tnorm, xnorm;
00042     extern /* Subroutine */ int dlabad_(doublereal *, doublereal *);
00043     extern doublereal dlamch_(char *);
00044     extern integer idamax_(integer *, doublereal *, integer *);
00045     doublereal bignum, smlnum;
00046 
00047 
00048 /*  -- LAPACK test routine (version 3.1) -- */
00049 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00050 /*     November 2006 */
00051 
00052 /*     .. Scalar Arguments .. */
00053 /*     .. */
00054 /*     .. Array Arguments .. */
00055 /*     .. */
00056 
00057 /*  Purpose */
00058 /*  ======= */
00059 
00060 /*  DTRT03 computes the residual for the solution to a scaled triangular */
00061 /*  system of equations A*x = s*b  or  A'*x = s*b. */
00062 /*  Here A is a triangular matrix, A' is the transpose of A, s is a */
00063 /*  scalar, and x and b are N by NRHS matrices.  The test ratio is the */
00064 /*  maximum over the number of right hand sides of */
00065 /*     norm(s*b - op(A)*x) / ( norm(op(A)) * norm(x) * EPS ), */
00066 /*  where op(A) denotes A or A' and EPS is the machine epsilon. */
00067 
00068 /*  Arguments */
00069 /*  ========= */
00070 
00071 /*  UPLO    (input) CHARACTER*1 */
00072 /*          Specifies whether the matrix A is upper or lower triangular. */
00073 /*          = 'U':  Upper triangular */
00074 /*          = 'L':  Lower triangular */
00075 
00076 /*  TRANS   (input) CHARACTER*1 */
00077 /*          Specifies the operation applied to A. */
00078 /*          = 'N':  A *x = s*b  (No transpose) */
00079 /*          = 'T':  A'*x = s*b  (Transpose) */
00080 /*          = 'C':  A'*x = s*b  (Conjugate transpose = Transpose) */
00081 
00082 /*  DIAG    (input) CHARACTER*1 */
00083 /*          Specifies whether or not the matrix A is unit triangular. */
00084 /*          = 'N':  Non-unit triangular */
00085 /*          = 'U':  Unit triangular */
00086 
00087 /*  N       (input) INTEGER */
00088 /*          The order of the matrix A.  N >= 0. */
00089 
00090 /*  NRHS    (input) INTEGER */
00091 /*          The number of right hand sides, i.e., the number of columns */
00092 /*          of the matrices X and B.  NRHS >= 0. */
00093 
00094 /*  A       (input) DOUBLE PRECISION array, dimension (LDA,N) */
00095 /*          The triangular matrix A.  If UPLO = 'U', the leading n by n */
00096 /*          upper triangular part of the array A contains the upper */
00097 /*          triangular matrix, and the strictly lower triangular part of */
00098 /*          A is not referenced.  If UPLO = 'L', the leading n by n lower */
00099 /*          triangular part of the array A contains the lower triangular */
00100 /*          matrix, and the strictly upper triangular part of A is not */
00101 /*          referenced.  If DIAG = 'U', the diagonal elements of A are */
00102 /*          also not referenced and are assumed to be 1. */
00103 
00104 /*  LDA     (input) INTEGER */
00105 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00106 
00107 /*  SCALE   (input) DOUBLE PRECISION */
00108 /*          The scaling factor s used in solving the triangular system. */
00109 
00110 /*  CNORM   (input) DOUBLE PRECISION array, dimension (N) */
00111 /*          The 1-norms of the columns of A, not counting the diagonal. */
00112 
00113 /*  TSCAL   (input) DOUBLE PRECISION */
00114 /*          The scaling factor used in computing the 1-norms in CNORM. */
00115 /*          CNORM actually contains the column norms of TSCAL*A. */
00116 
00117 /*  X       (input) DOUBLE PRECISION array, dimension (LDX,NRHS) */
00118 /*          The computed solution vectors for the system of linear */
00119 /*          equations. */
00120 
00121 /*  LDX     (input) INTEGER */
00122 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00123 
00124 /*  B       (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
00125 /*          The right hand side vectors for the system of linear */
00126 /*          equations. */
00127 
00128 /*  LDB     (input) INTEGER */
00129 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00130 
00131 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (N) */
00132 
00133 /*  RESID   (output) DOUBLE PRECISION */
00134 /*          The maximum over the number of right hand sides of */
00135 /*          norm(op(A)*x - s*b) / ( norm(op(A)) * norm(x) * EPS ). */
00136 
00137 /*  ===================================================================== */
00138 
00139 /*     .. Parameters .. */
00140 /*     .. */
00141 /*     .. Local Scalars .. */
00142 /*     .. */
00143 /*     .. External Functions .. */
00144 /*     .. */
00145 /*     .. External Subroutines .. */
00146 /*     .. */
00147 /*     .. Intrinsic Functions .. */
00148 /*     .. */
00149 /*     .. Executable Statements .. */
00150 
00151 /*     Quick exit if N = 0 */
00152 
00153     /* Parameter adjustments */
00154     a_dim1 = *lda;
00155     a_offset = 1 + a_dim1;
00156     a -= a_offset;
00157     --cnorm;
00158     x_dim1 = *ldx;
00159     x_offset = 1 + x_dim1;
00160     x -= x_offset;
00161     b_dim1 = *ldb;
00162     b_offset = 1 + b_dim1;
00163     b -= b_offset;
00164     --work;
00165 
00166     /* Function Body */
00167     if (*n <= 0 || *nrhs <= 0) {
00168         *resid = 0.;
00169         return 0;
00170     }
00171     eps = dlamch_("Epsilon");
00172     smlnum = dlamch_("Safe minimum");
00173     bignum = 1. / smlnum;
00174     dlabad_(&smlnum, &bignum);
00175 
00176 /*     Compute the norm of the triangular matrix A using the column */
00177 /*     norms already computed by DLATRS. */
00178 
00179     tnorm = 0.;
00180     if (lsame_(diag, "N")) {
00181         i__1 = *n;
00182         for (j = 1; j <= i__1; ++j) {
00183 /* Computing MAX */
00184             d__2 = tnorm, d__3 = *tscal * (d__1 = a[j + j * a_dim1], abs(d__1)
00185                     ) + cnorm[j];
00186             tnorm = max(d__2,d__3);
00187 /* L10: */
00188         }
00189     } else {
00190         i__1 = *n;
00191         for (j = 1; j <= i__1; ++j) {
00192 /* Computing MAX */
00193             d__1 = tnorm, d__2 = *tscal + cnorm[j];
00194             tnorm = max(d__1,d__2);
00195 /* L20: */
00196         }
00197     }
00198 
00199 /*     Compute the maximum over the number of right hand sides of */
00200 /*        norm(op(A)*x - s*b) / ( norm(op(A)) * norm(x) * EPS ). */
00201 
00202     *resid = 0.;
00203     i__1 = *nrhs;
00204     for (j = 1; j <= i__1; ++j) {
00205         dcopy_(n, &x[j * x_dim1 + 1], &c__1, &work[1], &c__1);
00206         ix = idamax_(n, &work[1], &c__1);
00207 /* Computing MAX */
00208         d__2 = 1., d__3 = (d__1 = x[ix + j * x_dim1], abs(d__1));
00209         xnorm = max(d__2,d__3);
00210         xscal = 1. / xnorm / (doublereal) (*n);
00211         dscal_(n, &xscal, &work[1], &c__1);
00212         dtrmv_(uplo, trans, diag, n, &a[a_offset], lda, &work[1], &c__1);
00213         d__1 = -(*scale) * xscal;
00214         daxpy_(n, &d__1, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1);
00215         ix = idamax_(n, &work[1], &c__1);
00216         err = *tscal * (d__1 = work[ix], abs(d__1));
00217         ix = idamax_(n, &x[j * x_dim1 + 1], &c__1);
00218         xnorm = (d__1 = x[ix + j * x_dim1], abs(d__1));
00219         if (err * smlnum <= xnorm) {
00220             if (xnorm > 0.) {
00221                 err /= xnorm;
00222             }
00223         } else {
00224             if (err > 0.) {
00225                 err = 1. / eps;
00226             }
00227         }
00228         if (err * smlnum <= tnorm) {
00229             if (tnorm > 0.) {
00230                 err /= tnorm;
00231             }
00232         } else {
00233             if (err > 0.) {
00234                 err = 1. / eps;
00235             }
00236         }
00237         *resid = max(*resid,err);
00238 /* L30: */
00239     }
00240 
00241     return 0;
00242 
00243 /*     End of DTRT03 */
00244 
00245 } /* dtrt03_ */


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