LAPACK 3.3.1
Linear Algebra PACKage

crqt02.f

Go to the documentation of this file.
00001       SUBROUTINE CRQT02( M, N, K, A, AF, Q, R, LDA, TAU, WORK, LWORK,
00002      $                   RWORK, RESULT )
00003 *
00004 *  -- LAPACK test routine (version 3.1) --
00005 *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
00006 *     November 2006
00007 *
00008 *     .. Scalar Arguments ..
00009       INTEGER            K, LDA, LWORK, M, N
00010 *     ..
00011 *     .. Array Arguments ..
00012       REAL               RESULT( * ), RWORK( * )
00013       COMPLEX            A( LDA, * ), AF( LDA, * ), Q( LDA, * ),
00014      $                   R( LDA, * ), TAU( * ), WORK( LWORK )
00015 *     ..
00016 *
00017 *  Purpose
00018 *  =======
00019 *
00020 *  CRQT02 tests CUNGRQ, which generates an m-by-n matrix Q with
00021 *  orthonornmal rows that is defined as the product of k elementary
00022 *  reflectors.
00023 *
00024 *  Given the RQ factorization of an m-by-n matrix A, CRQT02 generates
00025 *  the orthogonal matrix Q defined by the factorization of the last k
00026 *  rows of A; it compares R(m-k+1:m,n-m+1:n) with
00027 *  A(m-k+1:m,1:n)*Q(n-m+1:n,1:n)', and checks that the rows of Q are
00028 *  orthonormal.
00029 *
00030 *  Arguments
00031 *  =========
00032 *
00033 *  M       (input) INTEGER
00034 *          The number of rows of the matrix Q to be generated.  M >= 0.
00035 *
00036 *  N       (input) INTEGER
00037 *          The number of columns of the matrix Q to be generated.
00038 *          N >= M >= 0.
00039 *
00040 *  K       (input) INTEGER
00041 *          The number of elementary reflectors whose product defines the
00042 *          matrix Q. M >= K >= 0.
00043 *
00044 *  A       (input) COMPLEX array, dimension (LDA,N)
00045 *          The m-by-n matrix A which was factorized by CRQT01.
00046 *
00047 *  AF      (input) COMPLEX array, dimension (LDA,N)
00048 *          Details of the RQ factorization of A, as returned by CGERQF.
00049 *          See CGERQF for further details.
00050 *
00051 *  Q       (workspace) COMPLEX array, dimension (LDA,N)
00052 *
00053 *  R       (workspace) COMPLEX array, dimension (LDA,M)
00054 *
00055 *  LDA     (input) INTEGER
00056 *          The leading dimension of the arrays A, AF, Q and L. LDA >= N.
00057 *
00058 *  TAU     (input) COMPLEX array, dimension (M)
00059 *          The scalar factors of the elementary reflectors corresponding
00060 *          to the RQ factorization in AF.
00061 *
00062 *  WORK    (workspace) COMPLEX array, dimension (LWORK)
00063 *
00064 *  LWORK   (input) INTEGER
00065 *          The dimension of the array WORK.
00066 *
00067 *  RWORK   (workspace) REAL array, dimension (M)
00068 *
00069 *  RESULT  (output) REAL array, dimension (2)
00070 *          The test ratios:
00071 *          RESULT(1) = norm( R - A*Q' ) / ( N * norm(A) * EPS )
00072 *          RESULT(2) = norm( I - Q*Q' ) / ( N * EPS )
00073 *
00074 *  =====================================================================
00075 *
00076 *     .. Parameters ..
00077       REAL               ZERO, ONE
00078       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
00079       COMPLEX            ROGUE
00080       PARAMETER          ( ROGUE = ( -1.0E+10, -1.0E+10 ) )
00081 *     ..
00082 *     .. Local Scalars ..
00083       INTEGER            INFO
00084       REAL               ANORM, EPS, RESID
00085 *     ..
00086 *     .. External Functions ..
00087       REAL               CLANGE, CLANSY, SLAMCH
00088       EXTERNAL           CLANGE, CLANSY, SLAMCH
00089 *     ..
00090 *     .. External Subroutines ..
00091       EXTERNAL           CGEMM, CHERK, CLACPY, CLASET, CUNGRQ
00092 *     ..
00093 *     .. Intrinsic Functions ..
00094       INTRINSIC          CMPLX, MAX, REAL
00095 *     ..
00096 *     .. Scalars in Common ..
00097       CHARACTER*32       SRNAMT
00098 *     ..
00099 *     .. Common blocks ..
00100       COMMON             / SRNAMC / SRNAMT
00101 *     ..
00102 *     .. Executable Statements ..
00103 *
00104 *     Quick return if possible
00105 *
00106       IF( M.EQ.0 .OR. N.EQ.0 .OR. K.EQ.0 ) THEN
00107          RESULT( 1 ) = ZERO
00108          RESULT( 2 ) = ZERO
00109          RETURN
00110       END IF
00111 *
00112       EPS = SLAMCH( 'Epsilon' )
00113 *
00114 *     Copy the last k rows of the factorization to the array Q
00115 *
00116       CALL CLASET( 'Full', M, N, ROGUE, ROGUE, Q, LDA )
00117       IF( K.LT.N )
00118      $   CALL CLACPY( 'Full', K, N-K, AF( M-K+1, 1 ), LDA,
00119      $                Q( M-K+1, 1 ), LDA )
00120       IF( K.GT.1 )
00121      $   CALL CLACPY( 'Lower', K-1, K-1, AF( M-K+2, N-K+1 ), LDA,
00122      $                Q( M-K+2, N-K+1 ), LDA )
00123 *
00124 *     Generate the last n rows of the matrix Q
00125 *
00126       SRNAMT = 'CUNGRQ'
00127       CALL CUNGRQ( M, N, K, Q, LDA, TAU( M-K+1 ), WORK, LWORK, INFO )
00128 *
00129 *     Copy R(m-k+1:m,n-m+1:n)
00130 *
00131       CALL CLASET( 'Full', K, M, CMPLX( ZERO ), CMPLX( ZERO ),
00132      $             R( M-K+1, N-M+1 ), LDA )
00133       CALL CLACPY( 'Upper', K, K, AF( M-K+1, N-K+1 ), LDA,
00134      $             R( M-K+1, N-K+1 ), LDA )
00135 *
00136 *     Compute R(m-k+1:m,n-m+1:n) - A(m-k+1:m,1:n) * Q(n-m+1:n,1:n)'
00137 *
00138       CALL CGEMM( 'No transpose', 'Conjugate transpose', K, M, N,
00139      $            CMPLX( -ONE ), A( M-K+1, 1 ), LDA, Q, LDA,
00140      $            CMPLX( ONE ), R( M-K+1, N-M+1 ), LDA )
00141 *
00142 *     Compute norm( R - A*Q' ) / ( N * norm(A) * EPS ) .
00143 *
00144       ANORM = CLANGE( '1', K, N, A( M-K+1, 1 ), LDA, RWORK )
00145       RESID = CLANGE( '1', K, M, R( M-K+1, N-M+1 ), LDA, RWORK )
00146       IF( ANORM.GT.ZERO ) THEN
00147          RESULT( 1 ) = ( ( RESID / REAL( MAX( 1, N ) ) ) / ANORM ) / EPS
00148       ELSE
00149          RESULT( 1 ) = ZERO
00150       END IF
00151 *
00152 *     Compute I - Q*Q'
00153 *
00154       CALL CLASET( 'Full', M, M, CMPLX( ZERO ), CMPLX( ONE ), R, LDA )
00155       CALL CHERK( 'Upper', 'No transpose', M, N, -ONE, Q, LDA, ONE, R,
00156      $            LDA )
00157 *
00158 *     Compute norm( I - Q*Q' ) / ( N * EPS ) .
00159 *
00160       RESID = CLANSY( '1', 'Upper', M, R, LDA, RWORK )
00161 *
00162       RESULT( 2 ) = ( RESID / REAL( MAX( 1, N ) ) ) / EPS
00163 *
00164       RETURN
00165 *
00166 *     End of CRQT02
00167 *
00168       END
 All Files Functions