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.

claqps.f 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. *> \brief \b CLAQPS computes a step of QR factorization with column pivoting of a real m-by-n matrix A by using BLAS level 3.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CLAQPS + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/claqps.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/claqps.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/claqps.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CLAQPS( M, N, OFFSET, NB, KB, A, LDA, JPVT, TAU, VN1,
  22. * VN2, AUXV, F, LDF )
  23. *
  24. * .. Scalar Arguments ..
  25. * INTEGER KB, LDA, LDF, M, N, NB, OFFSET
  26. * ..
  27. * .. Array Arguments ..
  28. * INTEGER JPVT( * )
  29. * REAL VN1( * ), VN2( * )
  30. * COMPLEX A( LDA, * ), AUXV( * ), F( LDF, * ), TAU( * )
  31. * ..
  32. *
  33. *
  34. *> \par Purpose:
  35. * =============
  36. *>
  37. *> \verbatim
  38. *>
  39. *> CLAQPS computes a step of QR factorization with column pivoting
  40. *> of a complex M-by-N matrix A by using Blas-3. It tries to factorize
  41. *> NB columns from A starting from the row OFFSET+1, and updates all
  42. *> of the matrix with Blas-3 xGEMM.
  43. *>
  44. *> In some cases, due to catastrophic cancellations, it cannot
  45. *> factorize NB columns. Hence, the actual number of factorized
  46. *> columns is returned in KB.
  47. *>
  48. *> Block A(1:OFFSET,1:N) is accordingly pivoted, but not factorized.
  49. *> \endverbatim
  50. *
  51. * Arguments:
  52. * ==========
  53. *
  54. *> \param[in] M
  55. *> \verbatim
  56. *> M is INTEGER
  57. *> The number of rows of the matrix A. M >= 0.
  58. *> \endverbatim
  59. *>
  60. *> \param[in] N
  61. *> \verbatim
  62. *> N is INTEGER
  63. *> The number of columns of the matrix A. N >= 0
  64. *> \endverbatim
  65. *>
  66. *> \param[in] OFFSET
  67. *> \verbatim
  68. *> OFFSET is INTEGER
  69. *> The number of rows of A that have been factorized in
  70. *> previous steps.
  71. *> \endverbatim
  72. *>
  73. *> \param[in] NB
  74. *> \verbatim
  75. *> NB is INTEGER
  76. *> The number of columns to factorize.
  77. *> \endverbatim
  78. *>
  79. *> \param[out] KB
  80. *> \verbatim
  81. *> KB is INTEGER
  82. *> The number of columns actually factorized.
  83. *> \endverbatim
  84. *>
  85. *> \param[in,out] A
  86. *> \verbatim
  87. *> A is COMPLEX array, dimension (LDA,N)
  88. *> On entry, the M-by-N matrix A.
  89. *> On exit, block A(OFFSET+1:M,1:KB) is the triangular
  90. *> factor obtained and block A(1:OFFSET,1:N) has been
  91. *> accordingly pivoted, but no factorized.
  92. *> The rest of the matrix, block A(OFFSET+1:M,KB+1:N) has
  93. *> been updated.
  94. *> \endverbatim
  95. *>
  96. *> \param[in] LDA
  97. *> \verbatim
  98. *> LDA is INTEGER
  99. *> The leading dimension of the array A. LDA >= max(1,M).
  100. *> \endverbatim
  101. *>
  102. *> \param[in,out] JPVT
  103. *> \verbatim
  104. *> JPVT is INTEGER array, dimension (N)
  105. *> JPVT(I) = K <==> Column K of the full matrix A has been
  106. *> permuted into position I in AP.
  107. *> \endverbatim
  108. *>
  109. *> \param[out] TAU
  110. *> \verbatim
  111. *> TAU is COMPLEX array, dimension (KB)
  112. *> The scalar factors of the elementary reflectors.
  113. *> \endverbatim
  114. *>
  115. *> \param[in,out] VN1
  116. *> \verbatim
  117. *> VN1 is REAL array, dimension (N)
  118. *> The vector with the partial column norms.
  119. *> \endverbatim
  120. *>
  121. *> \param[in,out] VN2
  122. *> \verbatim
  123. *> VN2 is REAL array, dimension (N)
  124. *> The vector with the exact column norms.
  125. *> \endverbatim
  126. *>
  127. *> \param[in,out] AUXV
  128. *> \verbatim
  129. *> AUXV is COMPLEX array, dimension (NB)
  130. *> Auxiliary vector.
  131. *> \endverbatim
  132. *>
  133. *> \param[in,out] F
  134. *> \verbatim
  135. *> F is COMPLEX array, dimension (LDF,NB)
  136. *> Matrix F**H = L * Y**H * A.
  137. *> \endverbatim
  138. *>
  139. *> \param[in] LDF
  140. *> \verbatim
  141. *> LDF is INTEGER
  142. *> The leading dimension of the array F. LDF >= max(1,N).
  143. *> \endverbatim
  144. *
  145. * Authors:
  146. * ========
  147. *
  148. *> \author Univ. of Tennessee
  149. *> \author Univ. of California Berkeley
  150. *> \author Univ. of Colorado Denver
  151. *> \author NAG Ltd.
  152. *
  153. *> \date December 2016
  154. *
  155. *> \ingroup complexOTHERauxiliary
  156. *
  157. *> \par Contributors:
  158. * ==================
  159. *>
  160. *> G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain
  161. *> X. Sun, Computer Science Dept., Duke University, USA
  162. *>
  163. *> \n
  164. *> Partial column norm updating strategy modified on April 2011
  165. *> Z. Drmac and Z. Bujanovic, Dept. of Mathematics,
  166. *> University of Zagreb, Croatia.
  167. *
  168. *> \par References:
  169. * ================
  170. *>
  171. *> LAPACK Working Note 176
  172. *
  173. *> \htmlonly
  174. *> <a href="http://www.netlib.org/lapack/lawnspdf/lawn176.pdf">[PDF]</a>
  175. *> \endhtmlonly
  176. *
  177. * =====================================================================
  178. SUBROUTINE CLAQPS( M, N, OFFSET, NB, KB, A, LDA, JPVT, TAU, VN1,
  179. $ VN2, AUXV, F, LDF )
  180. *
  181. * -- LAPACK auxiliary routine (version 3.7.0) --
  182. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  183. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  184. * December 2016
  185. *
  186. * .. Scalar Arguments ..
  187. INTEGER KB, LDA, LDF, M, N, NB, OFFSET
  188. * ..
  189. * .. Array Arguments ..
  190. INTEGER JPVT( * )
  191. REAL VN1( * ), VN2( * )
  192. COMPLEX A( LDA, * ), AUXV( * ), F( LDF, * ), TAU( * )
  193. * ..
  194. *
  195. * =====================================================================
  196. *
  197. * .. Parameters ..
  198. REAL ZERO, ONE
  199. COMPLEX CZERO, CONE
  200. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0,
  201. $ CZERO = ( 0.0E+0, 0.0E+0 ),
  202. $ CONE = ( 1.0E+0, 0.0E+0 ) )
  203. * ..
  204. * .. Local Scalars ..
  205. INTEGER ITEMP, J, K, LASTRK, LSTICC, PVT, RK
  206. REAL TEMP, TEMP2, TOL3Z
  207. COMPLEX AKK
  208. * ..
  209. * .. External Subroutines ..
  210. EXTERNAL CGEMM, CGEMV, CLARFG, CSWAP
  211. * ..
  212. * .. Intrinsic Functions ..
  213. INTRINSIC ABS, CONJG, MAX, MIN, NINT, REAL, SQRT
  214. * ..
  215. * .. External Functions ..
  216. INTEGER ISAMAX
  217. REAL SCNRM2, SLAMCH
  218. EXTERNAL ISAMAX, SCNRM2, SLAMCH
  219. * ..
  220. * .. Executable Statements ..
  221. *
  222. LASTRK = MIN( M, N+OFFSET )
  223. LSTICC = 0
  224. K = 0
  225. TOL3Z = SQRT(SLAMCH('Epsilon'))
  226. *
  227. * Beginning of while loop.
  228. *
  229. 10 CONTINUE
  230. IF( ( K.LT.NB ) .AND. ( LSTICC.EQ.0 ) ) THEN
  231. K = K + 1
  232. RK = OFFSET + K
  233. *
  234. * Determine ith pivot column and swap if necessary
  235. *
  236. PVT = ( K-1 ) + ISAMAX( N-K+1, VN1( K ), 1 )
  237. IF( PVT.NE.K ) THEN
  238. CALL CSWAP( M, A( 1, PVT ), 1, A( 1, K ), 1 )
  239. CALL CSWAP( K-1, F( PVT, 1 ), LDF, F( K, 1 ), LDF )
  240. ITEMP = JPVT( PVT )
  241. JPVT( PVT ) = JPVT( K )
  242. JPVT( K ) = ITEMP
  243. VN1( PVT ) = VN1( K )
  244. VN2( PVT ) = VN2( K )
  245. END IF
  246. *
  247. * Apply previous Householder reflectors to column K:
  248. * A(RK:M,K) := A(RK:M,K) - A(RK:M,1:K-1)*F(K,1:K-1)**H.
  249. *
  250. IF( K.GT.1 ) THEN
  251. DO 20 J = 1, K - 1
  252. F( K, J ) = CONJG( F( K, J ) )
  253. 20 CONTINUE
  254. CALL CGEMV( 'No transpose', M-RK+1, K-1, -CONE, A( RK, 1 ),
  255. $ LDA, F( K, 1 ), LDF, CONE, A( RK, K ), 1 )
  256. DO 30 J = 1, K - 1
  257. F( K, J ) = CONJG( F( K, J ) )
  258. 30 CONTINUE
  259. END IF
  260. *
  261. * Generate elementary reflector H(k).
  262. *
  263. IF( RK.LT.M ) THEN
  264. CALL CLARFG( M-RK+1, A( RK, K ), A( RK+1, K ), 1, TAU( K ) )
  265. ELSE
  266. CALL CLARFG( 1, A( RK, K ), A( RK, K ), 1, TAU( K ) )
  267. END IF
  268. *
  269. AKK = A( RK, K )
  270. A( RK, K ) = CONE
  271. *
  272. * Compute Kth column of F:
  273. *
  274. * Compute F(K+1:N,K) := tau(K)*A(RK:M,K+1:N)**H*A(RK:M,K).
  275. *
  276. IF( K.LT.N ) THEN
  277. CALL CGEMV( 'Conjugate transpose', M-RK+1, N-K, TAU( K ),
  278. $ A( RK, K+1 ), LDA, A( RK, K ), 1, CZERO,
  279. $ F( K+1, K ), 1 )
  280. END IF
  281. *
  282. * Padding F(1:K,K) with zeros.
  283. *
  284. DO 40 J = 1, K
  285. F( J, K ) = CZERO
  286. 40 CONTINUE
  287. *
  288. * Incremental updating of F:
  289. * F(1:N,K) := F(1:N,K) - tau(K)*F(1:N,1:K-1)*A(RK:M,1:K-1)**H
  290. * *A(RK:M,K).
  291. *
  292. IF( K.GT.1 ) THEN
  293. CALL CGEMV( 'Conjugate transpose', M-RK+1, K-1, -TAU( K ),
  294. $ A( RK, 1 ), LDA, A( RK, K ), 1, CZERO,
  295. $ AUXV( 1 ), 1 )
  296. *
  297. CALL CGEMV( 'No transpose', N, K-1, CONE, F( 1, 1 ), LDF,
  298. $ AUXV( 1 ), 1, CONE, F( 1, K ), 1 )
  299. END IF
  300. *
  301. * Update the current row of A:
  302. * A(RK,K+1:N) := A(RK,K+1:N) - A(RK,1:K)*F(K+1:N,1:K)**H.
  303. *
  304. IF( K.LT.N ) THEN
  305. CALL CGEMM( 'No transpose', 'Conjugate transpose', 1, N-K,
  306. $ K, -CONE, A( RK, 1 ), LDA, F( K+1, 1 ), LDF,
  307. $ CONE, A( RK, K+1 ), LDA )
  308. END IF
  309. *
  310. * Update partial column norms.
  311. *
  312. IF( RK.LT.LASTRK ) THEN
  313. DO 50 J = K + 1, N
  314. IF( VN1( J ).NE.ZERO ) THEN
  315. *
  316. * NOTE: The following 4 lines follow from the analysis in
  317. * Lapack Working Note 176.
  318. *
  319. TEMP = ABS( A( RK, J ) ) / VN1( J )
  320. TEMP = MAX( ZERO, ( ONE+TEMP )*( ONE-TEMP ) )
  321. TEMP2 = TEMP*( VN1( J ) / VN2( J ) )**2
  322. IF( TEMP2 .LE. TOL3Z ) THEN
  323. VN2( J ) = REAL( LSTICC )
  324. LSTICC = J
  325. ELSE
  326. VN1( J ) = VN1( J )*SQRT( TEMP )
  327. END IF
  328. END IF
  329. 50 CONTINUE
  330. END IF
  331. *
  332. A( RK, K ) = AKK
  333. *
  334. * End of while loop.
  335. *
  336. GO TO 10
  337. END IF
  338. KB = K
  339. RK = OFFSET + KB
  340. *
  341. * Apply the block reflector to the rest of the matrix:
  342. * A(OFFSET+KB+1:M,KB+1:N) := A(OFFSET+KB+1:M,KB+1:N) -
  343. * A(OFFSET+KB+1:M,1:KB)*F(KB+1:N,1:KB)**H.
  344. *
  345. IF( KB.LT.MIN( N, M-OFFSET ) ) THEN
  346. CALL CGEMM( 'No transpose', 'Conjugate transpose', M-RK, N-KB,
  347. $ KB, -CONE, A( RK+1, 1 ), LDA, F( KB+1, 1 ), LDF,
  348. $ CONE, A( RK+1, KB+1 ), LDA )
  349. END IF
  350. *
  351. * Recomputation of difficult columns.
  352. *
  353. 60 CONTINUE
  354. IF( LSTICC.GT.0 ) THEN
  355. ITEMP = NINT( VN2( LSTICC ) )
  356. VN1( LSTICC ) = SCNRM2( M-RK, A( RK+1, LSTICC ), 1 )
  357. *
  358. * NOTE: The computation of VN1( LSTICC ) relies on the fact that
  359. * SNRM2 does not fail on vectors with norm below the value of
  360. * SQRT(DLAMCH('S'))
  361. *
  362. VN2( LSTICC ) = VN1( LSTICC )
  363. LSTICC = ITEMP
  364. GO TO 60
  365. END IF
  366. *
  367. RETURN
  368. *
  369. * End of CLAQPS
  370. *
  371. END