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.

cgetsqrhrt.f 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. *> \brief \b CGETSQRHRT
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CGETSQRHRT + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgetsqrhrt.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgetsqrhrt.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgetsqrhrt.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CGETSQRHRT( M, N, MB1, NB1, NB2, A, LDA, T, LDT, WORK,
  22. * $ LWORK, INFO )
  23. * IMPLICIT NONE
  24. *
  25. * .. Scalar Arguments ..
  26. * INTEGER INFO, LDA, LDT, LWORK, M, N, NB1, NB2, MB1
  27. * ..
  28. * .. Array Arguments ..
  29. * COMPLEX*16 A( LDA, * ), T( LDT, * ), WORK( * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> CGETSQRHRT computes a NB2-sized column blocked QR-factorization
  39. *> of a complex M-by-N matrix A with M >= N,
  40. *>
  41. *> A = Q * R.
  42. *>
  43. *> The routine uses internally a NB1-sized column blocked and MB1-sized
  44. *> row blocked TSQR-factorization and perfors the reconstruction
  45. *> of the Householder vectors from the TSQR output. The routine also
  46. *> converts the R_tsqr factor from the TSQR-factorization output into
  47. *> the R factor that corresponds to the Householder QR-factorization,
  48. *>
  49. *> A = Q_tsqr * R_tsqr = Q * R.
  50. *>
  51. *> The output Q and R factors are stored in the same format as in CGEQRT
  52. *> (Q is in blocked compact WY-representation). See the documentation
  53. *> of CGEQRT for more details on the format.
  54. *> \endverbatim
  55. *
  56. * Arguments:
  57. * ==========
  58. *
  59. *> \param[in] M
  60. *> \verbatim
  61. *> M is INTEGER
  62. *> The number of rows of the matrix A. M >= 0.
  63. *> \endverbatim
  64. *>
  65. *> \param[in] N
  66. *> \verbatim
  67. *> N is INTEGER
  68. *> The number of columns of the matrix A. M >= N >= 0.
  69. *> \endverbatim
  70. *>
  71. *> \param[in] MB1
  72. *> \verbatim
  73. *> MB1 is INTEGER
  74. *> The row block size to be used in the blocked TSQR.
  75. *> MB1 > N.
  76. *> \endverbatim
  77. *>
  78. *> \param[in] NB1
  79. *> \verbatim
  80. *> NB1 is INTEGER
  81. *> The column block size to be used in the blocked TSQR.
  82. *> N >= NB1 >= 1.
  83. *> \endverbatim
  84. *>
  85. *> \param[in] NB2
  86. *> \verbatim
  87. *> NB2 is INTEGER
  88. *> The block size to be used in the blocked QR that is
  89. *> output. NB2 >= 1.
  90. *> \endverbatim
  91. *>
  92. *> \param[in,out] A
  93. *> \verbatim
  94. *> A is COMPLEX*16 array, dimension (LDA,N)
  95. *>
  96. *> On entry: an M-by-N matrix A.
  97. *>
  98. *> On exit:
  99. *> a) the elements on and above the diagonal
  100. *> of the array contain the N-by-N upper-triangular
  101. *> matrix R corresponding to the Householder QR;
  102. *> b) the elements below the diagonal represent Q by
  103. *> the columns of blocked V (compact WY-representation).
  104. *> \endverbatim
  105. *>
  106. *> \param[in] LDA
  107. *> \verbatim
  108. *> LDA is INTEGER
  109. *> The leading dimension of the array A. LDA >= max(1,M).
  110. *> \endverbatim
  111. *>
  112. *> \param[out] T
  113. *> \verbatim
  114. *> T is COMPLEX array, dimension (LDT,N))
  115. *> The upper triangular block reflectors stored in compact form
  116. *> as a sequence of upper triangular blocks.
  117. *> \endverbatim
  118. *>
  119. *> \param[in] LDT
  120. *> \verbatim
  121. *> LDT is INTEGER
  122. *> The leading dimension of the array T. LDT >= NB2.
  123. *> \endverbatim
  124. *>
  125. *> \param[out] WORK
  126. *> \verbatim
  127. *> (workspace) COMPLEX array, dimension (MAX(1,LWORK))
  128. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  129. *> \endverbatim
  130. *>
  131. *> \param[in] LWORK
  132. *> \verbatim
  133. *> The dimension of the array WORK.
  134. *> If MIN(M,N) = 0, LWORK >= 1, else
  135. *> LWORK >= MAX( 1, LWT + LW1, MAX( LWT+N*N+LW2, LWT+N*N+N ) ),
  136. *> where
  137. *> NUM_ALL_ROW_BLOCKS = CEIL((M-N)/(MB1-N)),
  138. *> NB1LOCAL = MIN(NB1,N).
  139. *> LWT = NUM_ALL_ROW_BLOCKS * N * NB1LOCAL,
  140. *> LW1 = NB1LOCAL * N,
  141. *> LW2 = NB1LOCAL * MAX( NB1LOCAL, ( N - NB1LOCAL ) ).
  142. *>
  143. *> If LWORK = -1, then a workspace query is assumed.
  144. *> The routine only calculates the optimal size of the WORK
  145. *> array, returns this value as the first entry of the WORK
  146. *> array, and no error message related to LWORK is issued
  147. *> by XERBLA.
  148. *> \endverbatim
  149. *>
  150. *> \param[out] INFO
  151. *> \verbatim
  152. *> INFO is INTEGER
  153. *> = 0: successful exit
  154. *> < 0: if INFO = -i, the i-th argument had an illegal value
  155. *> \endverbatim
  156. *
  157. * Authors:
  158. * ========
  159. *
  160. *> \author Univ. of Tennessee
  161. *> \author Univ. of California Berkeley
  162. *> \author Univ. of Colorado Denver
  163. *> \author NAG Ltd.
  164. *
  165. *> \ingroup getsqrhrt
  166. *
  167. *> \par Contributors:
  168. * ==================
  169. *>
  170. *> \verbatim
  171. *>
  172. *> November 2020, Igor Kozachenko,
  173. *> Computer Science Division,
  174. *> University of California, Berkeley
  175. *>
  176. *> \endverbatim
  177. *>
  178. * =====================================================================
  179. SUBROUTINE CGETSQRHRT( M, N, MB1, NB1, NB2, A, LDA, T, LDT, WORK,
  180. $ LWORK, INFO )
  181. IMPLICIT NONE
  182. *
  183. * -- LAPACK computational routine --
  184. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  185. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  186. *
  187. * .. Scalar Arguments ..
  188. INTEGER INFO, LDA, LDT, LWORK, M, N, NB1, NB2, MB1
  189. * ..
  190. * .. Array Arguments ..
  191. COMPLEX A( LDA, * ), T( LDT, * ), WORK( * )
  192. * ..
  193. *
  194. * =====================================================================
  195. *
  196. * .. Parameters ..
  197. COMPLEX CONE
  198. PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ) )
  199. * ..
  200. * .. Local Scalars ..
  201. LOGICAL LQUERY
  202. INTEGER I, IINFO, J, LW1, LW2, LWT, LDWT, LWORKOPT,
  203. $ NB1LOCAL, NB2LOCAL, NUM_ALL_ROW_BLOCKS
  204. * ..
  205. * .. External Functions ..
  206. REAL SROUNDUP_LWORK
  207. EXTERNAL SROUNDUP_LWORK
  208. * ..
  209. * .. External Subroutines ..
  210. EXTERNAL CCOPY, CLATSQR, CUNGTSQR_ROW, CUNHR_COL,
  211. $ XERBLA
  212. * ..
  213. * .. Intrinsic Functions ..
  214. INTRINSIC CEILING, REAL, CMPLX, MAX, MIN
  215. * ..
  216. * .. Executable Statements ..
  217. *
  218. * Test the input arguments
  219. *
  220. INFO = 0
  221. LQUERY = ( LWORK.EQ.-1 )
  222. IF( M.LT.0 ) THEN
  223. INFO = -1
  224. ELSE IF( N.LT.0 .OR. M.LT.N ) THEN
  225. INFO = -2
  226. ELSE IF( MB1.LE.N ) THEN
  227. INFO = -3
  228. ELSE IF( NB1.LT.1 ) THEN
  229. INFO = -4
  230. ELSE IF( NB2.LT.1 ) THEN
  231. INFO = -5
  232. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  233. INFO = -7
  234. ELSE IF( LDT.LT.MAX( 1, MIN( NB2, N ) ) ) THEN
  235. INFO = -9
  236. ELSE
  237. *
  238. * Test the input LWORK for the dimension of the array WORK.
  239. * This workspace is used to store array:
  240. * a) Matrix T and WORK for CLATSQR;
  241. * b) N-by-N upper-triangular factor R_tsqr;
  242. * c) Matrix T and array WORK for CUNGTSQR_ROW;
  243. * d) Diagonal D for CUNHR_COL.
  244. *
  245. IF( LWORK.LT.N*N+1 .AND. .NOT.LQUERY ) THEN
  246. INFO = -11
  247. ELSE
  248. *
  249. * Set block size for column blocks
  250. *
  251. NB1LOCAL = MIN( NB1, N )
  252. *
  253. NUM_ALL_ROW_BLOCKS = MAX( 1,
  254. $ CEILING( REAL( M - N ) / REAL( MB1 - N ) ) )
  255. *
  256. * Length and leading dimension of WORK array to place
  257. * T array in TSQR.
  258. *
  259. LWT = NUM_ALL_ROW_BLOCKS * N * NB1LOCAL
  260. LDWT = NB1LOCAL
  261. *
  262. * Length of TSQR work array
  263. *
  264. LW1 = NB1LOCAL * N
  265. *
  266. * Length of CUNGTSQR_ROW work array.
  267. *
  268. LW2 = NB1LOCAL * MAX( NB1LOCAL, ( N - NB1LOCAL ) )
  269. *
  270. LWORKOPT = MAX( LWT + LW1, MAX( LWT+N*N+LW2, LWT+N*N+N ) )
  271. LWORKOPT = MAX( 1, LWORKOPT )
  272. *
  273. IF( LWORK.LT.LWORKOPT .AND. .NOT.LQUERY ) THEN
  274. INFO = -11
  275. END IF
  276. *
  277. END IF
  278. END IF
  279. *
  280. * Handle error in the input parameters and return workspace query.
  281. *
  282. IF( INFO.NE.0 ) THEN
  283. CALL XERBLA( 'CGETSQRHRT', -INFO )
  284. RETURN
  285. ELSE IF ( LQUERY ) THEN
  286. WORK( 1 ) = SROUNDUP_LWORK( LWORKOPT )
  287. RETURN
  288. END IF
  289. *
  290. * Quick return if possible
  291. *
  292. IF( MIN( M, N ).EQ.0 ) THEN
  293. WORK( 1 ) = SROUNDUP_LWORK( LWORKOPT )
  294. RETURN
  295. END IF
  296. *
  297. NB2LOCAL = MIN( NB2, N )
  298. *
  299. *
  300. * (1) Perform TSQR-factorization of the M-by-N matrix A.
  301. *
  302. CALL CLATSQR( M, N, MB1, NB1LOCAL, A, LDA, WORK, LDWT,
  303. $ WORK(LWT+1), LW1, IINFO )
  304. *
  305. * (2) Copy the factor R_tsqr stored in the upper-triangular part
  306. * of A into the square matrix in the work array
  307. * WORK(LWT+1:LWT+N*N) column-by-column.
  308. *
  309. DO J = 1, N
  310. CALL CCOPY( J, A( 1, J ), 1, WORK( LWT + N*(J-1)+1 ), 1 )
  311. END DO
  312. *
  313. * (3) Generate a M-by-N matrix Q with orthonormal columns from
  314. * the result stored below the diagonal in the array A in place.
  315. *
  316. CALL CUNGTSQR_ROW( M, N, MB1, NB1LOCAL, A, LDA, WORK, LDWT,
  317. $ WORK( LWT+N*N+1 ), LW2, IINFO )
  318. *
  319. * (4) Perform the reconstruction of Householder vectors from
  320. * the matrix Q (stored in A) in place.
  321. *
  322. CALL CUNHR_COL( M, N, NB2LOCAL, A, LDA, T, LDT,
  323. $ WORK( LWT+N*N+1 ), IINFO )
  324. *
  325. * (5) Copy the factor R_tsqr stored in the square matrix in the
  326. * work array WORK(LWT+1:LWT+N*N) into the upper-triangular
  327. * part of A.
  328. *
  329. * (6) Compute from R_tsqr the factor R_hr corresponding to
  330. * the reconstructed Householder vectors, i.e. R_hr = S * R_tsqr.
  331. * This multiplication by the sign matrix S on the left means
  332. * changing the sign of I-th row of the matrix R_tsqr according
  333. * to sign of the I-th diagonal element DIAG(I) of the matrix S.
  334. * DIAG is stored in WORK( LWT+N*N+1 ) from the CUNHR_COL output.
  335. *
  336. * (5) and (6) can be combined in a single loop, so the rows in A
  337. * are accessed only once.
  338. *
  339. DO I = 1, N
  340. IF( WORK( LWT+N*N+I ).EQ.-CONE ) THEN
  341. DO J = I, N
  342. A( I, J ) = -CONE * WORK( LWT+N*(J-1)+I )
  343. END DO
  344. ELSE
  345. CALL CCOPY( N-I+1, WORK(LWT+N*(I-1)+I), N, A( I, I ), LDA )
  346. END IF
  347. END DO
  348. *
  349. WORK( 1 ) = SROUNDUP_LWORK( LWORKOPT )
  350. RETURN
  351. *
  352. * End of CGETSQRHRT
  353. *
  354. END