1       SUBROUTINE CHET22( ITYPE, UPLO, N, M, KBAND, A, LDA, D, E, U, LDU,
  2      $                   V, LDV, TAU, WORK, RWORK, RESULT )
  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          UPLO
 10       INTEGER            ITYPE, KBAND, LDA, LDU, LDV, M, N
 11 *     ..
 12 *     .. Array Arguments ..
 13       REAL               D( * ), E( * ), RESULT2 ), RWORK( * )
 14       COMPLEX            A( LDA, * ), TAU( * ), U( LDU, * ),
 15      $                   V( LDV, * ), WORK( * )
 16 *     ..
 17 *
 18 *  Purpose
 19 *  =======
 20 *
 21 *       CHET22  generally checks a decomposition of the form
 22 *
 23 *               A U = U S
 24 *
 25 *       where A is complex Hermitian, the columns of U are orthonormal,
 26 *       and S is diagonal (if KBAND=0) or symmetric tridiagonal (if
 27 *       KBAND=1).  If ITYPE=1, then U is represented as a dense matrix,
 28 *       otherwise the U is expressed as a product of Householder
 29 *       transformations, whose vectors are stored in the array "V" and
 30 *       whose scaling constants are in "TAU"; we shall use the letter
 31 *       "V" to refer to the product of Householder transformations
 32 *       (which should be equal to U).
 33 *
 34 *       Specifically, if ITYPE=1, then:
 35 *
 36 *               RESULT(1) = | U' A U - S | / ( |A| m ulp ) *and*
 37 *               RESULT(2) = | I - U'U | / ( m ulp )
 38 *
 39 *  Arguments
 40 *  =========
 41 *
 42 *  ITYPE   INTEGER
 43 *          Specifies the type of tests to be performed.
 44 *          1: U expressed as a dense orthogonal matrix:
 45 *             RESULT(1) = | A - U S U' | / ( |A| n ulp )   *and*
 46 *             RESULT(2) = | I - UU' | / ( n ulp )
 47 *
 48 *  UPLO    CHARACTER
 49 *          If UPLO='U', the upper triangle of A will be used and the
 50 *          (strictly) lower triangle will not be referenced.  If
 51 *          UPLO='L', the lower triangle of A will be used and the
 52 *          (strictly) upper triangle will not be referenced.
 53 *          Not modified.
 54 *
 55 *  N       INTEGER
 56 *          The size of the matrix.  If it is zero, CHET22 does nothing.
 57 *          It must be at least zero.
 58 *          Not modified.
 59 *
 60 *  M       INTEGER
 61 *          The number of columns of U.  If it is zero, CHET22 does
 62 *          nothing.  It must be at least zero.
 63 *          Not modified.
 64 *
 65 *  KBAND   INTEGER
 66 *          The bandwidth of the matrix.  It may only be zero or one.
 67 *          If zero, then S is diagonal, and E is not referenced.  If
 68 *          one, then S is symmetric tri-diagonal.
 69 *          Not modified.
 70 *
 71 *  A       COMPLEX array, dimension (LDA , N)
 72 *          The original (unfactored) matrix.  It is assumed to be
 73 *          symmetric, and only the upper (UPLO='U') or only the lower
 74 *          (UPLO='L') will be referenced.
 75 *          Not modified.
 76 *
 77 *  LDA     INTEGER
 78 *          The leading dimension of A.  It must be at least 1
 79 *          and at least N.
 80 *          Not modified.
 81 *
 82 *  D       REAL array, dimension (N)
 83 *          The diagonal of the (symmetric tri-) diagonal matrix.
 84 *          Not modified.
 85 *
 86 *  E       REAL array, dimension (N)
 87 *          The off-diagonal of the (symmetric tri-) diagonal matrix.
 88 *          E(1) is ignored, E(2) is the (1,2) and (2,1) element, etc.
 89 *          Not referenced if KBAND=0.
 90 *          Not modified.
 91 *
 92 *  U       COMPLEX array, dimension (LDU, N)
 93 *          If ITYPE=1, this contains the orthogonal matrix in
 94 *          the decomposition, expressed as a dense matrix.
 95 *          Not modified.
 96 *
 97 *  LDU     INTEGER
 98 *          The leading dimension of U.  LDU must be at least N and
 99 *          at least 1.
100 *          Not modified.
101 *
102 *  V       COMPLEX array, dimension (LDV, N)
103 *          If ITYPE=2 or 3, the lower triangle of this array contains
104 *          the Householder vectors used to describe the orthogonal
105 *          matrix in the decomposition.  If ITYPE=1, then it is not
106 *          referenced.
107 *          Not modified.
108 *
109 *  LDV     INTEGER
110 *          The leading dimension of V.  LDV must be at least N and
111 *          at least 1.
112 *          Not modified.
113 *
114 *  TAU     COMPLEX array, dimension (N)
115 *          If ITYPE >= 2, then TAU(j) is the scalar factor of
116 *          v(j) v(j)' in the Householder transformation H(j) of
117 *          the product  U = H(1)...H(n-2)
118 *          If ITYPE < 2, then TAU is not referenced.
119 *          Not modified.
120 *
121 *  WORK    COMPLEX array, dimension (2*N**2)
122 *          Workspace.
123 *          Modified.
124 *
125 *  RWORK   REAL array, dimension (N)
126 *          Workspace.
127 *          Modified.
128 *
129 *  RESULT  REAL array, dimension (2)
130 *          The values computed by the two tests described above.  The
131 *          values are currently limited to 1/ulp, to avoid overflow.
132 *          RESULT(1) is always modified.  RESULT(2) is modified only
133 *          if LDU is at least N.
134 *          Modified.
135 *
136 *  =====================================================================
137 *
138 *     .. Parameters ..
139       REAL               ZERO, ONE
140       PARAMETER          ( ZERO = 0.0E0, ONE = 1.0E0 )
141       COMPLEX            CZERO, CONE
142       PARAMETER          ( CZERO = ( 0.0E00.0E0 ),
143      $                   CONE = ( 1.0E00.0E0 ) )
144 *     ..
145 *     .. Local Scalars ..
146       INTEGER            J, JJ, JJ1, JJ2, NN, NNP1
147       REAL               ANORM, ULP, UNFL, WNORM
148 *     ..
149 *     .. External Functions ..
150       REAL               CLANHE, SLAMCH
151       EXTERNAL           CLANHE, SLAMCH
152 *     ..
153 *     .. External Subroutines ..
154       EXTERNAL           CGEMM, CHEMM
155 *     ..
156 *     .. Intrinsic Functions ..
157       INTRINSIC          MAXMIN, REAL
158 *     ..
159 *     .. Executable Statements ..
160 *
161       RESULT1 ) = ZERO
162       RESULT2 ) = ZERO
163       IF( N.LE.0 .OR. M.LE.0 )
164      $   RETURN
165 *
166       UNFL = SLAMCH( 'Safe minimum' )
167       ULP = SLAMCH( 'Precision' )
168 *
169 *     Do Test 1
170 *
171 *     Norm of A:
172 *
173       ANORM = MAX( CLANHE( '1', UPLO, N, A, LDA, RWORK ), UNFL )
174 *
175 *     Compute error matrix:
176 *
177 *     ITYPE=1: error = U' A U - S
178 *
179       CALL CHEMM( 'L', UPLO, N, M, CONE, A, LDA, U, LDU, CZERO, WORK,
180      $            N )
181       NN = N*N
182       NNP1 = NN + 1
183       CALL CGEMM( 'C''N', M, M, N, CONE, U, LDU, WORK, N, CZERO,
184      $            WORK( NNP1 ), N )
185       DO 10 J = 1, M
186          JJ = NN + ( J-1 )*+ J
187          WORK( JJ ) = WORK( JJ ) - D( J )
188    10 CONTINUE
189       IF( KBAND.EQ.1 .AND. N.GT.1 ) THEN
190          DO 20 J = 2, M
191             JJ1 = NN + ( J-1 )*+ J - 1
192             JJ2 = NN + ( J-2 )*+ J
193             WORK( JJ1 ) = WORK( JJ1 ) - E( J-1 )
194             WORK( JJ2 ) = WORK( JJ2 ) - E( J-1 )
195    20    CONTINUE
196       END IF
197       WNORM = CLANHE( '1', UPLO, M, WORK( NNP1 ), N, RWORK )
198 *
199       IF( ANORM.GT.WNORM ) THEN
200          RESULT1 ) = ( WNORM / ANORM ) / ( M*ULP )
201       ELSE
202          IF( ANORM.LT.ONE ) THEN
203             RESULT1 ) = ( MIN( WNORM, M*ANORM ) / ANORM ) / ( M*ULP )
204          ELSE
205             RESULT1 ) = MIN( WNORM / ANORM, REAL( M ) ) / ( M*ULP )
206          END IF
207       END IF
208 *
209 *     Do Test 2
210 *
211 *     Compute  U'U - I
212 *
213       IF( ITYPE.EQ.1 )
214      $   CALL CUNT01( 'Columns', N, M, U, LDU, WORK, 2*N*N, RWORK,
215      $                RESULT2 ) )
216 *
217       RETURN
218 *
219 *     End of CHET22
220 *
221       END