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.

zunhr_col01.f 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. *> \brief \b ZUNHR_COL01
  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 ZUNHR_COL01( M, N, MB1, NB1, NB2, RESULT )
  12. *
  13. * .. Scalar Arguments ..
  14. * INTEGER M, N, MB1, NB1, NB2
  15. * .. Return values ..
  16. * DOUBLE PRECISION RESULT(6)
  17. *
  18. *
  19. *> \par Purpose:
  20. * =============
  21. *>
  22. *> \verbatim
  23. *>
  24. *> ZUNHR_COL01 tests ZUNGTSQR and ZUNHR_COL using ZLATSQR, ZGEMQRT.
  25. *> Therefore, ZLATSQR (part of ZGEQR), ZGEMQRT (part of ZGEMQR)
  26. *> have to be tested before this test.
  27. *>
  28. *> \endverbatim
  29. *
  30. * Arguments:
  31. * ==========
  32. *
  33. *> \param[in] M
  34. *> \verbatim
  35. *> M is INTEGER
  36. *> Number of rows in test matrix.
  37. *> \endverbatim
  38. *> \param[in] N
  39. *> \verbatim
  40. *> N is INTEGER
  41. *> Number of columns in test matrix.
  42. *> \endverbatim
  43. *> \param[in] MB1
  44. *> \verbatim
  45. *> MB1 is INTEGER
  46. *> Number of row in row block in an input test matrix.
  47. *> \endverbatim
  48. *>
  49. *> \param[in] NB1
  50. *> \verbatim
  51. *> NB1 is INTEGER
  52. *> Number of columns in column block an input test matrix.
  53. *> \endverbatim
  54. *>
  55. *> \param[in] NB2
  56. *> \verbatim
  57. *> NB2 is INTEGER
  58. *> Number of columns in column block in an output test matrix.
  59. *> \endverbatim
  60. *>
  61. *> \param[out] RESULT
  62. *> \verbatim
  63. *> RESULT is DOUBLE PRECISION array, dimension (6)
  64. *> Results of each of the six tests below.
  65. *>
  66. *> A is a m-by-n test input matrix to be factored.
  67. *> so that A = Q_gr * ( R )
  68. *> ( 0 ),
  69. *>
  70. *> Q_qr is an implicit m-by-m unitary Q matrix, the result
  71. *> of factorization in blocked WY-representation,
  72. *> stored in ZGEQRT output format.
  73. *>
  74. *> R is a n-by-n upper-triangular matrix,
  75. *>
  76. *> 0 is a (m-n)-by-n zero matrix,
  77. *>
  78. *> Q is an explicit m-by-m unitary matrix Q = Q_gr * I
  79. *>
  80. *> C is an m-by-n random matrix,
  81. *>
  82. *> D is an n-by-m random matrix.
  83. *>
  84. *> The six tests are:
  85. *>
  86. *> RESULT(1) = |R - (Q**H) * A| / ( eps * m * |A| )
  87. *> is equivalent to test for | A - Q * R | / (eps * m * |A|),
  88. *>
  89. *> RESULT(2) = |I - (Q**H) * Q| / ( eps * m ),
  90. *>
  91. *> RESULT(3) = | Q_qr * C - Q * C | / (eps * m * |C|),
  92. *>
  93. *> RESULT(4) = | (Q_gr**H) * C - (Q**H) * C | / (eps * m * |C|)
  94. *>
  95. *> RESULT(5) = | D * Q_qr - D * Q | / (eps * m * |D|)
  96. *>
  97. *> RESULT(6) = | D * (Q_qr**H) - D * (Q**H) | / (eps * m * |D|),
  98. *>
  99. *> where:
  100. *> Q_qr * C, (Q_gr**H) * C, D * Q_qr, D * (Q_qr**H) are
  101. *> computed using ZGEMQRT,
  102. *>
  103. *> Q * C, (Q**H) * C, D * Q, D * (Q**H) are
  104. *> computed using ZGEMM.
  105. *> \endverbatim
  106. *
  107. * Authors:
  108. * ========
  109. *
  110. *> \author Univ. of Tennessee
  111. *> \author Univ. of California Berkeley
  112. *> \author Univ. of Colorado Denver
  113. *> \author NAG Ltd.
  114. *
  115. *> \ingroup complex16_lin
  116. *
  117. * =====================================================================
  118. SUBROUTINE ZUNHR_COL01( M, N, MB1, NB1, NB2, RESULT )
  119. IMPLICIT NONE
  120. *
  121. * -- LAPACK test routine --
  122. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  123. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  124. *
  125. * .. Scalar Arguments ..
  126. INTEGER M, N, MB1, NB1, NB2
  127. * .. Return values ..
  128. DOUBLE PRECISION RESULT(6)
  129. *
  130. * =====================================================================
  131. *
  132. * ..
  133. * .. Local allocatable arrays
  134. COMPLEX*16 , ALLOCATABLE :: A(:,:), AF(:,:), Q(:,:), R(:,:),
  135. $ WORK( : ), T1(:,:), T2(:,:), DIAG(:),
  136. $ C(:,:), CF(:,:), D(:,:), DF(:,:)
  137. DOUBLE PRECISION, ALLOCATABLE :: RWORK(:)
  138. *
  139. * .. Parameters ..
  140. DOUBLE PRECISION ZERO
  141. PARAMETER ( ZERO = 0.0D+0 )
  142. COMPLEX*16 CONE, CZERO
  143. PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ),
  144. $ CZERO = ( 0.0D+0, 0.0D+0 ) )
  145. * ..
  146. * .. Local Scalars ..
  147. LOGICAL TESTZEROS
  148. INTEGER INFO, I, J, K, L, LWORK, NB1_UB, NB2_UB, NRB
  149. DOUBLE PRECISION ANORM, EPS, RESID, CNORM, DNORM
  150. * ..
  151. * .. Local Arrays ..
  152. INTEGER ISEED( 4 )
  153. COMPLEX*16 WORKQUERY( 1 )
  154. * ..
  155. * .. External Functions ..
  156. DOUBLE PRECISION DLAMCH, ZLANGE, ZLANSY
  157. EXTERNAL DLAMCH, ZLANGE, ZLANSY
  158. * ..
  159. * .. External Subroutines ..
  160. EXTERNAL ZLACPY, ZLARNV, ZLASET, ZLATSQR, ZUNHR_COL,
  161. $ ZUNGTSQR, ZSCAL, ZGEMM, ZGEMQRT, ZHERK
  162. * ..
  163. * .. Intrinsic Functions ..
  164. INTRINSIC CEILING, DBLE, MAX, MIN
  165. * ..
  166. * .. Scalars in Common ..
  167. CHARACTER(LEN=32) SRNAMT
  168. * ..
  169. * .. Common blocks ..
  170. COMMON / SRMNAMC / SRNAMT
  171. * ..
  172. * .. Data statements ..
  173. DATA ISEED / 1988, 1989, 1990, 1991 /
  174. *
  175. * TEST MATRICES WITH HALF OF MATRIX BEING ZEROS
  176. *
  177. TESTZEROS = .FALSE.
  178. *
  179. EPS = DLAMCH( 'Epsilon' )
  180. K = MIN( M, N )
  181. L = MAX( M, N, 1)
  182. *
  183. * Dynamically allocate local arrays
  184. *
  185. ALLOCATE ( A(M,N), AF(M,N), Q(L,L), R(M,L), RWORK(L),
  186. $ C(M,N), CF(M,N),
  187. $ D(N,M), DF(N,M) )
  188. *
  189. * Put random numbers into A and copy to AF
  190. *
  191. DO J = 1, N
  192. CALL ZLARNV( 2, ISEED, M, A( 1, J ) )
  193. END DO
  194. IF( TESTZEROS ) THEN
  195. IF( M.GE.4 ) THEN
  196. DO J = 1, N
  197. CALL ZLARNV( 2, ISEED, M/2, A( M/4, J ) )
  198. END DO
  199. END IF
  200. END IF
  201. CALL ZLACPY( 'Full', M, N, A, M, AF, M )
  202. *
  203. * Number of row blocks in ZLATSQR
  204. *
  205. NRB = MAX( 1, CEILING( DBLE( M - N ) / DBLE( MB1 - N ) ) )
  206. *
  207. ALLOCATE ( T1( NB1, N * NRB ) )
  208. ALLOCATE ( T2( NB2, N ) )
  209. ALLOCATE ( DIAG( N ) )
  210. *
  211. * Begin determine LWORK for the array WORK and allocate memory.
  212. *
  213. * ZLATSQR requires NB1 to be bounded by N.
  214. *
  215. NB1_UB = MIN( NB1, N)
  216. *
  217. * ZGEMQRT requires NB2 to be bounded by N.
  218. *
  219. NB2_UB = MIN( NB2, N)
  220. *
  221. CALL ZLATSQR( M, N, MB1, NB1_UB, AF, M, T1, NB1,
  222. $ WORKQUERY, -1, INFO )
  223. LWORK = INT( WORKQUERY( 1 ) )
  224. CALL ZUNGTSQR( M, N, MB1, NB1, AF, M, T1, NB1, WORKQUERY, -1,
  225. $ INFO )
  226. LWORK = MAX( LWORK, INT( WORKQUERY( 1 ) ) )
  227. *
  228. * In ZGEMQRT, WORK is N*NB2_UB if SIDE = 'L',
  229. * or M*NB2_UB if SIDE = 'R'.
  230. *
  231. LWORK = MAX( LWORK, NB2_UB * N, NB2_UB * M )
  232. *
  233. ALLOCATE ( WORK( LWORK ) )
  234. *
  235. * End allocate memory for WORK.
  236. *
  237. *
  238. * Begin Householder reconstruction routines
  239. *
  240. * Factor the matrix A in the array AF.
  241. *
  242. SRNAMT = 'ZLATSQR'
  243. CALL ZLATSQR( M, N, MB1, NB1_UB, AF, M, T1, NB1, WORK, LWORK,
  244. $ INFO )
  245. *
  246. * Copy the factor R into the array R.
  247. *
  248. SRNAMT = 'ZLACPY'
  249. CALL ZLACPY( 'U', N, N, AF, M, R, M )
  250. *
  251. * Reconstruct the orthogonal matrix Q.
  252. *
  253. SRNAMT = 'ZUNGTSQR'
  254. CALL ZUNGTSQR( M, N, MB1, NB1, AF, M, T1, NB1, WORK, LWORK,
  255. $ INFO )
  256. *
  257. * Perform the Householder reconstruction, the result is stored
  258. * the arrays AF and T2.
  259. *
  260. SRNAMT = 'ZUNHR_COL'
  261. CALL ZUNHR_COL( M, N, NB2, AF, M, T2, NB2, DIAG, INFO )
  262. *
  263. * Compute the factor R_hr corresponding to the Householder
  264. * reconstructed Q_hr and place it in the upper triangle of AF to
  265. * match the Q storage format in ZGEQRT. R_hr = R_tsqr * S,
  266. * this means changing the sign of I-th row of the matrix R_tsqr
  267. * according to sign of of I-th diagonal element DIAG(I) of the
  268. * matrix S.
  269. *
  270. SRNAMT = 'ZLACPY'
  271. CALL ZLACPY( 'U', N, N, R, M, AF, M )
  272. *
  273. DO I = 1, N
  274. IF( DIAG( I ).EQ.-CONE ) THEN
  275. CALL ZSCAL( N+1-I, -CONE, AF( I, I ), M )
  276. END IF
  277. END DO
  278. *
  279. * End Householder reconstruction routines.
  280. *
  281. *
  282. * Generate the m-by-m matrix Q
  283. *
  284. CALL ZLASET( 'Full', M, M, CZERO, CONE, Q, M )
  285. *
  286. SRNAMT = 'ZGEMQRT'
  287. CALL ZGEMQRT( 'L', 'N', M, M, K, NB2_UB, AF, M, T2, NB2, Q, M,
  288. $ WORK, INFO )
  289. *
  290. * Copy R
  291. *
  292. CALL ZLASET( 'Full', M, N, CZERO, CZERO, R, M )
  293. *
  294. CALL ZLACPY( 'Upper', M, N, AF, M, R, M )
  295. *
  296. * TEST 1
  297. * Compute |R - (Q**H)*A| / ( eps * m * |A| ) and store in RESULT(1)
  298. *
  299. CALL ZGEMM( 'C', 'N', M, N, M, -CONE, Q, M, A, M, CONE, R, M )
  300. *
  301. ANORM = ZLANGE( '1', M, N, A, M, RWORK )
  302. RESID = ZLANGE( '1', M, N, R, M, RWORK )
  303. IF( ANORM.GT.ZERO ) THEN
  304. RESULT( 1 ) = RESID / ( EPS * MAX( 1, M ) * ANORM )
  305. ELSE
  306. RESULT( 1 ) = ZERO
  307. END IF
  308. *
  309. * TEST 2
  310. * Compute |I - (Q**H)*Q| / ( eps * m ) and store in RESULT(2)
  311. *
  312. CALL ZLASET( 'Full', M, M, CZERO, CONE, R, M )
  313. CALL ZHERK( 'U', 'C', M, M, -CONE, Q, M, CONE, R, M )
  314. RESID = ZLANSY( '1', 'Upper', M, R, M, RWORK )
  315. RESULT( 2 ) = RESID / ( EPS * MAX( 1, M ) )
  316. *
  317. * Generate random m-by-n matrix C
  318. *
  319. DO J = 1, N
  320. CALL ZLARNV( 2, ISEED, M, C( 1, J ) )
  321. END DO
  322. CNORM = ZLANGE( '1', M, N, C, M, RWORK )
  323. CALL ZLACPY( 'Full', M, N, C, M, CF, M )
  324. *
  325. * Apply Q to C as Q*C = CF
  326. *
  327. SRNAMT = 'ZGEMQRT'
  328. CALL ZGEMQRT( 'L', 'N', M, N, K, NB2_UB, AF, M, T2, NB2, CF, M,
  329. $ WORK, INFO )
  330. *
  331. * TEST 3
  332. * Compute |CF - Q*C| / ( eps * m * |C| )
  333. *
  334. CALL ZGEMM( 'N', 'N', M, N, M, -CONE, Q, M, C, M, CONE, CF, M )
  335. RESID = ZLANGE( '1', M, N, CF, M, RWORK )
  336. IF( CNORM.GT.ZERO ) THEN
  337. RESULT( 3 ) = RESID / ( EPS * MAX( 1, M ) * CNORM )
  338. ELSE
  339. RESULT( 3 ) = ZERO
  340. END IF
  341. *
  342. * Copy C into CF again
  343. *
  344. CALL ZLACPY( 'Full', M, N, C, M, CF, M )
  345. *
  346. * Apply Q to C as (Q**H)*C = CF
  347. *
  348. SRNAMT = 'ZGEMQRT'
  349. CALL ZGEMQRT( 'L', 'C', M, N, K, NB2_UB, AF, M, T2, NB2, CF, M,
  350. $ WORK, INFO )
  351. *
  352. * TEST 4
  353. * Compute |CF - (Q**H)*C| / ( eps * m * |C|)
  354. *
  355. CALL ZGEMM( 'C', 'N', M, N, M, -CONE, Q, M, C, M, CONE, CF, M )
  356. RESID = ZLANGE( '1', M, N, CF, M, RWORK )
  357. IF( CNORM.GT.ZERO ) THEN
  358. RESULT( 4 ) = RESID / ( EPS * MAX( 1, M ) * CNORM )
  359. ELSE
  360. RESULT( 4 ) = ZERO
  361. END IF
  362. *
  363. * Generate random n-by-m matrix D and a copy DF
  364. *
  365. DO J = 1, M
  366. CALL ZLARNV( 2, ISEED, N, D( 1, J ) )
  367. END DO
  368. DNORM = ZLANGE( '1', N, M, D, N, RWORK )
  369. CALL ZLACPY( 'Full', N, M, D, N, DF, N )
  370. *
  371. * Apply Q to D as D*Q = DF
  372. *
  373. SRNAMT = 'ZGEMQRT'
  374. CALL ZGEMQRT( 'R', 'N', N, M, K, NB2_UB, AF, M, T2, NB2, DF, N,
  375. $ WORK, INFO )
  376. *
  377. * TEST 5
  378. * Compute |DF - D*Q| / ( eps * m * |D| )
  379. *
  380. CALL ZGEMM( 'N', 'N', N, M, M, -CONE, D, N, Q, M, CONE, DF, N )
  381. RESID = ZLANGE( '1', N, M, DF, N, RWORK )
  382. IF( DNORM.GT.ZERO ) THEN
  383. RESULT( 5 ) = RESID / ( EPS * MAX( 1, M ) * DNORM )
  384. ELSE
  385. RESULT( 5 ) = ZERO
  386. END IF
  387. *
  388. * Copy D into DF again
  389. *
  390. CALL ZLACPY( 'Full', N, M, D, N, DF, N )
  391. *
  392. * Apply Q to D as D*QT = DF
  393. *
  394. SRNAMT = 'ZGEMQRT'
  395. CALL ZGEMQRT( 'R', 'C', N, M, K, NB2_UB, AF, M, T2, NB2, DF, N,
  396. $ WORK, INFO )
  397. *
  398. * TEST 6
  399. * Compute |DF - D*(Q**H)| / ( eps * m * |D| )
  400. *
  401. CALL ZGEMM( 'N', 'C', N, M, M, -CONE, D, N, Q, M, CONE, DF, N )
  402. RESID = ZLANGE( '1', N, M, DF, N, RWORK )
  403. IF( DNORM.GT.ZERO ) THEN
  404. RESULT( 6 ) = RESID / ( EPS * MAX( 1, M ) * DNORM )
  405. ELSE
  406. RESULT( 6 ) = ZERO
  407. END IF
  408. *
  409. * Deallocate all arrays
  410. *
  411. DEALLOCATE ( A, AF, Q, R, RWORK, WORK, T1, T2, DIAG,
  412. $ C, D, CF, DF )
  413. *
  414. RETURN
  415. *
  416. * End of ZUNHR_COL01
  417. *
  418. END