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.

cgelq.f 10 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. *> \brief \b CGELQ
  2. *
  3. * Definition:
  4. * ===========
  5. *
  6. * SUBROUTINE CGELQ( M, N, A, LDA, T, TSIZE, WORK, LWORK,
  7. * INFO )
  8. *
  9. * .. Scalar Arguments ..
  10. * INTEGER INFO, LDA, M, N, TSIZE, LWORK
  11. * ..
  12. * .. Array Arguments ..
  13. * COMPLEX A( LDA, * ), T( * ), WORK( * )
  14. * ..
  15. *
  16. *
  17. *> \par Purpose:
  18. * =============
  19. *>
  20. *> \verbatim
  21. *>
  22. *> CGELQ computes an LQ factorization of a complex M-by-N matrix A:
  23. *>
  24. *> A = ( L 0 ) * Q
  25. *>
  26. *> where:
  27. *>
  28. *> Q is a N-by-N orthogonal matrix;
  29. *> L is a lower-triangular M-by-M matrix;
  30. *> 0 is a M-by-(N-M) zero matrix, if M < N.
  31. *>
  32. *> \endverbatim
  33. *
  34. * Arguments:
  35. * ==========
  36. *
  37. *> \param[in] M
  38. *> \verbatim
  39. *> M is INTEGER
  40. *> The number of rows of the matrix A. M >= 0.
  41. *> \endverbatim
  42. *>
  43. *> \param[in] N
  44. *> \verbatim
  45. *> N is INTEGER
  46. *> The number of columns of the matrix A. N >= 0.
  47. *> \endverbatim
  48. *>
  49. *> \param[in,out] A
  50. *> \verbatim
  51. *> A is COMPLEX array, dimension (LDA,N)
  52. *> On entry, the M-by-N matrix A.
  53. *> On exit, the elements on and below the diagonal of the array
  54. *> contain the M-by-min(M,N) lower trapezoidal matrix L
  55. *> (L is lower triangular if M <= N);
  56. *> the elements above the diagonal are used to store part of the
  57. *> data structure to represent Q.
  58. *> \endverbatim
  59. *>
  60. *> \param[in] LDA
  61. *> \verbatim
  62. *> LDA is INTEGER
  63. *> The leading dimension of the array A. LDA >= max(1,M).
  64. *> \endverbatim
  65. *>
  66. *> \param[out] T
  67. *> \verbatim
  68. *> T is COMPLEX array, dimension (MAX(5,TSIZE))
  69. *> On exit, if INFO = 0, T(1) returns optimal (or either minimal
  70. *> or optimal, if query is assumed) TSIZE. See TSIZE for details.
  71. *> Remaining T contains part of the data structure used to represent Q.
  72. *> If one wants to apply or construct Q, then one needs to keep T
  73. *> (in addition to A) and pass it to further subroutines.
  74. *> \endverbatim
  75. *>
  76. *> \param[in] TSIZE
  77. *> \verbatim
  78. *> TSIZE is INTEGER
  79. *> If TSIZE >= 5, the dimension of the array T.
  80. *> If TSIZE = -1 or -2, then a workspace query is assumed. The routine
  81. *> only calculates the sizes of the T and WORK arrays, returns these
  82. *> values as the first entries of the T and WORK arrays, and no error
  83. *> message related to T or WORK is issued by XERBLA.
  84. *> If TSIZE = -1, the routine calculates optimal size of T for the
  85. *> optimum performance and returns this value in T(1).
  86. *> If TSIZE = -2, the routine calculates minimal size of T and
  87. *> returns this value in T(1).
  88. *> \endverbatim
  89. *>
  90. *> \param[out] WORK
  91. *> \verbatim
  92. *> (workspace) COMPLEX array, dimension (MAX(1,LWORK))
  93. *> On exit, if INFO = 0, WORK(1) contains optimal (or either minimal
  94. *> or optimal, if query was assumed) LWORK.
  95. *> See LWORK for details.
  96. *> \endverbatim
  97. *>
  98. *> \param[in] LWORK
  99. *> \verbatim
  100. *> LWORK is INTEGER
  101. *> The dimension of the array WORK. LWORK >= 1.
  102. *> If LWORK = -1 or -2, then a workspace query is assumed. The routine
  103. *> only calculates the sizes of the T and WORK arrays, returns these
  104. *> values as the first entries of the T and WORK arrays, and no error
  105. *> message related to T or WORK is issued by XERBLA.
  106. *> If LWORK = -1, the routine calculates optimal size of WORK for the
  107. *> optimal performance and returns this value in WORK(1).
  108. *> If LWORK = -2, the routine calculates minimal size of WORK and
  109. *> returns this value in WORK(1).
  110. *> \endverbatim
  111. *>
  112. *> \param[out] INFO
  113. *> \verbatim
  114. *> INFO is INTEGER
  115. *> = 0: successful exit
  116. *> < 0: if INFO = -i, the i-th argument had an illegal value
  117. *> \endverbatim
  118. *
  119. * Authors:
  120. * ========
  121. *
  122. *> \author Univ. of Tennessee
  123. *> \author Univ. of California Berkeley
  124. *> \author Univ. of Colorado Denver
  125. *> \author NAG Ltd.
  126. *
  127. *> \par Further Details
  128. * ====================
  129. *>
  130. *> \verbatim
  131. *>
  132. *> The goal of the interface is to give maximum freedom to the developers for
  133. *> creating any LQ factorization algorithm they wish. The triangular
  134. *> (trapezoidal) L has to be stored in the lower part of A. The lower part of A
  135. *> and the array T can be used to store any relevant information for applying or
  136. *> constructing the Q factor. The WORK array can safely be discarded after exit.
  137. *>
  138. *> Caution: One should not expect the sizes of T and WORK to be the same from one
  139. *> LAPACK implementation to the other, or even from one execution to the other.
  140. *> A workspace query (for T and WORK) is needed at each execution. However,
  141. *> for a given execution, the size of T and WORK are fixed and will not change
  142. *> from one query to the next.
  143. *>
  144. *> \endverbatim
  145. *>
  146. *> \par Further Details particular to this LAPACK implementation:
  147. * ==============================================================
  148. *>
  149. *> \verbatim
  150. *>
  151. *> These details are particular for this LAPACK implementation. Users should not
  152. *> take them for granted. These details may change in the future, and are not likely
  153. *> true for another LAPACK implementation. These details are relevant if one wants
  154. *> to try to understand the code. They are not part of the interface.
  155. *>
  156. *> In this version,
  157. *>
  158. *> T(2): row block size (MB)
  159. *> T(3): column block size (NB)
  160. *> T(6:TSIZE): data structure needed for Q, computed by
  161. *> CLASWLQ or CGELQT
  162. *>
  163. *> Depending on the matrix dimensions M and N, and row and column
  164. *> block sizes MB and NB returned by ILAENV, CGELQ will use either
  165. *> CLASWLQ (if the matrix is short-and-wide) or CGELQT to compute
  166. *> the LQ factorization.
  167. *> \endverbatim
  168. *>
  169. *> \ingroup gelq
  170. *>
  171. * =====================================================================
  172. SUBROUTINE CGELQ( M, N, A, LDA, T, TSIZE, WORK, LWORK,
  173. $ INFO )
  174. *
  175. * -- LAPACK computational routine --
  176. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  177. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd. --
  178. *
  179. * .. Scalar Arguments ..
  180. INTEGER INFO, LDA, M, N, TSIZE, LWORK
  181. * ..
  182. * .. Array Arguments ..
  183. COMPLEX A( LDA, * ), T( * ), WORK( * )
  184. * ..
  185. *
  186. * =====================================================================
  187. *
  188. * ..
  189. * .. Local Scalars ..
  190. LOGICAL LQUERY, LMINWS, MINT, MINW
  191. INTEGER MB, NB, MINTSZ, NBLCKS, LWMIN, LWOPT, LWREQ
  192. * ..
  193. * .. External Functions ..
  194. LOGICAL LSAME
  195. REAL SROUNDUP_LWORK
  196. EXTERNAL LSAME, SROUNDUP_LWORK
  197. * ..
  198. * .. External Subroutines ..
  199. EXTERNAL CGELQT, CLASWLQ, XERBLA
  200. * ..
  201. * .. Intrinsic Functions ..
  202. INTRINSIC MAX, MIN, MOD
  203. * ..
  204. * .. External Functions ..
  205. INTEGER ILAENV
  206. EXTERNAL ILAENV
  207. * ..
  208. * .. Executable Statements ..
  209. *
  210. * Test the input arguments
  211. *
  212. INFO = 0
  213. *
  214. LQUERY = ( TSIZE.EQ.-1 .OR. TSIZE.EQ.-2 .OR.
  215. $ LWORK.EQ.-1 .OR. LWORK.EQ.-2 )
  216. *
  217. MINT = .FALSE.
  218. MINW = .FALSE.
  219. IF( TSIZE.EQ.-2 .OR. LWORK.EQ.-2 ) THEN
  220. IF( TSIZE.NE.-1 ) MINT = .TRUE.
  221. IF( LWORK.NE.-1 ) MINW = .TRUE.
  222. END IF
  223. *
  224. * Determine the block size
  225. *
  226. IF( MIN( M, N ).GT.0 ) THEN
  227. MB = ILAENV( 1, 'CGELQ ', ' ', M, N, 1, -1 )
  228. NB = ILAENV( 1, 'CGELQ ', ' ', M, N, 2, -1 )
  229. ELSE
  230. MB = 1
  231. NB = N
  232. END IF
  233. IF( MB.GT.MIN( M, N ) .OR. MB.LT.1 ) MB = 1
  234. IF( NB.GT.N .OR. NB.LE.M ) NB = N
  235. MINTSZ = M + 5
  236. IF( NB.GT.M .AND. N.GT.M ) THEN
  237. IF( MOD( N - M, NB - M ).EQ.0 ) THEN
  238. NBLCKS = ( N - M ) / ( NB - M )
  239. ELSE
  240. NBLCKS = ( N - M ) / ( NB - M ) + 1
  241. END IF
  242. ELSE
  243. NBLCKS = 1
  244. END IF
  245. *
  246. * Determine if the workspace size satisfies minimal size
  247. *
  248. IF( ( N.LE.M ) .OR. ( NB.LE.M ) .OR. ( NB.GE.N ) ) THEN
  249. LWMIN = MAX( 1, N )
  250. LWOPT = MAX( 1, MB*N )
  251. ELSE
  252. LWMIN = MAX( 1, M )
  253. LWOPT = MAX( 1, MB*M )
  254. END IF
  255. LMINWS = .FALSE.
  256. IF( ( TSIZE.LT.MAX( 1, MB*M*NBLCKS + 5 ) .OR. LWORK.LT.LWOPT )
  257. $ .AND. ( LWORK.GE.LWMIN ) .AND. ( TSIZE.GE.MINTSZ )
  258. $ .AND. ( .NOT.LQUERY ) ) THEN
  259. IF( TSIZE.LT.MAX( 1, MB*M*NBLCKS + 5 ) ) THEN
  260. LMINWS = .TRUE.
  261. MB = 1
  262. NB = N
  263. END IF
  264. IF( LWORK.LT.LWOPT ) THEN
  265. LMINWS = .TRUE.
  266. MB = 1
  267. END IF
  268. END IF
  269. IF( ( N.LE.M ) .OR. ( NB.LE.M ) .OR. ( NB.GE.N ) ) THEN
  270. LWREQ = MAX( 1, MB*N )
  271. ELSE
  272. LWREQ = MAX( 1, MB*M )
  273. END IF
  274. *
  275. IF( M.LT.0 ) THEN
  276. INFO = -1
  277. ELSE IF( N.LT.0 ) THEN
  278. INFO = -2
  279. ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  280. INFO = -4
  281. ELSE IF( TSIZE.LT.MAX( 1, MB*M*NBLCKS + 5 )
  282. $ .AND. ( .NOT.LQUERY ) .AND. ( .NOT.LMINWS ) ) THEN
  283. INFO = -6
  284. ELSE IF( ( LWORK.LT.LWREQ ) .AND .( .NOT.LQUERY )
  285. $ .AND. ( .NOT.LMINWS ) ) THEN
  286. INFO = -8
  287. END IF
  288. *
  289. IF( INFO.EQ.0 ) THEN
  290. IF( MINT ) THEN
  291. T( 1 ) = MINTSZ
  292. ELSE
  293. T( 1 ) = MB*M*NBLCKS + 5
  294. END IF
  295. T( 2 ) = MB
  296. T( 3 ) = NB
  297. IF( MINW ) THEN
  298. WORK( 1 ) = SROUNDUP_LWORK( LWMIN )
  299. ELSE
  300. WORK( 1 ) = SROUNDUP_LWORK( LWREQ )
  301. END IF
  302. END IF
  303. IF( INFO.NE.0 ) THEN
  304. CALL XERBLA( 'CGELQ', -INFO )
  305. RETURN
  306. ELSE IF( LQUERY ) THEN
  307. RETURN
  308. END IF
  309. *
  310. * Quick return if possible
  311. *
  312. IF( MIN( M, N ).EQ.0 ) THEN
  313. RETURN
  314. END IF
  315. *
  316. * The LQ Decomposition
  317. *
  318. IF( ( N.LE.M ) .OR. ( NB.LE.M ) .OR. ( NB.GE.N ) ) THEN
  319. CALL CGELQT( M, N, MB, A, LDA, T( 6 ), MB, WORK, INFO )
  320. ELSE
  321. CALL CLASWLQ( M, N, MB, NB, A, LDA, T( 6 ), MB, WORK,
  322. $ LWORK, INFO )
  323. END IF
  324. *
  325. WORK( 1 ) = SROUNDUP_LWORK( LWREQ )
  326. *
  327. RETURN
  328. *
  329. * End of CGELQ
  330. *
  331. END