You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

zqrt02.f 6.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. *> \brief \b ZQRT02
  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 ZQRT02( M, N, K, A, AF, Q, R, LDA, TAU, WORK, LWORK,
  12. * RWORK, RESULT )
  13. *
  14. * .. Scalar Arguments ..
  15. * INTEGER K, LDA, LWORK, M, N
  16. * ..
  17. * .. Array Arguments ..
  18. * DOUBLE PRECISION RESULT( * ), RWORK( * )
  19. * COMPLEX*16 A( LDA, * ), AF( LDA, * ), Q( LDA, * ),
  20. * $ R( LDA, * ), TAU( * ), WORK( LWORK )
  21. * ..
  22. *
  23. *
  24. *> \par Purpose:
  25. * =============
  26. *>
  27. *> \verbatim
  28. *>
  29. *> ZQRT02 tests ZUNGQR, which generates an m-by-n matrix Q with
  30. *> orthonornmal columns that is defined as the product of k elementary
  31. *> reflectors.
  32. *>
  33. *> Given the QR factorization of an m-by-n matrix A, ZQRT02 generates
  34. *> the orthogonal matrix Q defined by the factorization of the first k
  35. *> columns of A; it compares R(1:n,1:k) with Q(1:m,1:n)'*A(1:m,1:k),
  36. *> and checks that the columns of Q are orthonormal.
  37. *> \endverbatim
  38. *
  39. * Arguments:
  40. * ==========
  41. *
  42. *> \param[in] M
  43. *> \verbatim
  44. *> M is INTEGER
  45. *> The number of rows of the matrix Q to be generated. M >= 0.
  46. *> \endverbatim
  47. *>
  48. *> \param[in] N
  49. *> \verbatim
  50. *> N is INTEGER
  51. *> The number of columns of the matrix Q to be generated.
  52. *> M >= N >= 0.
  53. *> \endverbatim
  54. *>
  55. *> \param[in] K
  56. *> \verbatim
  57. *> K is INTEGER
  58. *> The number of elementary reflectors whose product defines the
  59. *> matrix Q. N >= K >= 0.
  60. *> \endverbatim
  61. *>
  62. *> \param[in] A
  63. *> \verbatim
  64. *> A is COMPLEX*16 array, dimension (LDA,N)
  65. *> The m-by-n matrix A which was factorized by ZQRT01.
  66. *> \endverbatim
  67. *>
  68. *> \param[in] AF
  69. *> \verbatim
  70. *> AF is COMPLEX*16 array, dimension (LDA,N)
  71. *> Details of the QR factorization of A, as returned by ZGEQRF.
  72. *> See ZGEQRF for further details.
  73. *> \endverbatim
  74. *>
  75. *> \param[out] Q
  76. *> \verbatim
  77. *> Q is COMPLEX*16 array, dimension (LDA,N)
  78. *> \endverbatim
  79. *>
  80. *> \param[out] R
  81. *> \verbatim
  82. *> R is COMPLEX*16 array, dimension (LDA,N)
  83. *> \endverbatim
  84. *>
  85. *> \param[in] LDA
  86. *> \verbatim
  87. *> LDA is INTEGER
  88. *> The leading dimension of the arrays A, AF, Q and R. LDA >= M.
  89. *> \endverbatim
  90. *>
  91. *> \param[in] TAU
  92. *> \verbatim
  93. *> TAU is COMPLEX*16 array, dimension (N)
  94. *> The scalar factors of the elementary reflectors corresponding
  95. *> to the QR factorization in AF.
  96. *> \endverbatim
  97. *>
  98. *> \param[out] WORK
  99. *> \verbatim
  100. *> WORK is COMPLEX*16 array, dimension (LWORK)
  101. *> \endverbatim
  102. *>
  103. *> \param[in] LWORK
  104. *> \verbatim
  105. *> LWORK is INTEGER
  106. *> The dimension of the array WORK.
  107. *> \endverbatim
  108. *>
  109. *> \param[out] RWORK
  110. *> \verbatim
  111. *> RWORK is DOUBLE PRECISION array, dimension (M)
  112. *> \endverbatim
  113. *>
  114. *> \param[out] RESULT
  115. *> \verbatim
  116. *> RESULT is DOUBLE PRECISION array, dimension (2)
  117. *> The test ratios:
  118. *> RESULT(1) = norm( R - Q'*A ) / ( M * norm(A) * EPS )
  119. *> RESULT(2) = norm( I - Q'*Q ) / ( M * EPS )
  120. *> \endverbatim
  121. *
  122. * Authors:
  123. * ========
  124. *
  125. *> \author Univ. of Tennessee
  126. *> \author Univ. of California Berkeley
  127. *> \author Univ. of Colorado Denver
  128. *> \author NAG Ltd.
  129. *
  130. *> \date December 2016
  131. *
  132. *> \ingroup complex16_lin
  133. *
  134. * =====================================================================
  135. SUBROUTINE ZQRT02( M, N, K, A, AF, Q, R, LDA, TAU, WORK, LWORK,
  136. $ RWORK, RESULT )
  137. *
  138. * -- LAPACK test routine (version 3.7.0) --
  139. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  140. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  141. * December 2016
  142. *
  143. * .. Scalar Arguments ..
  144. INTEGER K, LDA, LWORK, M, N
  145. * ..
  146. * .. Array Arguments ..
  147. DOUBLE PRECISION RESULT( * ), RWORK( * )
  148. COMPLEX*16 A( LDA, * ), AF( LDA, * ), Q( LDA, * ),
  149. $ R( LDA, * ), TAU( * ), WORK( LWORK )
  150. * ..
  151. *
  152. * =====================================================================
  153. *
  154. * .. Parameters ..
  155. DOUBLE PRECISION ZERO, ONE
  156. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  157. COMPLEX*16 ROGUE
  158. PARAMETER ( ROGUE = ( -1.0D+10, -1.0D+10 ) )
  159. * ..
  160. * .. Local Scalars ..
  161. INTEGER INFO
  162. DOUBLE PRECISION ANORM, EPS, RESID
  163. * ..
  164. * .. External Functions ..
  165. DOUBLE PRECISION DLAMCH, ZLANGE, ZLANSY
  166. EXTERNAL DLAMCH, ZLANGE, ZLANSY
  167. * ..
  168. * .. External Subroutines ..
  169. EXTERNAL ZGEMM, ZHERK, ZLACPY, ZLASET, ZUNGQR
  170. * ..
  171. * .. Intrinsic Functions ..
  172. INTRINSIC DBLE, DCMPLX, MAX
  173. * ..
  174. * .. Scalars in Common ..
  175. CHARACTER*32 SRNAMT
  176. * ..
  177. * .. Common blocks ..
  178. COMMON / SRNAMC / SRNAMT
  179. * ..
  180. * .. Executable Statements ..
  181. *
  182. EPS = DLAMCH( 'Epsilon' )
  183. *
  184. * Copy the first k columns of the factorization to the array Q
  185. *
  186. CALL ZLASET( 'Full', M, N, ROGUE, ROGUE, Q, LDA )
  187. CALL ZLACPY( 'Lower', M-1, K, AF( 2, 1 ), LDA, Q( 2, 1 ), LDA )
  188. *
  189. * Generate the first n columns of the matrix Q
  190. *
  191. SRNAMT = 'ZUNGQR'
  192. CALL ZUNGQR( M, N, K, Q, LDA, TAU, WORK, LWORK, INFO )
  193. *
  194. * Copy R(1:n,1:k)
  195. *
  196. CALL ZLASET( 'Full', N, K, DCMPLX( ZERO ), DCMPLX( ZERO ), R,
  197. $ LDA )
  198. CALL ZLACPY( 'Upper', N, K, AF, LDA, R, LDA )
  199. *
  200. * Compute R(1:n,1:k) - Q(1:m,1:n)' * A(1:m,1:k)
  201. *
  202. CALL ZGEMM( 'Conjugate transpose', 'No transpose', N, K, M,
  203. $ DCMPLX( -ONE ), Q, LDA, A, LDA, DCMPLX( ONE ), R,
  204. $ LDA )
  205. *
  206. * Compute norm( R - Q'*A ) / ( M * norm(A) * EPS ) .
  207. *
  208. ANORM = ZLANGE( '1', M, K, A, LDA, RWORK )
  209. RESID = ZLANGE( '1', N, K, R, LDA, RWORK )
  210. IF( ANORM.GT.ZERO ) THEN
  211. RESULT( 1 ) = ( ( RESID / DBLE( MAX( 1, M ) ) ) / ANORM ) / EPS
  212. ELSE
  213. RESULT( 1 ) = ZERO
  214. END IF
  215. *
  216. * Compute I - Q'*Q
  217. *
  218. CALL ZLASET( 'Full', N, N, DCMPLX( ZERO ), DCMPLX( ONE ), R, LDA )
  219. CALL ZHERK( 'Upper', 'Conjugate transpose', N, M, -ONE, Q, LDA,
  220. $ ONE, R, LDA )
  221. *
  222. * Compute norm( I - Q'*Q ) / ( M * EPS ) .
  223. *
  224. RESID = ZLANSY( '1', 'Upper', N, R, LDA, RWORK )
  225. *
  226. RESULT( 2 ) = ( RESID / DBLE( MAX( 1, M ) ) ) / EPS
  227. *
  228. RETURN
  229. *
  230. * End of ZQRT02
  231. *
  232. END