1       SUBROUTINE STPT03( UPLO, TRANS, DIAG, N, NRHS, AP, SCALE, CNORM,
  2      $                   TSCAL, X, LDX, B, LDB, WORK, RESID )
  3 *
  4 *  -- LAPACK test routine (version 3.1) --
  5 *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  6 *     November 2006
  7 *
  8 *     .. Scalar Arguments ..
  9       CHARACTER          DIAG, TRANS, UPLO
 10       INTEGER            LDB, LDX, N, NRHS
 11       REAL               RESID, SCALE, TSCAL
 12 *     ..
 13 *     .. Array Arguments ..
 14       REAL               AP( * ), B( LDB, * ), CNORM( * ), WORK( * ),
 15      $                   X( LDX, * )
 16 *     ..
 17 *
 18 *  Purpose
 19 *  =======
 20 *
 21 *  STPT03 computes the residual for the solution to a scaled triangular
 22 *  system of equations A*x = s*b  or  A'*x = s*b  when the triangular
 23 *  matrix A is stored in packed format.  Here A' is the transpose of A,
 24 *  s is a scalar, and x and b are N by NRHS matrices.  The test ratio is
 25 *  the maximum over the number of right hand sides of
 26 *     norm(s*b - op(A)*x) / ( norm(op(A)) * norm(x) * EPS ),
 27 *  where op(A) denotes A or A' and EPS is the machine epsilon.
 28 *
 29 *  Arguments
 30 *  =========
 31 *
 32 *  UPLO    (input) CHARACTER*1
 33 *          Specifies whether the matrix A is upper or lower triangular.
 34 *          = 'U':  Upper triangular
 35 *          = 'L':  Lower triangular
 36 *
 37 *  TRANS   (input) CHARACTER*1
 38 *          Specifies the operation applied to A.
 39 *          = 'N':  A *x = s*b  (No transpose)
 40 *          = 'T':  A'*x = s*b  (Transpose)
 41 *          = 'C':  A'*x = s*b  (Conjugate transpose = Transpose)
 42 *
 43 *  DIAG    (input) CHARACTER*1
 44 *          Specifies whether or not the matrix A is unit triangular.
 45 *          = 'N':  Non-unit triangular
 46 *          = 'U':  Unit triangular
 47 *
 48 *  N       (input) INTEGER
 49 *          The order of the matrix A.  N >= 0.
 50 *
 51 *  NRHS    (input) INTEGER
 52 *          The number of right hand sides, i.e., the number of columns
 53 *          of the matrices X and B.  NRHS >= 0.
 54 *
 55 *  AP      (input) REAL array, dimension (N*(N+1)/2)
 56 *          The upper or lower triangular matrix A, packed columnwise in
 57 *          a linear array.  The j-th column of A is stored in the array
 58 *          AP as follows:
 59 *          if UPLO = 'U', AP((j-1)*j/2 + i) = A(i,j) for 1<=i<=j;
 60 *          if UPLO = 'L',
 61 *             AP((j-1)*(n-j) + j*(j+1)/2 + i-j) = A(i,j) for j<=i<=n.
 62 *
 63 *  SCALE   (input) REAL
 64 *          The scaling factor s used in solving the triangular system.
 65 *
 66 *  CNORM   (input) REAL array, dimension (N)
 67 *          The 1-norms of the columns of A, not counting the diagonal.
 68 *
 69 *  TSCAL   (input) REAL
 70 *          The scaling factor used in computing the 1-norms in CNORM.
 71 *          CNORM actually contains the column norms of TSCAL*A.
 72 *
 73 *  X       (input) REAL array, dimension (LDX,NRHS)
 74 *          The computed solution vectors for the system of linear
 75 *          equations.
 76 *
 77 *  LDX     (input) INTEGER
 78 *          The leading dimension of the array X.  LDX >= max(1,N).
 79 *
 80 *  B       (input) REAL array, dimension (LDB,NRHS)
 81 *          The right hand side vectors for the system of linear
 82 *          equations.
 83 *
 84 *  LDB     (input) INTEGER
 85 *          The leading dimension of the array B.  LDB >= max(1,N).
 86 *
 87 *  WORK    (workspace) REAL array, dimension (N)
 88 *
 89 *  RESID   (output) REAL
 90 *          The maximum over the number of right hand sides of
 91 *          norm(op(A)*x - s*b) / ( norm(op(A)) * norm(x) * EPS ).
 92 *
 93 *  =====================================================================
 94 *
 95 *     .. Parameters ..
 96       REAL               ONE, ZERO
 97       PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
 98 *     ..
 99 *     .. Local Scalars ..
100       INTEGER            IX, J, JJ
101       REAL               BIGNUM, EPS, ERR, SMLNUM, TNORM, XNORM, XSCAL
102 *     ..
103 *     .. External Functions ..
104       LOGICAL            LSAME
105       INTEGER            ISAMAX
106       REAL               SLAMCH
107       EXTERNAL           LSAME, ISAMAX, SLAMCH
108 *     ..
109 *     .. External Subroutines ..
110       EXTERNAL           SAXPY, SCOPY, SLABAD, SSCAL, STPMV
111 *     ..
112 *     .. Intrinsic Functions ..
113       INTRINSIC          ABSMAX, REAL
114 *     ..
115 *     .. Executable Statements ..
116 *
117 *     Quick exit if N = 0.
118 *
119       IF( N.LE.0 .OR. NRHS.LE.0 ) THEN
120          RESID = ZERO
121          RETURN
122       END IF
123       EPS = SLAMCH( 'Epsilon' )
124       SMLNUM = SLAMCH( 'Safe minimum' )
125       BIGNUM = ONE / SMLNUM
126       CALL SLABAD( SMLNUM, BIGNUM )
127 *
128 *     Compute the norm of the triangular matrix A using the column
129 *     norms already computed by SLATPS.
130 *
131       TNORM = ZERO
132       IF( LSAME( DIAG, 'N' ) ) THEN
133          IF( LSAME( UPLO, 'U' ) ) THEN
134             JJ = 1
135             DO 10 J = 1, N
136                TNORM = MAX( TNORM, TSCAL*ABS( AP( JJ ) )+CNORM( J ) )
137                JJ = JJ + J + 1
138    10       CONTINUE
139          ELSE
140             JJ = 1
141             DO 20 J = 1, N
142                TNORM = MAX( TNORM, TSCAL*ABS( AP( JJ ) )+CNORM( J ) )
143                JJ = JJ + N - J + 1
144    20       CONTINUE
145          END IF
146       ELSE
147          DO 30 J = 1, N
148             TNORM = MAX( TNORM, TSCAL+CNORM( J ) )
149    30    CONTINUE
150       END IF
151 *
152 *     Compute the maximum over the number of right hand sides of
153 *        norm(op(A)*x - s*b) / ( norm(op(A)) * norm(x) * EPS ).
154 *
155       RESID = ZERO
156       DO 40 J = 1, NRHS
157          CALL SCOPY( N, X( 1, J ), 1, WORK, 1 )
158          IX = ISAMAX( N, WORK, 1 )
159          XNORM = MAX( ONE, ABS( X( IX, J ) ) )
160          XSCAL = ( ONE / XNORM ) / REAL( N )
161          CALL SSCAL( N, XSCAL, WORK, 1 )
162          CALL STPMV( UPLO, TRANS, DIAG, N, AP, WORK, 1 )
163          CALL SAXPY( N, -SCALE*XSCAL, B( 1, J ), 1, WORK, 1 )
164          IX = ISAMAX( N, WORK, 1 )
165          ERR = TSCAL*ABS( WORK( IX ) )
166          IX = ISAMAX( N, X( 1, J ), 1 )
167          XNORM = ABS( X( IX, J ) )
168          IF( ERR*SMLNUM.LE.XNORM ) THEN
169             IF( XNORM.GT.ZERO )
170      $         ERR = ERR / XNORM
171          ELSE
172             IF( ERR.GT.ZERO )
173      $         ERR = ONE / EPS
174          END IF
175          IF( ERR*SMLNUM.LE.TNORM ) THEN
176             IF( TNORM.GT.ZERO )
177      $         ERR = ERR / TNORM
178          ELSE
179             IF( ERR.GT.ZERO )
180      $         ERR = ONE / EPS
181          END IF
182          RESID = MAX( RESID, ERR )
183    40 CONTINUE
184 *
185       RETURN
186 *
187 *     End of STPT03
188 *
189       END