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.

zgeqrf.f 7.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. *> \brief \b ZGEQRF
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download ZGEQRF + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgeqrf.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgeqrf.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgeqrf.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE ZGEQRF( 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*16 A( LDA, * ), TAU( * ), WORK( * )
  28. * ..
  29. *
  30. *
  31. *> \par Purpose:
  32. * =============
  33. *>
  34. *> \verbatim
  35. *>
  36. *> ZGEQRF computes a QR factorization of a complex M-by-N matrix A:
  37. *> A = Q * R.
  38. *> \endverbatim
  39. *
  40. * Arguments:
  41. * ==========
  42. *
  43. *> \param[in] M
  44. *> \verbatim
  45. *> M is INTEGER
  46. *> The number of rows of the matrix A. M >= 0.
  47. *> \endverbatim
  48. *>
  49. *> \param[in] N
  50. *> \verbatim
  51. *> N is INTEGER
  52. *> The number of columns of the matrix A. N >= 0.
  53. *> \endverbatim
  54. *>
  55. *> \param[in,out] A
  56. *> \verbatim
  57. *> A is COMPLEX*16 array, dimension (LDA,N)
  58. *> On entry, the M-by-N matrix A.
  59. *> On exit, the elements on and above the diagonal of the array
  60. *> contain the min(M,N)-by-N upper trapezoidal matrix R (R is
  61. *> upper triangular if m >= n); the elements below the diagonal,
  62. *> with the array TAU, represent the unitary matrix Q as a
  63. *> product of min(m,n) elementary reflectors (see Further
  64. *> Details).
  65. *> \endverbatim
  66. *>
  67. *> \param[in] LDA
  68. *> \verbatim
  69. *> LDA is INTEGER
  70. *> The leading dimension of the array A. LDA >= max(1,M).
  71. *> \endverbatim
  72. *>
  73. *> \param[out] TAU
  74. *> \verbatim
  75. *> TAU is COMPLEX*16 array, dimension (min(M,N))
  76. *> The scalar factors of the elementary reflectors (see Further
  77. *> Details).
  78. *> \endverbatim
  79. *>
  80. *> \param[out] WORK
  81. *> \verbatim
  82. *> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))
  83. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  84. *> \endverbatim
  85. *>
  86. *> \param[in] LWORK
  87. *> \verbatim
  88. *> LWORK is INTEGER
  89. *> The dimension of the array WORK. LWORK >= max(1,N).
  90. *> For optimum performance LWORK >= N*NB, where NB is
  91. *> the optimal blocksize.
  92. *>
  93. *> If LWORK = -1, then a workspace query is assumed; the routine
  94. *> only calculates the optimal size of the WORK array, returns
  95. *> this value as the first entry of the WORK array, and no error
  96. *> message related to LWORK is issued by XERBLA.
  97. *> \endverbatim
  98. *>
  99. *> \param[out] INFO
  100. *> \verbatim
  101. *> INFO is INTEGER
  102. *> = 0: successful exit
  103. *> < 0: if INFO = -i, the i-th argument had an illegal value
  104. *> \endverbatim
  105. *
  106. * Authors:
  107. * ========
  108. *
  109. *> \author Univ. of Tennessee
  110. *> \author Univ. of California Berkeley
  111. *> \author Univ. of Colorado Denver
  112. *> \author NAG Ltd.
  113. *
  114. *> \date December 2016
  115. *
  116. *> \ingroup complex16GEcomputational
  117. *
  118. *> \par Further Details:
  119. * =====================
  120. *>
  121. *> \verbatim
  122. *>
  123. *> The matrix Q is represented as a product of elementary reflectors
  124. *>
  125. *> Q = H(1) H(2) . . . H(k), where k = min(m,n).
  126. *>
  127. *> Each H(i) has the form
  128. *>
  129. *> H(i) = I - tau * v * v**H
  130. *>
  131. *> where tau is a complex scalar, and v is a complex vector with
  132. *> v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i),
  133. *> and tau in TAU(i).
  134. *> \endverbatim
  135. *>
  136. * =====================================================================
  137. SUBROUTINE ZGEQRF( M, N, A, LDA, TAU, WORK, LWORK, INFO )
  138. *
  139. * -- LAPACK computational routine (version 3.7.0) --
  140. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  141. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  142. * December 2016
  143. *
  144. * .. Scalar Arguments ..
  145. INTEGER INFO, LDA, LWORK, M, N
  146. * ..
  147. * .. Array Arguments ..
  148. COMPLEX*16 A( LDA, * ), TAU( * ), WORK( * )
  149. * ..
  150. *
  151. * =====================================================================
  152. *
  153. * .. Local Scalars ..
  154. LOGICAL LQUERY
  155. INTEGER I, IB, IINFO, IWS, K, LDWORK, LWKOPT, NB,
  156. $ NBMIN, NX
  157. * ..
  158. * .. External Subroutines ..
  159. EXTERNAL XERBLA, ZGEQR2, ZLARFB, ZLARFT
  160. * ..
  161. * .. Intrinsic Functions ..
  162. INTRINSIC MAX, MIN
  163. * ..
  164. * .. External Functions ..
  165. INTEGER ILAENV
  166. EXTERNAL ILAENV
  167. * ..
  168. * .. Executable Statements ..
  169. *
  170. * Test the input arguments
  171. *
  172. INFO = 0
  173. NB = ILAENV( 1, 'ZGEQRF', ' ', M, N, -1, -1 )
  174. LWKOPT = N*NB
  175. WORK( 1 ) = LWKOPT
  176. LQUERY = ( LWORK.EQ.-1 )
  177. IF( M.LT.0 ) THEN
  178. INFO = -1
  179. ELSE IF( N.LT.0 ) THEN
  180. INFO = -2
  181. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  182. INFO = -4
  183. ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
  184. INFO = -7
  185. END IF
  186. IF( INFO.NE.0 ) THEN
  187. CALL XERBLA( 'ZGEQRF', -INFO )
  188. RETURN
  189. ELSE IF( LQUERY ) THEN
  190. RETURN
  191. END IF
  192. *
  193. * Quick return if possible
  194. *
  195. K = MIN( M, N )
  196. IF( K.EQ.0 ) THEN
  197. WORK( 1 ) = 1
  198. RETURN
  199. END IF
  200. *
  201. NBMIN = 2
  202. NX = 0
  203. IWS = N
  204. IF( NB.GT.1 .AND. NB.LT.K ) THEN
  205. *
  206. * Determine when to cross over from blocked to unblocked code.
  207. *
  208. NX = MAX( 0, ILAENV( 3, 'ZGEQRF', ' ', M, N, -1, -1 ) )
  209. IF( NX.LT.K ) THEN
  210. *
  211. * Determine if workspace is large enough for blocked code.
  212. *
  213. LDWORK = N
  214. IWS = LDWORK*NB
  215. IF( LWORK.LT.IWS ) THEN
  216. *
  217. * Not enough workspace to use optimal NB: reduce NB and
  218. * determine the minimum value of NB.
  219. *
  220. NB = LWORK / LDWORK
  221. NBMIN = MAX( 2, ILAENV( 2, 'ZGEQRF', ' ', M, N, -1,
  222. $ -1 ) )
  223. END IF
  224. END IF
  225. END IF
  226. *
  227. IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN
  228. *
  229. * Use blocked code initially
  230. *
  231. DO 10 I = 1, K - NX, NB
  232. IB = MIN( K-I+1, NB )
  233. *
  234. * Compute the QR factorization of the current block
  235. * A(i:m,i:i+ib-1)
  236. *
  237. CALL ZGEQR2( M-I+1, IB, A( I, I ), LDA, TAU( I ), WORK,
  238. $ IINFO )
  239. IF( I+IB.LE.N ) THEN
  240. *
  241. * Form the triangular factor of the block reflector
  242. * H = H(i) H(i+1) . . . H(i+ib-1)
  243. *
  244. CALL ZLARFT( 'Forward', 'Columnwise', M-I+1, IB,
  245. $ A( I, I ), LDA, TAU( I ), WORK, LDWORK )
  246. *
  247. * Apply H**H to A(i:m,i+ib:n) from the left
  248. *
  249. CALL ZLARFB( 'Left', 'Conjugate transpose', 'Forward',
  250. $ 'Columnwise', M-I+1, N-I-IB+1, IB,
  251. $ A( I, I ), LDA, WORK, LDWORK, A( I, I+IB ),
  252. $ LDA, WORK( IB+1 ), LDWORK )
  253. END IF
  254. 10 CONTINUE
  255. ELSE
  256. I = 1
  257. END IF
  258. *
  259. * Use unblocked code to factor the last or only block.
  260. *
  261. IF( I.LE.K )
  262. $ CALL ZGEQR2( M-I+1, N-I+1, A( I, I ), LDA, TAU( I ), WORK,
  263. $ IINFO )
  264. *
  265. WORK( 1 ) = IWS
  266. RETURN
  267. *
  268. * End of ZGEQRF
  269. *
  270. END