1       SUBROUTINE CQLT03( M, N, K, AF, C, CC, Q, LDA, TAU, WORK, LWORK,
  2      $                   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       INTEGER            K, LDA, LWORK, M, N
 10 *     ..
 11 *     .. Array Arguments ..
 12       REAL               RESULT* ), RWORK( * )
 13       COMPLEX            AF( LDA, * ), C( LDA, * ), CC( LDA, * ),
 14      $                   Q( LDA, * ), TAU( * ), WORK( LWORK )
 15 *     ..
 16 *
 17 *  Purpose
 18 *  =======
 19 *
 20 *  CQLT03 tests CUNMQL, which computes Q*C, Q'*C, C*Q or C*Q'.
 21 *
 22 *  CQLT03 compares the results of a call to CUNMQL with the results of
 23 *  forming Q explicitly by a call to CUNGQL and then performing matrix
 24 *  multiplication by a call to CGEMM.
 25 *
 26 *  Arguments
 27 *  =========
 28 *
 29 *  M       (input) INTEGER
 30 *          The order of the orthogonal matrix Q.  M >= 0.
 31 *
 32 *  N       (input) INTEGER
 33 *          The number of rows or columns of the matrix C; C is m-by-n if
 34 *          Q is applied from the left, or n-by-m if Q is applied from
 35 *          the right.  N >= 0.
 36 *
 37 *  K       (input) INTEGER
 38 *          The number of elementary reflectors whose product defines the
 39 *          orthogonal matrix Q.  M >= K >= 0.
 40 *
 41 *  AF      (input) COMPLEX array, dimension (LDA,N)
 42 *          Details of the QL factorization of an m-by-n matrix, as
 43 *          returned by CGEQLF. See CGEQLF for further details.
 44 *
 45 *  C       (workspace) COMPLEX array, dimension (LDA,N)
 46 *
 47 *  CC      (workspace) COMPLEX array, dimension (LDA,N)
 48 *
 49 *  Q       (workspace) COMPLEX array, dimension (LDA,M)
 50 *
 51 *  LDA     (input) INTEGER
 52 *          The leading dimension of the arrays AF, C, CC, and Q.
 53 *
 54 *  TAU     (input) COMPLEX array, dimension (min(M,N))
 55 *          The scalar factors of the elementary reflectors corresponding
 56 *          to the QL factorization in AF.
 57 *
 58 *  WORK    (workspace) COMPLEX array, dimension (LWORK)
 59 *
 60 *  LWORK   (input) INTEGER
 61 *          The length of WORK.  LWORK must be at least M, and should be
 62 *          M*NB, where NB is the blocksize for this environment.
 63 *
 64 *  RWORK   (workspace) REAL array, dimension (M)
 65 *
 66 *  RESULT  (output) REAL array, dimension (4)
 67 *          The test ratios compare two techniques for multiplying a
 68 *          random matrix C by an m-by-m orthogonal matrix Q.
 69 *          RESULT(1) = norm( Q*C - Q*C )  / ( M * norm(C) * EPS )
 70 *          RESULT(2) = norm( C*Q - C*Q )  / ( M * norm(C) * EPS )
 71 *          RESULT(3) = norm( Q'*C - Q'*C )/ ( M * norm(C) * EPS )
 72 *          RESULT(4) = norm( C*Q' - C*Q' )/ ( M * norm(C) * EPS )
 73 *
 74 *  =====================================================================
 75 *
 76 *     .. Parameters ..
 77       REAL               ZERO, ONE
 78       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
 79       COMPLEX            ROGUE
 80       PARAMETER          ( ROGUE = ( -1.0E+10-1.0E+10 ) )
 81 *     ..
 82 *     .. Local Scalars ..
 83       CHARACTER          SIDE, TRANS
 84       INTEGER            INFO, ISIDE, ITRANS, J, MC, MINMN, NC
 85       REAL               CNORM, EPS, RESID
 86 *     ..
 87 *     .. External Functions ..
 88       LOGICAL            LSAME
 89       REAL               CLANGE, SLAMCH
 90       EXTERNAL           LSAME, CLANGE, SLAMCH
 91 *     ..
 92 *     .. External Subroutines ..
 93       EXTERNAL           CGEMM, CLACPY, CLARNV, CLASET, CUNGQL, CUNMQL
 94 *     ..
 95 *     .. Local Arrays ..
 96       INTEGER            ISEED( 4 )
 97 *     ..
 98 *     .. Intrinsic Functions ..
 99       INTRINSIC          CMPLXMAXMIN, REAL
100 *     ..
101 *     .. Scalars in Common ..
102       CHARACTER*32       SRNAMT
103 *     ..
104 *     .. Common blocks ..
105       COMMON             / SRNAMC / SRNAMT
106 *     ..
107 *     .. Data statements ..
108       DATA               ISEED / 1988198919901991 /
109 *     ..
110 *     .. Executable Statements ..
111 *
112       EPS = SLAMCH( 'Epsilon' )
113       MINMN = MIN( M, N )
114 *
115 *     Quick return if possible
116 *
117       IF( MINMN.EQ.0 ) THEN
118          RESULT1 ) = ZERO
119          RESULT2 ) = ZERO
120          RESULT3 ) = ZERO
121          RESULT4 ) = ZERO
122          RETURN
123       ENDIF
124 *
125 *     Copy the last k columns of the factorization to the array Q
126 *
127       CALL CLASET( 'Full', M, M, ROGUE, ROGUE, Q, LDA )
128       IF( K.GT.0 .AND. M.GT.K )
129      $   CALL CLACPY( 'Full', M-K, K, AF( 1, N-K+1 ), LDA,
130      $                Q( 1, M-K+1 ), LDA )
131       IF( K.GT.1 )
132      $   CALL CLACPY( 'Upper', K-1, K-1, AF( M-K+1, N-K+2 ), LDA,
133      $                Q( M-K+1, M-K+2 ), LDA )
134 *
135 *     Generate the m-by-m matrix Q
136 *
137       SRNAMT = 'CUNGQL'
138       CALL CUNGQL( M, M, K, Q, LDA, TAU( MINMN-K+1 ), WORK, LWORK,
139      $             INFO )
140 *
141       DO 30 ISIDE = 12
142          IF( ISIDE.EQ.1 ) THEN
143             SIDE = 'L'
144             MC = M
145             NC = N
146          ELSE
147             SIDE = 'R'
148             MC = N
149             NC = M
150          END IF
151 *
152 *        Generate MC by NC matrix C
153 *
154          DO 10 J = 1, NC
155             CALL CLARNV( 2, ISEED, MC, C( 1, J ) )
156    10    CONTINUE
157          CNORM = CLANGE( '1', MC, NC, C, LDA, RWORK )
158          IF( CNORM.EQ.ZERO )
159      $      CNORM = ONE
160 *
161          DO 20 ITRANS = 12
162             IF( ITRANS.EQ.1 ) THEN
163                TRANS = 'N'
164             ELSE
165                TRANS = 'C'
166             END IF
167 *
168 *           Copy C
169 *
170             CALL CLACPY( 'Full', MC, NC, C, LDA, CC, LDA )
171 *
172 *           Apply Q or Q' to C
173 *
174             SRNAMT = 'CUNMQL'
175             IF( K.GT.0 )
176      $         CALL CUNMQL( SIDE, TRANS, MC, NC, K, AF( 1, N-K+1 ),
177      $                      LDA, TAU( MINMN-K+1 ), CC, LDA, WORK,
178      $                      LWORK, INFO )
179 *
180 *           Form explicit product and subtract
181 *
182             IF( LSAME( SIDE, 'L' ) ) THEN
183                CALL CGEMM( TRANS, 'No transpose', MC, NC, MC,
184      $                     CMPLX-ONE ), Q, LDA, C, LDA, CMPLX( ONE ),
185      $                     CC, LDA )
186             ELSE
187                CALL CGEMM( 'No transpose', TRANS, MC, NC, NC,
188      $                     CMPLX-ONE ), C, LDA, Q, LDA, CMPLX( ONE ),
189      $                     CC, LDA )
190             END IF
191 *
192 *           Compute error in the difference
193 *
194             RESID = CLANGE( '1', MC, NC, CC, LDA, RWORK )
195             RESULT( ( ISIDE-1 )*2+ITRANS ) = RESID /
196      $         ( REALMAX1, M ) )*CNORM*EPS )
197 *
198    20    CONTINUE
199    30 CONTINUE
200 *
201       RETURN
202 *
203 *     End of CQLT03
204 *
205       END