1 SUBROUTINE CQRT02( M, N, K, A, AF, Q, R, 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 A( LDA, * ), AF( LDA, * ), Q( LDA, * ),
14 $ R( LDA, * ), TAU( * ), WORK( LWORK )
15 * ..
16 *
17 * Purpose
18 * =======
19 *
20 * CQRT02 tests CUNGQR, which generates an m-by-n matrix Q with
21 * orthonornmal columns that is defined as the product of k elementary
22 * reflectors.
23 *
24 * Given the QR factorization of an m-by-n matrix A, CQRT02 generates
25 * the orthogonal matrix Q defined by the factorization of the first k
26 * columns of A; it compares R(1:n,1:k) with Q(1:m,1:n)'*A(1:m,1:k),
27 * and checks that the columns of Q are orthonormal.
28 *
29 * Arguments
30 * =========
31 *
32 * M (input) INTEGER
33 * The number of rows of the matrix Q to be generated. M >= 0.
34 *
35 * N (input) INTEGER
36 * The number of columns of the matrix Q to be generated.
37 * M >= N >= 0.
38 *
39 * K (input) INTEGER
40 * The number of elementary reflectors whose product defines the
41 * matrix Q. N >= K >= 0.
42 *
43 * A (input) COMPLEX array, dimension (LDA,N)
44 * The m-by-n matrix A which was factorized by CQRT01.
45 *
46 * AF (input) COMPLEX array, dimension (LDA,N)
47 * Details of the QR factorization of A, as returned by CGEQRF.
48 * See CGEQRF for further details.
49 *
50 * Q (workspace) COMPLEX array, dimension (LDA,N)
51 *
52 * R (workspace) COMPLEX array, dimension (LDA,N)
53 *
54 * LDA (input) INTEGER
55 * The leading dimension of the arrays A, AF, Q and R. LDA >= M.
56 *
57 * TAU (input) COMPLEX array, dimension (N)
58 * The scalar factors of the elementary reflectors corresponding
59 * to the QR factorization in AF.
60 *
61 * WORK (workspace) COMPLEX array, dimension (LWORK)
62 *
63 * LWORK (input) INTEGER
64 * The dimension of the array WORK.
65 *
66 * RWORK (workspace) REAL array, dimension (M)
67 *
68 * RESULT (output) REAL array, dimension (2)
69 * The test ratios:
70 * RESULT(1) = norm( R - Q'*A ) / ( M * norm(A) * EPS )
71 * RESULT(2) = norm( I - Q'*Q ) / ( M * EPS )
72 *
73 * =====================================================================
74 *
75 * .. Parameters ..
76 REAL ZERO, ONE
77 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
78 COMPLEX ROGUE
79 PARAMETER ( ROGUE = ( -1.0E+10, -1.0E+10 ) )
80 * ..
81 * .. Local Scalars ..
82 INTEGER INFO
83 REAL ANORM, EPS, RESID
84 * ..
85 * .. External Functions ..
86 REAL CLANGE, CLANSY, SLAMCH
87 EXTERNAL CLANGE, CLANSY, SLAMCH
88 * ..
89 * .. External Subroutines ..
90 EXTERNAL CGEMM, CHERK, CLACPY, CLASET, CUNGQR
91 * ..
92 * .. Intrinsic Functions ..
93 INTRINSIC CMPLX, MAX, REAL
94 * ..
95 * .. Scalars in Common ..
96 CHARACTER*32 SRNAMT
97 * ..
98 * .. Common blocks ..
99 COMMON / SRNAMC / SRNAMT
100 * ..
101 * .. Executable Statements ..
102 *
103 EPS = SLAMCH( 'Epsilon' )
104 *
105 * Copy the first k columns of the factorization to the array Q
106 *
107 CALL CLASET( 'Full', M, N, ROGUE, ROGUE, Q, LDA )
108 CALL CLACPY( 'Lower', M-1, K, AF( 2, 1 ), LDA, Q( 2, 1 ), LDA )
109 *
110 * Generate the first n columns of the matrix Q
111 *
112 SRNAMT = 'CUNGQR'
113 CALL CUNGQR( M, N, K, Q, LDA, TAU, WORK, LWORK, INFO )
114 *
115 * Copy R(1:n,1:k)
116 *
117 CALL CLASET( 'Full', N, K, CMPLX( ZERO ), CMPLX( ZERO ), R, LDA )
118 CALL CLACPY( 'Upper', N, K, AF, LDA, R, LDA )
119 *
120 * Compute R(1:n,1:k) - Q(1:m,1:n)' * A(1:m,1:k)
121 *
122 CALL CGEMM( 'Conjugate transpose', 'No transpose', N, K, M,
123 $ CMPLX( -ONE ), Q, LDA, A, LDA, CMPLX( ONE ), R, LDA )
124 *
125 * Compute norm( R - Q'*A ) / ( M * norm(A) * EPS ) .
126 *
127 ANORM = CLANGE( '1', M, K, A, LDA, RWORK )
128 RESID = CLANGE( '1', N, K, R, LDA, RWORK )
129 IF( ANORM.GT.ZERO ) THEN
130 RESULT( 1 ) = ( ( RESID / REAL( MAX( 1, M ) ) ) / ANORM ) / EPS
131 ELSE
132 RESULT( 1 ) = ZERO
133 END IF
134 *
135 * Compute I - Q'*Q
136 *
137 CALL CLASET( 'Full', N, N, CMPLX( ZERO ), CMPLX( ONE ), R, LDA )
138 CALL CHERK( 'Upper', 'Conjugate transpose', N, M, -ONE, Q, LDA,
139 $ ONE, R, LDA )
140 *
141 * Compute norm( I - Q'*Q ) / ( M * EPS ) .
142 *
143 RESID = CLANSY( '1', 'Upper', N, R, LDA, RWORK )
144 *
145 RESULT( 2 ) = ( RESID / REAL( MAX( 1, M ) ) ) / EPS
146 *
147 RETURN
148 *
149 * End of CQRT02
150 *
151 END
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 A( LDA, * ), AF( LDA, * ), Q( LDA, * ),
14 $ R( LDA, * ), TAU( * ), WORK( LWORK )
15 * ..
16 *
17 * Purpose
18 * =======
19 *
20 * CQRT02 tests CUNGQR, which generates an m-by-n matrix Q with
21 * orthonornmal columns that is defined as the product of k elementary
22 * reflectors.
23 *
24 * Given the QR factorization of an m-by-n matrix A, CQRT02 generates
25 * the orthogonal matrix Q defined by the factorization of the first k
26 * columns of A; it compares R(1:n,1:k) with Q(1:m,1:n)'*A(1:m,1:k),
27 * and checks that the columns of Q are orthonormal.
28 *
29 * Arguments
30 * =========
31 *
32 * M (input) INTEGER
33 * The number of rows of the matrix Q to be generated. M >= 0.
34 *
35 * N (input) INTEGER
36 * The number of columns of the matrix Q to be generated.
37 * M >= N >= 0.
38 *
39 * K (input) INTEGER
40 * The number of elementary reflectors whose product defines the
41 * matrix Q. N >= K >= 0.
42 *
43 * A (input) COMPLEX array, dimension (LDA,N)
44 * The m-by-n matrix A which was factorized by CQRT01.
45 *
46 * AF (input) COMPLEX array, dimension (LDA,N)
47 * Details of the QR factorization of A, as returned by CGEQRF.
48 * See CGEQRF for further details.
49 *
50 * Q (workspace) COMPLEX array, dimension (LDA,N)
51 *
52 * R (workspace) COMPLEX array, dimension (LDA,N)
53 *
54 * LDA (input) INTEGER
55 * The leading dimension of the arrays A, AF, Q and R. LDA >= M.
56 *
57 * TAU (input) COMPLEX array, dimension (N)
58 * The scalar factors of the elementary reflectors corresponding
59 * to the QR factorization in AF.
60 *
61 * WORK (workspace) COMPLEX array, dimension (LWORK)
62 *
63 * LWORK (input) INTEGER
64 * The dimension of the array WORK.
65 *
66 * RWORK (workspace) REAL array, dimension (M)
67 *
68 * RESULT (output) REAL array, dimension (2)
69 * The test ratios:
70 * RESULT(1) = norm( R - Q'*A ) / ( M * norm(A) * EPS )
71 * RESULT(2) = norm( I - Q'*Q ) / ( M * EPS )
72 *
73 * =====================================================================
74 *
75 * .. Parameters ..
76 REAL ZERO, ONE
77 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
78 COMPLEX ROGUE
79 PARAMETER ( ROGUE = ( -1.0E+10, -1.0E+10 ) )
80 * ..
81 * .. Local Scalars ..
82 INTEGER INFO
83 REAL ANORM, EPS, RESID
84 * ..
85 * .. External Functions ..
86 REAL CLANGE, CLANSY, SLAMCH
87 EXTERNAL CLANGE, CLANSY, SLAMCH
88 * ..
89 * .. External Subroutines ..
90 EXTERNAL CGEMM, CHERK, CLACPY, CLASET, CUNGQR
91 * ..
92 * .. Intrinsic Functions ..
93 INTRINSIC CMPLX, MAX, REAL
94 * ..
95 * .. Scalars in Common ..
96 CHARACTER*32 SRNAMT
97 * ..
98 * .. Common blocks ..
99 COMMON / SRNAMC / SRNAMT
100 * ..
101 * .. Executable Statements ..
102 *
103 EPS = SLAMCH( 'Epsilon' )
104 *
105 * Copy the first k columns of the factorization to the array Q
106 *
107 CALL CLASET( 'Full', M, N, ROGUE, ROGUE, Q, LDA )
108 CALL CLACPY( 'Lower', M-1, K, AF( 2, 1 ), LDA, Q( 2, 1 ), LDA )
109 *
110 * Generate the first n columns of the matrix Q
111 *
112 SRNAMT = 'CUNGQR'
113 CALL CUNGQR( M, N, K, Q, LDA, TAU, WORK, LWORK, INFO )
114 *
115 * Copy R(1:n,1:k)
116 *
117 CALL CLASET( 'Full', N, K, CMPLX( ZERO ), CMPLX( ZERO ), R, LDA )
118 CALL CLACPY( 'Upper', N, K, AF, LDA, R, LDA )
119 *
120 * Compute R(1:n,1:k) - Q(1:m,1:n)' * A(1:m,1:k)
121 *
122 CALL CGEMM( 'Conjugate transpose', 'No transpose', N, K, M,
123 $ CMPLX( -ONE ), Q, LDA, A, LDA, CMPLX( ONE ), R, LDA )
124 *
125 * Compute norm( R - Q'*A ) / ( M * norm(A) * EPS ) .
126 *
127 ANORM = CLANGE( '1', M, K, A, LDA, RWORK )
128 RESID = CLANGE( '1', N, K, R, LDA, RWORK )
129 IF( ANORM.GT.ZERO ) THEN
130 RESULT( 1 ) = ( ( RESID / REAL( MAX( 1, M ) ) ) / ANORM ) / EPS
131 ELSE
132 RESULT( 1 ) = ZERO
133 END IF
134 *
135 * Compute I - Q'*Q
136 *
137 CALL CLASET( 'Full', N, N, CMPLX( ZERO ), CMPLX( ONE ), R, LDA )
138 CALL CHERK( 'Upper', 'Conjugate transpose', N, M, -ONE, Q, LDA,
139 $ ONE, R, LDA )
140 *
141 * Compute norm( I - Q'*Q ) / ( M * EPS ) .
142 *
143 RESID = CLANSY( '1', 'Upper', N, R, LDA, RWORK )
144 *
145 RESULT( 2 ) = ( RESID / REAL( MAX( 1, M ) ) ) / EPS
146 *
147 RETURN
148 *
149 * End of CQRT02
150 *
151 END