b5cdbac265f599d215b7bb0b319cf05382bd2558
[platform/upstream/lapack.git] / TESTING / LIN / cqrt01.f
1 *> \brief \b CQRT01
2 *
3 *  =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at 
6 *            http://www.netlib.org/lapack/explore-html/ 
7 *
8 *  Definition:
9 *  ===========
10 *
11 *       SUBROUTINE CQRT01( M, N, A, AF, Q, R, LDA, TAU, WORK, LWORK,
12 *                          RWORK, RESULT )
13
14 *       .. Scalar Arguments ..
15 *       INTEGER            LDA, LWORK, M, N
16 *       ..
17 *       .. Array Arguments ..
18 *       REAL               RESULT( * ), RWORK( * )
19 *       COMPLEX            A( LDA, * ), AF( LDA, * ), Q( LDA, * ),
20 *      $                   R( LDA, * ), TAU( * ), WORK( LWORK )
21 *       ..
22 *  
23 *
24 *> \par Purpose:
25 *  =============
26 *>
27 *> \verbatim
28 *>
29 *> CQRT01 tests CGEQRF, which computes the QR factorization of an m-by-n
30 *> matrix A, and partially tests CUNGQR which forms the m-by-m
31 *> orthogonal matrix Q.
32 *>
33 *> CQRT01 compares R with Q'*A, and checks that Q is orthogonal.
34 *> \endverbatim
35 *
36 *  Arguments:
37 *  ==========
38 *
39 *> \param[in] M
40 *> \verbatim
41 *>          M is INTEGER
42 *>          The number of rows of the matrix A.  M >= 0.
43 *> \endverbatim
44 *>
45 *> \param[in] N
46 *> \verbatim
47 *>          N is INTEGER
48 *>          The number of columns of the matrix A.  N >= 0.
49 *> \endverbatim
50 *>
51 *> \param[in] A
52 *> \verbatim
53 *>          A is COMPLEX array, dimension (LDA,N)
54 *>          The m-by-n matrix A.
55 *> \endverbatim
56 *>
57 *> \param[out] AF
58 *> \verbatim
59 *>          AF is COMPLEX array, dimension (LDA,N)
60 *>          Details of the QR factorization of A, as returned by CGEQRF.
61 *>          See CGEQRF for further details.
62 *> \endverbatim
63 *>
64 *> \param[out] Q
65 *> \verbatim
66 *>          Q is COMPLEX array, dimension (LDA,M)
67 *>          The m-by-m orthogonal matrix Q.
68 *> \endverbatim
69 *>
70 *> \param[out] R
71 *> \verbatim
72 *>          R is COMPLEX array, dimension (LDA,max(M,N))
73 *> \endverbatim
74 *>
75 *> \param[in] LDA
76 *> \verbatim
77 *>          LDA is INTEGER
78 *>          The leading dimension of the arrays A, AF, Q and R.
79 *>          LDA >= max(M,N).
80 *> \endverbatim
81 *>
82 *> \param[out] TAU
83 *> \verbatim
84 *>          TAU is COMPLEX array, dimension (min(M,N))
85 *>          The scalar factors of the elementary reflectors, as returned
86 *>          by CGEQRF.
87 *> \endverbatim
88 *>
89 *> \param[out] WORK
90 *> \verbatim
91 *>          WORK is COMPLEX array, dimension (LWORK)
92 *> \endverbatim
93 *>
94 *> \param[in] LWORK
95 *> \verbatim
96 *>          LWORK is INTEGER
97 *>          The dimension of the array WORK.
98 *> \endverbatim
99 *>
100 *> \param[out] RWORK
101 *> \verbatim
102 *>          RWORK is REAL array, dimension (M)
103 *> \endverbatim
104 *>
105 *> \param[out] RESULT
106 *> \verbatim
107 *>          RESULT is REAL array, dimension (2)
108 *>          The test ratios:
109 *>          RESULT(1) = norm( R - Q'*A ) / ( M * norm(A) * EPS )
110 *>          RESULT(2) = norm( I - Q'*Q ) / ( M * EPS )
111 *> \endverbatim
112 *
113 *  Authors:
114 *  ========
115 *
116 *> \author Univ. of Tennessee 
117 *> \author Univ. of California Berkeley 
118 *> \author Univ. of Colorado Denver 
119 *> \author NAG Ltd. 
120 *
121 *> \date November 2011
122 *
123 *> \ingroup complex_lin
124 *
125 *  =====================================================================
126       SUBROUTINE CQRT01( M, N, A, AF, Q, R, LDA, TAU, WORK, LWORK,
127      $                   RWORK, RESULT )
128 *
129 *  -- LAPACK test routine (version 3.4.0) --
130 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
131 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
132 *     November 2011
133 *
134 *     .. Scalar Arguments ..
135       INTEGER            LDA, LWORK, M, N
136 *     ..
137 *     .. Array Arguments ..
138       REAL               RESULT( * ), RWORK( * )
139       COMPLEX            A( LDA, * ), AF( LDA, * ), Q( LDA, * ),
140      $                   R( LDA, * ), TAU( * ), WORK( LWORK )
141 *     ..
142 *
143 *  =====================================================================
144 *
145 *     .. Parameters ..
146       REAL               ZERO, ONE
147       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
148       COMPLEX            ROGUE
149       PARAMETER          ( ROGUE = ( -1.0E+10, -1.0E+10 ) )
150 *     ..
151 *     .. Local Scalars ..
152       INTEGER            INFO, MINMN
153       REAL               ANORM, EPS, RESID
154 *     ..
155 *     .. External Functions ..
156       REAL               CLANGE, CLANSY, SLAMCH
157       EXTERNAL           CLANGE, CLANSY, SLAMCH
158 *     ..
159 *     .. External Subroutines ..
160       EXTERNAL           CGEMM, CGEQRF, CHERK, CLACPY, CLASET, CUNGQR
161 *     ..
162 *     .. Intrinsic Functions ..
163       INTRINSIC          CMPLX, MAX, MIN, REAL
164 *     ..
165 *     .. Scalars in Common ..
166       CHARACTER*32       SRNAMT
167 *     ..
168 *     .. Common blocks ..
169       COMMON             / SRNAMC / SRNAMT
170 *     ..
171 *     .. Executable Statements ..
172 *
173       MINMN = MIN( M, N )
174       EPS = SLAMCH( 'Epsilon' )
175 *
176 *     Copy the matrix A to the array AF.
177 *
178       CALL CLACPY( 'Full', M, N, A, LDA, AF, LDA )
179 *
180 *     Factorize the matrix A in the array AF.
181 *
182       SRNAMT = 'CGEQRF'
183       CALL CGEQRF( M, N, AF, LDA, TAU, WORK, LWORK, INFO )
184 *
185 *     Copy details of Q
186 *
187       CALL CLASET( 'Full', M, M, ROGUE, ROGUE, Q, LDA )
188       CALL CLACPY( 'Lower', M-1, N, AF( 2, 1 ), LDA, Q( 2, 1 ), LDA )
189 *
190 *     Generate the m-by-m matrix Q
191 *
192       SRNAMT = 'CUNGQR'
193       CALL CUNGQR( M, M, MINMN, Q, LDA, TAU, WORK, LWORK, INFO )
194 *
195 *     Copy R
196 *
197       CALL CLASET( 'Full', M, N, CMPLX( ZERO ), CMPLX( ZERO ), R, LDA )
198       CALL CLACPY( 'Upper', M, N, AF, LDA, R, LDA )
199 *
200 *     Compute R - Q'*A
201 *
202       CALL CGEMM( 'Conjugate transpose', 'No transpose', M, N, M,
203      $            CMPLX( -ONE ), Q, LDA, A, LDA, CMPLX( ONE ), R, LDA )
204 *
205 *     Compute norm( R - Q'*A ) / ( M * norm(A) * EPS ) .
206 *
207       ANORM = CLANGE( '1', M, N, A, LDA, RWORK )
208       RESID = CLANGE( '1', M, N, R, LDA, RWORK )
209       IF( ANORM.GT.ZERO ) THEN
210          RESULT( 1 ) = ( ( RESID / REAL( MAX( 1, M ) ) ) / ANORM ) / EPS
211       ELSE
212          RESULT( 1 ) = ZERO
213       END IF
214 *
215 *     Compute I - Q'*Q
216 *
217       CALL CLASET( 'Full', M, M, CMPLX( ZERO ), CMPLX( ONE ), R, LDA )
218       CALL CHERK( 'Upper', 'Conjugate transpose', M, M, -ONE, Q, LDA,
219      $            ONE, R, LDA )
220 *
221 *     Compute norm( I - Q'*Q ) / ( M * EPS ) .
222 *
223       RESID = CLANSY( '1', 'Upper', M, R, LDA, RWORK )
224 *
225       RESULT( 2 ) = ( RESID / REAL( MAX( 1, M ) ) ) / EPS
226 *
227       RETURN
228 *
229 *     End of CQRT01
230 *
231       END