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.

dgeqrfp.f 8.0 kB

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