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