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