1       SUBROUTINE SQRT03( 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               AF( LDA, * ), C( LDA, * ), CC( LDA, * ),
 13      $                   Q( LDA, * ), RESULT* ), RWORK( * ), TAU( * ),
 14      $                   WORK( LWORK )
 15 *     ..
 16 *
 17 *  Purpose
 18 *  =======
 19 *
 20 *  SQRT03 tests SORMQR, which computes Q*C, Q'*C, C*Q or C*Q'.
 21 *
 22 *  SQRT03 compares the results of a call to SORMQR with the results of
 23 *  forming Q explicitly by a call to SORGQR and then performing matrix
 24 *  multiplication by a call to SGEMM.
 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) REAL array, dimension (LDA,N)
 42 *          Details of the QR factorization of an m-by-n matrix, as
 43 *          returnedby SGEQRF. See SGEQRF for further details.
 44 *
 45 *  C       (workspace) REAL array, dimension (LDA,N)
 46 *
 47 *  CC      (workspace) REAL array, dimension (LDA,N)
 48 *
 49 *  Q       (workspace) REAL 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) REAL array, dimension (min(M,N))
 55 *          The scalar factors of the elementary reflectors corresponding
 56 *          to the QR factorization in AF.
 57 *
 58 *  WORK    (workspace) REAL 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               ONE
 78       PARAMETER          ( ONE = 1.0E0 )
 79       REAL               ROGUE
 80       PARAMETER          ( ROGUE = -1.0E+10 )
 81 *     ..
 82 *     .. Local Scalars ..
 83       CHARACTER          SIDE, TRANS
 84       INTEGER            INFO, ISIDE, ITRANS, J, MC, NC
 85       REAL               CNORM, EPS, RESID
 86 *     ..
 87 *     .. External Functions ..
 88       LOGICAL            LSAME
 89       REAL               SLAMCH, SLANGE
 90       EXTERNAL           LSAME, SLAMCH, SLANGE
 91 *     ..
 92 *     .. External Subroutines ..
 93       EXTERNAL           SGEMM, SLACPY, SLARNV, SLASET, SORGQR, SORMQR
 94 *     ..
 95 *     .. Local Arrays ..
 96       INTEGER            ISEED( 4 )
 97 *     ..
 98 *     .. Intrinsic Functions ..
 99       INTRINSIC          MAX, 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 *
114 *     Copy the first k columns of the factorization to the array Q
115 *
116       CALL SLASET( 'Full', M, M, ROGUE, ROGUE, Q, LDA )
117       CALL SLACPY( 'Lower', M-1, K, AF( 21 ), LDA, Q( 21 ), LDA )
118 *
119 *     Generate the m-by-m matrix Q
120 *
121       SRNAMT = 'SORGQR'
122       CALL SORGQR( M, M, K, Q, LDA, TAU, WORK, LWORK, INFO )
123 *
124       DO 30 ISIDE = 12
125          IF( ISIDE.EQ.1 ) THEN
126             SIDE = 'L'
127             MC = M
128             NC = N
129          ELSE
130             SIDE = 'R'
131             MC = N
132             NC = M
133          END IF
134 *
135 *        Generate MC by NC matrix C
136 *
137          DO 10 J = 1, NC
138             CALL SLARNV( 2, ISEED, MC, C( 1, J ) )
139    10    CONTINUE
140          CNORM = SLANGE( '1', MC, NC, C, LDA, RWORK )
141          IF( CNORM.EQ.0.0 )
142      $      CNORM = ONE
143 *
144          DO 20 ITRANS = 12
145             IF( ITRANS.EQ.1 ) THEN
146                TRANS = 'N'
147             ELSE
148                TRANS = 'T'
149             END IF
150 *
151 *           Copy C
152 *
153             CALL SLACPY( 'Full', MC, NC, C, LDA, CC, LDA )
154 *
155 *           Apply Q or Q' to C
156 *
157             SRNAMT = 'SORMQR'
158             CALL SORMQR( SIDE, TRANS, MC, NC, K, AF, LDA, TAU, CC, LDA,
159      $                   WORK, LWORK, INFO )
160 *
161 *           Form explicit product and subtract
162 *
163             IF( LSAME( SIDE, 'L' ) ) THEN
164                CALL SGEMM( TRANS, 'No transpose', MC, NC, MC, -ONE, Q,
165      $                     LDA, C, LDA, ONE, CC, LDA )
166             ELSE
167                CALL SGEMM( 'No transpose', TRANS, MC, NC, NC, -ONE, C,
168      $                     LDA, Q, LDA, ONE, CC, LDA )
169             END IF
170 *
171 *           Compute error in the difference
172 *
173             RESID = SLANGE( '1', MC, NC, CC, LDA, RWORK )
174             RESULT( ( ISIDE-1 )*2+ITRANS ) = RESID /
175      $         ( REALMAX1, M ) )*CNORM*EPS )
176 *
177    20    CONTINUE
178    30 CONTINUE
179 *
180       RETURN
181 *
182 *     End of SQRT03
183 *
184       END