1       SUBROUTINE STPT05( UPLO, TRANS, DIAG, N, NRHS, AP, B, LDB, X, LDX,
  2      $                   XACT, LDXACT, FERR, BERR, RESLTS )
  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, LDXACT, N, NRHS
 11 *     ..
 12 *     .. Array Arguments ..
 13       REAL               AP( * ), B( LDB, * ), BERR( * ), FERR( * ),
 14      $                   RESLTS( * ), X( LDX, * ), XACT( LDXACT, * )
 15 *     ..
 16 *
 17 *  Purpose
 18 *  =======
 19 *
 20 *  STPT05 tests the error bounds from iterative refinement for the
 21 *  computed solution to a system of equations A*X = B, where A is a
 22 *  triangular matrix in packed storage format.
 23 *
 24 *  RESLTS(1) = test of the error bound
 25 *            = norm(X - XACT) / ( norm(X) * FERR )
 26 *
 27 *  A large value is returned if this ratio is not less than one.
 28 *
 29 *  RESLTS(2) = residual from the iterative refinement routine
 30 *            = the maximum of BERR / ( (n+1)*EPS + (*) ), where
 31 *              (*) = (n+1)*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i )
 32 *
 33 *  Arguments
 34 *  =========
 35 *
 36 *  UPLO    (input) CHARACTER*1
 37 *          Specifies whether the matrix A is upper or lower triangular.
 38 *          = 'U':  Upper triangular
 39 *          = 'L':  Lower triangular
 40 *
 41 *  TRANS   (input) CHARACTER*1
 42 *          Specifies the form of the system of equations.
 43 *          = 'N':  A * X = B  (No transpose)
 44 *          = 'T':  A'* X = B  (Transpose)
 45 *          = 'C':  A'* X = B  (Conjugate transpose = Transpose)
 46 *
 47 *  DIAG    (input) CHARACTER*1
 48 *          Specifies whether or not the matrix A is unit triangular.
 49 *          = 'N':  Non-unit triangular
 50 *          = 'U':  Unit triangular
 51 *
 52 *  N       (input) INTEGER
 53 *          The number of rows of the matrices X, B, and XACT, and the
 54 *          order of the matrix A.  N >= 0.
 55 *
 56 *  NRHS    (input) INTEGER
 57 *          The number of columns of the matrices X, B, and XACT.
 58 *          NRHS >= 0.
 59 *
 60 *  AP      (input) REAL array, dimension (N*(N+1)/2)
 61 *          The upper or lower triangular matrix A, packed columnwise in
 62 *          a linear array.  The j-th column of A is stored in the array
 63 *          AP as follows:
 64 *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
 65 *          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
 66 *          If DIAG = 'U', the diagonal elements of A are not referenced
 67 *          and are assumed to be 1.
 68 *
 69 *  B       (input) REAL array, dimension (LDB,NRHS)
 70 *          The right hand side vectors for the system of linear
 71 *          equations.
 72 *
 73 *  LDB     (input) INTEGER
 74 *          The leading dimension of the array B.  LDB >= max(1,N).
 75 *
 76 *  X       (input) REAL array, dimension (LDX,NRHS)
 77 *          The computed solution vectors.  Each vector is stored as a
 78 *          column of the matrix X.
 79 *
 80 *  LDX     (input) INTEGER
 81 *          The leading dimension of the array X.  LDX >= max(1,N).
 82 *
 83 *  XACT    (input) REAL array, dimension (LDX,NRHS)
 84 *          The exact solution vectors.  Each vector is stored as a
 85 *          column of the matrix XACT.
 86 *
 87 *  LDXACT  (input) INTEGER
 88 *          The leading dimension of the array XACT.  LDXACT >= max(1,N).
 89 *
 90 *  FERR    (input) REAL array, dimension (NRHS)
 91 *          The estimated forward error bounds for each solution vector
 92 *          X.  If XTRUE is the true solution, FERR bounds the magnitude
 93 *          of the largest entry in (X - XTRUE) divided by the magnitude
 94 *          of the largest entry in X.
 95 *
 96 *  BERR    (input) REAL array, dimension (NRHS)
 97 *          The componentwise relative backward error of each solution
 98 *          vector (i.e., the smallest relative change in any entry of A
 99 *          or B that makes X an exact solution).
100 *
101 *  RESLTS  (output) REAL array, dimension (2)
102 *          The maximum over the NRHS solution vectors of the ratios:
103 *          RESLTS(1) = norm(X - XACT) / ( norm(X) * FERR )
104 *          RESLTS(2) = BERR / ( (n+1)*EPS + (*) )
105 *
106 *  =====================================================================
107 *
108 *     .. Parameters ..
109       REAL               ZERO, ONE
110       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
111 *     ..
112 *     .. Local Scalars ..
113       LOGICAL            NOTRAN, UNIT, UPPER
114       INTEGER            I, IFU, IMAX, J, JC, K
115       REAL               AXBI, DIFF, EPS, ERRBND, OVFL, TMP, UNFL, XNORM
116 *     ..
117 *     .. External Functions ..
118       LOGICAL            LSAME
119       INTEGER            ISAMAX
120       REAL               SLAMCH
121       EXTERNAL           LSAME, ISAMAX, SLAMCH
122 *     ..
123 *     .. Intrinsic Functions ..
124       INTRINSIC          ABSMAXMIN
125 *     ..
126 *     .. Executable Statements ..
127 *
128 *     Quick exit if N = 0 or NRHS = 0.
129 *
130       IF( N.LE.0 .OR. NRHS.LE.0 ) THEN
131          RESLTS( 1 ) = ZERO
132          RESLTS( 2 ) = ZERO
133          RETURN
134       END IF
135 *
136       EPS = SLAMCH( 'Epsilon' )
137       UNFL = SLAMCH( 'Safe minimum' )
138       OVFL = ONE / UNFL
139       UPPER = LSAME( UPLO, 'U' )
140       NOTRAN = LSAME( TRANS, 'N' )
141       UNIT = LSAME( DIAG, 'U' )
142 *
143 *     Test 1:  Compute the maximum of
144 *        norm(X - XACT) / ( norm(X) * FERR )
145 *     over all the vectors X and XACT using the infinity-norm.
146 *
147       ERRBND = ZERO
148       DO 30 J = 1, NRHS
149          IMAX = ISAMAX( N, X( 1, J ), 1 )
150          XNORM = MAXABS( X( IMAX, J ) ), UNFL )
151          DIFF = ZERO
152          DO 10 I = 1, N
153             DIFF = MAX( DIFF, ABS( X( I, J )-XACT( I, J ) ) )
154    10    CONTINUE
155 *
156          IF( XNORM.GT.ONE ) THEN
157             GO TO 20
158          ELSE IF( DIFF.LE.OVFL*XNORM ) THEN
159             GO TO 20
160          ELSE
161             ERRBND = ONE / EPS
162             GO TO 30
163          END IF
164 *
165    20    CONTINUE
166          IF( DIFF / XNORM.LE.FERR( J ) ) THEN
167             ERRBND = MAX( ERRBND, ( DIFF / XNORM ) / FERR( J ) )
168          ELSE
169             ERRBND = ONE / EPS
170          END IF
171    30 CONTINUE
172       RESLTS( 1 ) = ERRBND
173 *
174 *     Test 2:  Compute the maximum of BERR / ( (n+1)*EPS + (*) ), where
175 *     (*) = (n+1)*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i )
176 *
177       IFU = 0
178       IFUNIT )
179      $   IFU = 1
180       DO 90 K = 1, NRHS
181          DO 80 I = 1, N
182             TMP = ABS( B( I, K ) )
183             IF( UPPER ) THEN
184                JC = ( ( I-1 )*I ) / 2
185                IF.NOT.NOTRAN ) THEN
186                   DO 40 J = 1, I - IFU
187                      TMP = TMP + ABS( AP( JC+J ) )*ABS( X( J, K ) )
188    40             CONTINUE
189                   IFUNIT )
190      $               TMP = TMP + ABS( X( I, K ) )
191                ELSE
192                   JC = JC + I
193                   IFUNIT ) THEN
194                      TMP = TMP + ABS( X( I, K ) )
195                      JC = JC + I
196                   END IF
197                   DO 50 J = I + IFU, N
198                      TMP = TMP + ABS( AP( JC ) )*ABS( X( J, K ) )
199                      JC = JC + J
200    50             CONTINUE
201                END IF
202             ELSE
203                IF( NOTRAN ) THEN
204                   JC = I
205                   DO 60 J = 1, I - IFU
206                      TMP = TMP + ABS( AP( JC ) )*ABS( X( J, K ) )
207                      JC = JC + N - J
208    60             CONTINUE
209                   IFUNIT )
210      $               TMP = TMP + ABS( X( I, K ) )
211                ELSE
212                   JC = ( I-1 )*( N-I ) + ( I*( I+1 ) ) / 2
213                   IFUNIT )
214      $               TMP = TMP + ABS( X( I, K ) )
215                   DO 70 J = I + IFU, N
216                      TMP = TMP + ABS( AP( JC+J-I ) )*ABS( X( J, K ) )
217    70             CONTINUE
218                END IF
219             END IF
220             IF( I.EQ.1 ) THEN
221                AXBI = TMP
222             ELSE
223                AXBI = MIN( AXBI, TMP )
224             END IF
225    80    CONTINUE
226          TMP = BERR( K ) / ( ( N+1 )*EPS+( N+1 )*UNFL /
227      $         MAX( AXBI, ( N+1 )*UNFL ) )
228          IF( K.EQ.1 ) THEN
229             RESLTS( 2 ) = TMP
230          ELSE
231             RESLTS( 2 ) = MAX( RESLTS( 2 ), TMP )
232          END IF
233    90 CONTINUE
234 *
235       RETURN
236 *
237 *     End of STPT05
238 *
239       END