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.

sgetsqrhrt.f 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. *> \brief \b SGETSQRHRT
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SGETSQRHRT + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgetsqrhrt.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgetsqrhrt.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgetsqrhrt.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SGETSQRHRT( 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. * REAL A( LDA, * ), T( LDT, * ), WORK( * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> SGETSQRHRT 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 SGEQRT
  52. *> (Q is in blocked compact WY-representation). See the documentation
  53. *> of SGEQRT 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 REAL 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 REAL 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) REAL 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. *> LWORK is INTEGER
  134. *> The dimension of the array WORK.
  135. *> If MIN(M,N) = 0, LWORK >= 1, else
  136. *> LWORK >= MAX( 1, LWT + LW1, MAX( LWT+N*N+LW2, LWT+N*N+N ) ),
  137. *> where
  138. *> NUM_ALL_ROW_BLOCKS = CEIL((M-N)/(MB1-N)),
  139. *> NB1LOCAL = MIN(NB1,N).
  140. *> LWT = NUM_ALL_ROW_BLOCKS * N * NB1LOCAL,
  141. *> LW1 = NB1LOCAL * N,
  142. *> LW2 = NB1LOCAL * MAX( NB1LOCAL, ( N - NB1LOCAL ) ).
  143. *>
  144. *> If LWORK = -1, then a workspace query is assumed.
  145. *> The routine only calculates the optimal size of the WORK
  146. *> array, returns this value as the first entry of the WORK
  147. *> array, and no error message related to LWORK is issued
  148. *> by XERBLA.
  149. *> \endverbatim
  150. *>
  151. *> \param[out] INFO
  152. *> \verbatim
  153. *> INFO is INTEGER
  154. *> = 0: successful exit
  155. *> < 0: if INFO = -i, the i-th argument had an illegal value
  156. *> \endverbatim
  157. *
  158. * Authors:
  159. * ========
  160. *
  161. *> \author Univ. of Tennessee
  162. *> \author Univ. of California Berkeley
  163. *> \author Univ. of Colorado Denver
  164. *> \author NAG Ltd.
  165. *
  166. *> \ingroup getsqrhrt
  167. *
  168. *> \par Contributors:
  169. * ==================
  170. *>
  171. *> \verbatim
  172. *>
  173. *> November 2020, Igor Kozachenko,
  174. *> Computer Science Division,
  175. *> University of California, Berkeley
  176. *>
  177. *> \endverbatim
  178. *>
  179. * =====================================================================
  180. SUBROUTINE SGETSQRHRT( M, N, MB1, NB1, NB2, A, LDA, T, LDT, WORK,
  181. $ LWORK, INFO )
  182. IMPLICIT NONE
  183. *
  184. * -- LAPACK computational routine --
  185. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  186. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  187. *
  188. * .. Scalar Arguments ..
  189. INTEGER INFO, LDA, LDT, LWORK, M, N, NB1, NB2, MB1
  190. * ..
  191. * .. Array Arguments ..
  192. REAL A( LDA, * ), T( LDT, * ), WORK( * )
  193. * ..
  194. *
  195. * =====================================================================
  196. *
  197. * .. Parameters ..
  198. REAL ONE
  199. PARAMETER ( ONE = 1.0E+0 )
  200. * ..
  201. * .. Local Scalars ..
  202. LOGICAL LQUERY
  203. INTEGER I, IINFO, J, LW1, LW2, LWT, LDWT, LWORKOPT,
  204. $ NB1LOCAL, NB2LOCAL, NUM_ALL_ROW_BLOCKS
  205. * ..
  206. * .. External Functions ..
  207. REAL SROUNDUP_LWORK
  208. EXTERNAL SROUNDUP_LWORK
  209. * ..
  210. * .. External Subroutines ..
  211. EXTERNAL SCOPY, SLATSQR, SORGTSQR_ROW, SORHR_COL,
  212. $ XERBLA
  213. * ..
  214. * .. Intrinsic Functions ..
  215. INTRINSIC CEILING, MAX, MIN
  216. * ..
  217. * .. Executable Statements ..
  218. *
  219. * Test the input arguments
  220. *
  221. INFO = 0
  222. LQUERY = ( LWORK.EQ.-1 )
  223. IF( M.LT.0 ) THEN
  224. INFO = -1
  225. ELSE IF( N.LT.0 .OR. M.LT.N ) THEN
  226. INFO = -2
  227. ELSE IF( MB1.LE.N ) THEN
  228. INFO = -3
  229. ELSE IF( NB1.LT.1 ) THEN
  230. INFO = -4
  231. ELSE IF( NB2.LT.1 ) THEN
  232. INFO = -5
  233. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  234. INFO = -7
  235. ELSE IF( LDT.LT.MAX( 1, MIN( NB2, N ) ) ) THEN
  236. INFO = -9
  237. ELSE
  238. *
  239. * Test the input LWORK for the dimension of the array WORK.
  240. * This workspace is used to store array:
  241. * a) Matrix T and WORK for SLATSQR;
  242. * b) N-by-N upper-triangular factor R_tsqr;
  243. * c) Matrix T and array WORK for SORGTSQR_ROW;
  244. * d) Diagonal D for SORHR_COL.
  245. *
  246. IF( LWORK.LT.N*N+1 .AND. .NOT.LQUERY ) THEN
  247. INFO = -11
  248. ELSE
  249. *
  250. * Set block size for column blocks
  251. *
  252. NB1LOCAL = MIN( NB1, N )
  253. *
  254. NUM_ALL_ROW_BLOCKS = MAX( 1,
  255. $ CEILING( REAL( M - N ) / REAL( MB1 - N ) ) )
  256. *
  257. * Length and leading dimension of WORK array to place
  258. * T array in TSQR.
  259. *
  260. LWT = NUM_ALL_ROW_BLOCKS * N * NB1LOCAL
  261. LDWT = NB1LOCAL
  262. *
  263. * Length of TSQR work array
  264. *
  265. LW1 = NB1LOCAL * N
  266. *
  267. * Length of SORGTSQR_ROW work array.
  268. *
  269. LW2 = NB1LOCAL * MAX( NB1LOCAL, ( N - NB1LOCAL ) )
  270. *
  271. LWORKOPT = MAX( LWT + LW1, MAX( LWT+N*N+LW2, LWT+N*N+N ) )
  272. LWORKOPT = MAX( 1, LWORKOPT )
  273. *
  274. IF( LWORK.LT.LWORKOPT .AND. .NOT.LQUERY ) THEN
  275. INFO = -11
  276. END IF
  277. *
  278. END IF
  279. END IF
  280. *
  281. * Handle error in the input parameters and return workspace query.
  282. *
  283. IF( INFO.NE.0 ) THEN
  284. CALL XERBLA( 'SGETSQRHRT', -INFO )
  285. RETURN
  286. ELSE IF ( LQUERY ) THEN
  287. WORK( 1 ) = SROUNDUP_LWORK( LWORKOPT )
  288. RETURN
  289. END IF
  290. *
  291. * Quick return if possible
  292. *
  293. IF( MIN( M, N ).EQ.0 ) THEN
  294. WORK( 1 ) = SROUNDUP_LWORK( LWORKOPT )
  295. RETURN
  296. END IF
  297. *
  298. NB2LOCAL = MIN( NB2, N )
  299. *
  300. *
  301. * (1) Perform TSQR-factorization of the M-by-N matrix A.
  302. *
  303. CALL SLATSQR( M, N, MB1, NB1LOCAL, A, LDA, WORK, LDWT,
  304. $ WORK(LWT+1), LW1, IINFO )
  305. *
  306. * (2) Copy the factor R_tsqr stored in the upper-triangular part
  307. * of A into the square matrix in the work array
  308. * WORK(LWT+1:LWT+N*N) column-by-column.
  309. *
  310. DO J = 1, N
  311. CALL SCOPY( J, A( 1, J ), 1, WORK( LWT + N*(J-1)+1 ), 1 )
  312. END DO
  313. *
  314. * (3) Generate a M-by-N matrix Q with orthonormal columns from
  315. * the result stored below the diagonal in the array A in place.
  316. *
  317. CALL SORGTSQR_ROW( M, N, MB1, NB1LOCAL, A, LDA, WORK, LDWT,
  318. $ WORK( LWT+N*N+1 ), LW2, IINFO )
  319. *
  320. * (4) Perform the reconstruction of Householder vectors from
  321. * the matrix Q (stored in A) in place.
  322. *
  323. CALL SORHR_COL( M, N, NB2LOCAL, A, LDA, T, LDT,
  324. $ WORK( LWT+N*N+1 ), IINFO )
  325. *
  326. * (5) Copy the factor R_tsqr stored in the square matrix in the
  327. * work array WORK(LWT+1:LWT+N*N) into the upper-triangular
  328. * part of A.
  329. *
  330. * (6) Compute from R_tsqr the factor R_hr corresponding to
  331. * the reconstructed Householder vectors, i.e. R_hr = S * R_tsqr.
  332. * This multiplication by the sign matrix S on the left means
  333. * changing the sign of I-th row of the matrix R_tsqr according
  334. * to sign of the I-th diagonal element DIAG(I) of the matrix S.
  335. * DIAG is stored in WORK( LWT+N*N+1 ) from the SORHR_COL output.
  336. *
  337. * (5) and (6) can be combined in a single loop, so the rows in A
  338. * are accessed only once.
  339. *
  340. DO I = 1, N
  341. IF( WORK( LWT+N*N+I ).EQ.-ONE ) THEN
  342. DO J = I, N
  343. A( I, J ) = -ONE * WORK( LWT+N*(J-1)+I )
  344. END DO
  345. ELSE
  346. CALL SCOPY( N-I+1, WORK(LWT+N*(I-1)+I), N, A( I, I ), LDA )
  347. END IF
  348. END DO
  349. *
  350. WORK( 1 ) = SROUNDUP_LWORK( LWORKOPT )
  351. RETURN
  352. *
  353. * End of SGETSQRHRT
  354. *
  355. END