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.

ctzrzf.f 8.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. *> \brief \b CTZRZF
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CTZRZF + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ctzrzf.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ctzrzf.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ctzrzf.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CTZRZF( M, N, A, LDA, TAU, WORK, LWORK, INFO )
  22. *
  23. * .. Scalar Arguments ..
  24. * INTEGER INFO, LDA, LWORK, M, N
  25. * ..
  26. * .. Array Arguments ..
  27. * COMPLEX A( LDA, * ), TAU( * ), WORK( * )
  28. * ..
  29. *
  30. *
  31. *> \par Purpose:
  32. * =============
  33. *>
  34. *> \verbatim
  35. *>
  36. *> CTZRZF reduces the M-by-N ( M<=N ) complex upper trapezoidal matrix A
  37. *> to upper triangular form by means of unitary transformations.
  38. *>
  39. *> The upper trapezoidal matrix A is factored as
  40. *>
  41. *> A = ( R 0 ) * Z,
  42. *>
  43. *> where Z is an N-by-N unitary matrix and R is an M-by-M upper
  44. *> triangular matrix.
  45. *> \endverbatim
  46. *
  47. * Arguments:
  48. * ==========
  49. *
  50. *> \param[in] M
  51. *> \verbatim
  52. *> M is INTEGER
  53. *> The number of rows of the matrix A. M >= 0.
  54. *> \endverbatim
  55. *>
  56. *> \param[in] N
  57. *> \verbatim
  58. *> N is INTEGER
  59. *> The number of columns of the matrix A. N >= M.
  60. *> \endverbatim
  61. *>
  62. *> \param[in,out] A
  63. *> \verbatim
  64. *> A is COMPLEX array, dimension (LDA,N)
  65. *> On entry, the leading M-by-N upper trapezoidal part of the
  66. *> array A must contain the matrix to be factorized.
  67. *> On exit, the leading M-by-M upper triangular part of A
  68. *> contains the upper triangular matrix R, and elements M+1 to
  69. *> N of the first M rows of A, with the array TAU, represent the
  70. *> unitary matrix Z as a product of M elementary reflectors.
  71. *> \endverbatim
  72. *>
  73. *> \param[in] LDA
  74. *> \verbatim
  75. *> LDA is INTEGER
  76. *> The leading dimension of the array A. LDA >= max(1,M).
  77. *> \endverbatim
  78. *>
  79. *> \param[out] TAU
  80. *> \verbatim
  81. *> TAU is COMPLEX array, dimension (M)
  82. *> The scalar factors of the elementary reflectors.
  83. *> \endverbatim
  84. *>
  85. *> \param[out] WORK
  86. *> \verbatim
  87. *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
  88. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  89. *> \endverbatim
  90. *>
  91. *> \param[in] LWORK
  92. *> \verbatim
  93. *> LWORK is INTEGER
  94. *> The dimension of the array WORK. LWORK >= max(1,M).
  95. *> For optimum performance LWORK >= M*NB, where NB is
  96. *> the optimal blocksize.
  97. *>
  98. *> If LWORK = -1, then a workspace query is assumed; the routine
  99. *> only calculates the optimal size of the WORK array, returns
  100. *> this value as the first entry of the WORK array, and no error
  101. *> message related to LWORK is issued by XERBLA.
  102. *> \endverbatim
  103. *>
  104. *> \param[out] INFO
  105. *> \verbatim
  106. *> INFO is INTEGER
  107. *> = 0: successful exit
  108. *> < 0: if INFO = -i, the i-th argument had an illegal value
  109. *> \endverbatim
  110. *
  111. * Authors:
  112. * ========
  113. *
  114. *> \author Univ. of Tennessee
  115. *> \author Univ. of California Berkeley
  116. *> \author Univ. of Colorado Denver
  117. *> \author NAG Ltd.
  118. *
  119. *> \ingroup tzrzf
  120. *
  121. *> \par Contributors:
  122. * ==================
  123. *>
  124. *> A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
  125. *
  126. *> \par Further Details:
  127. * =====================
  128. *>
  129. *> \verbatim
  130. *>
  131. *> The N-by-N matrix Z can be computed by
  132. *>
  133. *> Z = Z(1)*Z(2)* ... *Z(M)
  134. *>
  135. *> where each N-by-N Z(k) is given by
  136. *>
  137. *> Z(k) = I - tau(k)*v(k)*v(k)**H
  138. *>
  139. *> with v(k) is the kth row vector of the M-by-N matrix
  140. *>
  141. *> V = ( I A(:,M+1:N) )
  142. *>
  143. *> I is the M-by-M identity matrix, A(:,M+1:N)
  144. *> is the output stored in A on exit from CTZRZF,
  145. *> and tau(k) is the kth element of the array TAU.
  146. *>
  147. *> \endverbatim
  148. *>
  149. * =====================================================================
  150. SUBROUTINE CTZRZF( M, N, A, LDA, TAU, WORK, LWORK, INFO )
  151. *
  152. * -- LAPACK computational routine --
  153. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  154. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  155. *
  156. * .. Scalar Arguments ..
  157. INTEGER INFO, LDA, LWORK, M, N
  158. * ..
  159. * .. Array Arguments ..
  160. COMPLEX A( LDA, * ), TAU( * ), WORK( * )
  161. * ..
  162. *
  163. * =====================================================================
  164. *
  165. * .. Parameters ..
  166. COMPLEX ZERO
  167. PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )
  168. * ..
  169. * .. Local Scalars ..
  170. LOGICAL LQUERY
  171. INTEGER I, IB, IWS, KI, KK, LDWORK, LWKMIN, LWKOPT,
  172. $ M1, MU, NB, NBMIN, NX
  173. * ..
  174. * .. External Subroutines ..
  175. EXTERNAL XERBLA, CLARZB, CLARZT, CLATRZ
  176. * ..
  177. * .. Intrinsic Functions ..
  178. INTRINSIC MAX, MIN
  179. * ..
  180. * .. External Functions ..
  181. INTEGER ILAENV
  182. REAL SROUNDUP_LWORK
  183. EXTERNAL ILAENV, SROUNDUP_LWORK
  184. * ..
  185. * .. Executable Statements ..
  186. *
  187. * Test the input arguments
  188. *
  189. INFO = 0
  190. LQUERY = ( LWORK.EQ.-1 )
  191. IF( M.LT.0 ) THEN
  192. INFO = -1
  193. ELSE IF( N.LT.M ) THEN
  194. INFO = -2
  195. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  196. INFO = -4
  197. END IF
  198. *
  199. IF( INFO.EQ.0 ) THEN
  200. IF( M.EQ.0 .OR. M.EQ.N ) THEN
  201. LWKOPT = 1
  202. LWKMIN = 1
  203. ELSE
  204. *
  205. * Determine the block size.
  206. *
  207. NB = ILAENV( 1, 'CGERQF', ' ', M, N, -1, -1 )
  208. LWKOPT = M*NB
  209. LWKMIN = MAX( 1, M )
  210. END IF
  211. WORK( 1 ) = SROUNDUP_LWORK(LWKOPT)
  212. *
  213. IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY ) THEN
  214. INFO = -7
  215. END IF
  216. END IF
  217. *
  218. IF( INFO.NE.0 ) THEN
  219. CALL XERBLA( 'CTZRZF', -INFO )
  220. RETURN
  221. ELSE IF( LQUERY ) THEN
  222. RETURN
  223. END IF
  224. *
  225. * Quick return if possible
  226. *
  227. IF( M.EQ.0 ) THEN
  228. RETURN
  229. ELSE IF( M.EQ.N ) THEN
  230. DO 10 I = 1, N
  231. TAU( I ) = ZERO
  232. 10 CONTINUE
  233. RETURN
  234. END IF
  235. *
  236. NBMIN = 2
  237. NX = 1
  238. IWS = M
  239. IF( NB.GT.1 .AND. NB.LT.M ) THEN
  240. *
  241. * Determine when to cross over from blocked to unblocked code.
  242. *
  243. NX = MAX( 0, ILAENV( 3, 'CGERQF', ' ', M, N, -1, -1 ) )
  244. IF( NX.LT.M ) THEN
  245. *
  246. * Determine if workspace is large enough for blocked code.
  247. *
  248. LDWORK = M
  249. IWS = LDWORK*NB
  250. IF( LWORK.LT.IWS ) THEN
  251. *
  252. * Not enough workspace to use optimal NB: reduce NB and
  253. * determine the minimum value of NB.
  254. *
  255. NB = LWORK / LDWORK
  256. NBMIN = MAX( 2, ILAENV( 2, 'CGERQF', ' ', M, N, -1,
  257. $ -1 ) )
  258. END IF
  259. END IF
  260. END IF
  261. *
  262. IF( NB.GE.NBMIN .AND. NB.LT.M .AND. NX.LT.M ) THEN
  263. *
  264. * Use blocked code initially.
  265. * The last kk rows are handled by the block method.
  266. *
  267. M1 = MIN( M+1, N )
  268. KI = ( ( M-NX-1 ) / NB )*NB
  269. KK = MIN( M, KI+NB )
  270. *
  271. DO 20 I = M - KK + KI + 1, M - KK + 1, -NB
  272. IB = MIN( M-I+1, NB )
  273. *
  274. * Compute the TZ factorization of the current block
  275. * A(i:i+ib-1,i:n)
  276. *
  277. CALL CLATRZ( IB, N-I+1, N-M, A( I, I ), LDA, TAU( I ),
  278. $ WORK )
  279. IF( I.GT.1 ) THEN
  280. *
  281. * Form the triangular factor of the block reflector
  282. * H = H(i+ib-1) . . . H(i+1) H(i)
  283. *
  284. CALL CLARZT( 'Backward', 'Rowwise', N-M, IB, A( I, M1 ),
  285. $ LDA, TAU( I ), WORK, LDWORK )
  286. *
  287. * Apply H to A(1:i-1,i:n) from the right
  288. *
  289. CALL CLARZB( 'Right', 'No transpose', 'Backward',
  290. $ 'Rowwise', I-1, N-I+1, IB, N-M, A( I, M1 ),
  291. $ LDA, WORK, LDWORK, A( 1, I ), LDA,
  292. $ WORK( IB+1 ), LDWORK )
  293. END IF
  294. 20 CONTINUE
  295. MU = I + NB - 1
  296. ELSE
  297. MU = M
  298. END IF
  299. *
  300. * Use unblocked code to factor the last or only block
  301. *
  302. IF( MU.GT.0 )
  303. $ CALL CLATRZ( MU, N, N-M, A, LDA, TAU, WORK )
  304. *
  305. WORK( 1 ) = SROUNDUP_LWORK(LWKOPT)
  306. *
  307. RETURN
  308. *
  309. * End of CTZRZF
  310. *
  311. END