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.

dgrqts.f 9.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. *> \brief \b DGRQTS
  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 DGRQTS( M, P, N, A, AF, Q, R, LDA, TAUA, B, BF, Z, T,
  12. * BWK, LDB, TAUB, WORK, LWORK, RWORK, RESULT )
  13. *
  14. * .. Scalar Arguments ..
  15. * INTEGER LDA, LDB, LWORK, M, N, P
  16. * ..
  17. * .. Array Arguments ..
  18. * DOUBLE PRECISION A( LDA, * ), AF( LDA, * ), B( LDB, * ),
  19. * $ BF( LDB, * ), BWK( LDB, * ), Q( LDA, * ),
  20. * $ R( LDA, * ), RESULT( 4 ), RWORK( * ),
  21. * $ T( LDB, * ), TAUA( * ), TAUB( * ),
  22. * $ WORK( LWORK ), Z( LDB, * )
  23. * ..
  24. *
  25. *
  26. *> \par Purpose:
  27. * =============
  28. *>
  29. *> \verbatim
  30. *>
  31. *> DGRQTS tests DGGRQF, which computes the GRQ factorization of an
  32. *> M-by-N matrix A and a P-by-N matrix B: A = R*Q and B = Z*T*Q.
  33. *> \endverbatim
  34. *
  35. * Arguments:
  36. * ==========
  37. *
  38. *> \param[in] M
  39. *> \verbatim
  40. *> M is INTEGER
  41. *> The number of rows of the matrix A. M >= 0.
  42. *> \endverbatim
  43. *>
  44. *> \param[in] P
  45. *> \verbatim
  46. *> P is INTEGER
  47. *> The number of rows of the matrix B. P >= 0.
  48. *> \endverbatim
  49. *>
  50. *> \param[in] N
  51. *> \verbatim
  52. *> N is INTEGER
  53. *> The number of columns of the matrices A and B. N >= 0.
  54. *> \endverbatim
  55. *>
  56. *> \param[in] A
  57. *> \verbatim
  58. *> A is DOUBLE PRECISION array, dimension (LDA,N)
  59. *> The M-by-N matrix A.
  60. *> \endverbatim
  61. *>
  62. *> \param[out] AF
  63. *> \verbatim
  64. *> AF is DOUBLE PRECISION array, dimension (LDA,N)
  65. *> Details of the GRQ factorization of A and B, as returned
  66. *> by DGGRQF, see SGGRQF for further details.
  67. *> \endverbatim
  68. *>
  69. *> \param[out] Q
  70. *> \verbatim
  71. *> Q is DOUBLE PRECISION array, dimension (LDA,N)
  72. *> The N-by-N orthogonal matrix Q.
  73. *> \endverbatim
  74. *>
  75. *> \param[out] R
  76. *> \verbatim
  77. *> R is DOUBLE PRECISION array, dimension (LDA,MAX(M,N))
  78. *> \endverbatim
  79. *>
  80. *> \param[in] LDA
  81. *> \verbatim
  82. *> LDA is INTEGER
  83. *> The leading dimension of the arrays A, AF, R and Q.
  84. *> LDA >= max(M,N).
  85. *> \endverbatim
  86. *>
  87. *> \param[out] TAUA
  88. *> \verbatim
  89. *> TAUA is DOUBLE PRECISION array, dimension (min(M,N))
  90. *> The scalar factors of the elementary reflectors, as returned
  91. *> by DGGQRC.
  92. *> \endverbatim
  93. *>
  94. *> \param[in] B
  95. *> \verbatim
  96. *> B is DOUBLE PRECISION array, dimension (LDB,N)
  97. *> On entry, the P-by-N matrix A.
  98. *> \endverbatim
  99. *>
  100. *> \param[out] BF
  101. *> \verbatim
  102. *> BF is DOUBLE PRECISION array, dimension (LDB,N)
  103. *> Details of the GQR factorization of A and B, as returned
  104. *> by DGGRQF, see SGGRQF for further details.
  105. *> \endverbatim
  106. *>
  107. *> \param[out] Z
  108. *> \verbatim
  109. *> Z is DOUBLE PRECISION array, dimension (LDB,P)
  110. *> The P-by-P orthogonal matrix Z.
  111. *> \endverbatim
  112. *>
  113. *> \param[out] T
  114. *> \verbatim
  115. *> T is DOUBLE PRECISION array, dimension (LDB,max(P,N))
  116. *> \endverbatim
  117. *>
  118. *> \param[out] BWK
  119. *> \verbatim
  120. *> BWK is DOUBLE PRECISION array, dimension (LDB,N)
  121. *> \endverbatim
  122. *>
  123. *> \param[in] LDB
  124. *> \verbatim
  125. *> LDB is INTEGER
  126. *> The leading dimension of the arrays B, BF, Z and T.
  127. *> LDB >= max(P,N).
  128. *> \endverbatim
  129. *>
  130. *> \param[out] TAUB
  131. *> \verbatim
  132. *> TAUB is DOUBLE PRECISION array, dimension (min(P,N))
  133. *> The scalar factors of the elementary reflectors, as returned
  134. *> by DGGRQF.
  135. *> \endverbatim
  136. *>
  137. *> \param[out] WORK
  138. *> \verbatim
  139. *> WORK is DOUBLE PRECISION array, dimension (LWORK)
  140. *> \endverbatim
  141. *>
  142. *> \param[in] LWORK
  143. *> \verbatim
  144. *> LWORK is INTEGER
  145. *> The dimension of the array WORK, LWORK >= max(M,P,N)**2.
  146. *> \endverbatim
  147. *>
  148. *> \param[out] RWORK
  149. *> \verbatim
  150. *> RWORK is DOUBLE PRECISION array, dimension (M)
  151. *> \endverbatim
  152. *>
  153. *> \param[out] RESULT
  154. *> \verbatim
  155. *> RESULT is DOUBLE PRECISION array, dimension (4)
  156. *> The test ratios:
  157. *> RESULT(1) = norm( R - A*Q' ) / ( MAX(M,N)*norm(A)*ULP)
  158. *> RESULT(2) = norm( T*Q - Z'*B ) / (MAX(P,N)*norm(B)*ULP)
  159. *> RESULT(3) = norm( I - Q'*Q ) / ( N*ULP )
  160. *> RESULT(4) = norm( I - Z'*Z ) / ( P*ULP )
  161. *> \endverbatim
  162. *
  163. * Authors:
  164. * ========
  165. *
  166. *> \author Univ. of Tennessee
  167. *> \author Univ. of California Berkeley
  168. *> \author Univ. of Colorado Denver
  169. *> \author NAG Ltd.
  170. *
  171. *> \date November 2011
  172. *
  173. *> \ingroup double_eig
  174. *
  175. * =====================================================================
  176. SUBROUTINE DGRQTS( M, P, N, A, AF, Q, R, LDA, TAUA, B, BF, Z, T,
  177. $ BWK, LDB, TAUB, WORK, LWORK, RWORK, RESULT )
  178. *
  179. * -- LAPACK test routine (version 3.4.0) --
  180. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  181. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  182. * November 2011
  183. *
  184. * .. Scalar Arguments ..
  185. INTEGER LDA, LDB, LWORK, M, N, P
  186. * ..
  187. * .. Array Arguments ..
  188. DOUBLE PRECISION A( LDA, * ), AF( LDA, * ), B( LDB, * ),
  189. $ BF( LDB, * ), BWK( LDB, * ), Q( LDA, * ),
  190. $ R( LDA, * ), RESULT( 4 ), RWORK( * ),
  191. $ T( LDB, * ), TAUA( * ), TAUB( * ),
  192. $ WORK( LWORK ), Z( LDB, * )
  193. * ..
  194. *
  195. * =====================================================================
  196. *
  197. * .. Parameters ..
  198. DOUBLE PRECISION ZERO, ONE
  199. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  200. DOUBLE PRECISION ROGUE
  201. PARAMETER ( ROGUE = -1.0D+10 )
  202. * ..
  203. * .. Local Scalars ..
  204. INTEGER INFO
  205. DOUBLE PRECISION ANORM, BNORM, RESID, ULP, UNFL
  206. * ..
  207. * .. External Functions ..
  208. DOUBLE PRECISION DLAMCH, DLANGE, DLANSY
  209. EXTERNAL DLAMCH, DLANGE, DLANSY
  210. * ..
  211. * .. External Subroutines ..
  212. EXTERNAL DGEMM, DGGRQF, DLACPY, DLASET, DORGQR, DORGRQ,
  213. $ DSYRK
  214. * ..
  215. * .. Intrinsic Functions ..
  216. INTRINSIC DBLE, MAX, MIN
  217. * ..
  218. * .. Executable Statements ..
  219. *
  220. ULP = DLAMCH( 'Precision' )
  221. UNFL = DLAMCH( 'Safe minimum' )
  222. *
  223. * Copy the matrix A to the array AF.
  224. *
  225. CALL DLACPY( 'Full', M, N, A, LDA, AF, LDA )
  226. CALL DLACPY( 'Full', P, N, B, LDB, BF, LDB )
  227. *
  228. ANORM = MAX( DLANGE( '1', M, N, A, LDA, RWORK ), UNFL )
  229. BNORM = MAX( DLANGE( '1', P, N, B, LDB, RWORK ), UNFL )
  230. *
  231. * Factorize the matrices A and B in the arrays AF and BF.
  232. *
  233. CALL DGGRQF( M, P, N, AF, LDA, TAUA, BF, LDB, TAUB, WORK, LWORK,
  234. $ INFO )
  235. *
  236. * Generate the N-by-N matrix Q
  237. *
  238. CALL DLASET( 'Full', N, N, ROGUE, ROGUE, Q, LDA )
  239. IF( M.LE.N ) THEN
  240. IF( M.GT.0 .AND. M.LT.N )
  241. $ CALL DLACPY( 'Full', M, N-M, AF, LDA, Q( N-M+1, 1 ), LDA )
  242. IF( M.GT.1 )
  243. $ CALL DLACPY( 'Lower', M-1, M-1, AF( 2, N-M+1 ), LDA,
  244. $ Q( N-M+2, N-M+1 ), LDA )
  245. ELSE
  246. IF( N.GT.1 )
  247. $ CALL DLACPY( 'Lower', N-1, N-1, AF( M-N+2, 1 ), LDA,
  248. $ Q( 2, 1 ), LDA )
  249. END IF
  250. CALL DORGRQ( N, N, MIN( M, N ), Q, LDA, TAUA, WORK, LWORK, INFO )
  251. *
  252. * Generate the P-by-P matrix Z
  253. *
  254. CALL DLASET( 'Full', P, P, ROGUE, ROGUE, Z, LDB )
  255. IF( P.GT.1 )
  256. $ CALL DLACPY( 'Lower', P-1, N, BF( 2, 1 ), LDB, Z( 2, 1 ), LDB )
  257. CALL DORGQR( P, P, MIN( P, N ), Z, LDB, TAUB, WORK, LWORK, INFO )
  258. *
  259. * Copy R
  260. *
  261. CALL DLASET( 'Full', M, N, ZERO, ZERO, R, LDA )
  262. IF( M.LE.N ) THEN
  263. CALL DLACPY( 'Upper', M, M, AF( 1, N-M+1 ), LDA, R( 1, N-M+1 ),
  264. $ LDA )
  265. ELSE
  266. CALL DLACPY( 'Full', M-N, N, AF, LDA, R, LDA )
  267. CALL DLACPY( 'Upper', N, N, AF( M-N+1, 1 ), LDA, R( M-N+1, 1 ),
  268. $ LDA )
  269. END IF
  270. *
  271. * Copy T
  272. *
  273. CALL DLASET( 'Full', P, N, ZERO, ZERO, T, LDB )
  274. CALL DLACPY( 'Upper', P, N, BF, LDB, T, LDB )
  275. *
  276. * Compute R - A*Q'
  277. *
  278. CALL DGEMM( 'No transpose', 'Transpose', M, N, N, -ONE, A, LDA, Q,
  279. $ LDA, ONE, R, LDA )
  280. *
  281. * Compute norm( R - A*Q' ) / ( MAX(M,N)*norm(A)*ULP ) .
  282. *
  283. RESID = DLANGE( '1', M, N, R, LDA, RWORK )
  284. IF( ANORM.GT.ZERO ) THEN
  285. RESULT( 1 ) = ( ( RESID / DBLE( MAX( 1, M, N ) ) ) / ANORM ) /
  286. $ ULP
  287. ELSE
  288. RESULT( 1 ) = ZERO
  289. END IF
  290. *
  291. * Compute T*Q - Z'*B
  292. *
  293. CALL DGEMM( 'Transpose', 'No transpose', P, N, P, ONE, Z, LDB, B,
  294. $ LDB, ZERO, BWK, LDB )
  295. CALL DGEMM( 'No transpose', 'No transpose', P, N, N, ONE, T, LDB,
  296. $ Q, LDA, -ONE, BWK, LDB )
  297. *
  298. * Compute norm( T*Q - Z'*B ) / ( MAX(P,N)*norm(A)*ULP ) .
  299. *
  300. RESID = DLANGE( '1', P, N, BWK, LDB, RWORK )
  301. IF( BNORM.GT.ZERO ) THEN
  302. RESULT( 2 ) = ( ( RESID / DBLE( MAX( 1, P, M ) ) ) / BNORM ) /
  303. $ ULP
  304. ELSE
  305. RESULT( 2 ) = ZERO
  306. END IF
  307. *
  308. * Compute I - Q*Q'
  309. *
  310. CALL DLASET( 'Full', N, N, ZERO, ONE, R, LDA )
  311. CALL DSYRK( 'Upper', 'No Transpose', N, N, -ONE, Q, LDA, ONE, R,
  312. $ LDA )
  313. *
  314. * Compute norm( I - Q'*Q ) / ( N * ULP ) .
  315. *
  316. RESID = DLANSY( '1', 'Upper', N, R, LDA, RWORK )
  317. RESULT( 3 ) = ( RESID / DBLE( MAX( 1, N ) ) ) / ULP
  318. *
  319. * Compute I - Z'*Z
  320. *
  321. CALL DLASET( 'Full', P, P, ZERO, ONE, T, LDB )
  322. CALL DSYRK( 'Upper', 'Transpose', P, P, -ONE, Z, LDB, ONE, T,
  323. $ LDB )
  324. *
  325. * Compute norm( I - Z'*Z ) / ( P*ULP ) .
  326. *
  327. RESID = DLANSY( '1', 'Upper', P, T, LDB, RWORK )
  328. RESULT( 4 ) = ( RESID / DBLE( MAX( 1, P ) ) ) / ULP
  329. *
  330. RETURN
  331. *
  332. * End of DGRQTS
  333. *
  334. END