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.

sqpt01.f 5.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. *> \brief \b SQPT01
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * REAL FUNCTION SQPT01( M, N, K, A, AF, LDA, TAU, JPVT,
  12. * WORK, LWORK )
  13. *
  14. * .. Scalar Arguments ..
  15. * INTEGER K, LDA, LWORK, M, N
  16. * ..
  17. * .. Array Arguments ..
  18. * INTEGER JPVT( * )
  19. * REAL A( LDA, * ), AF( LDA, * ), TAU( * ),
  20. * $ WORK( LWORK )
  21. * ..
  22. *
  23. *
  24. *> \par Purpose:
  25. * =============
  26. *>
  27. *> \verbatim
  28. *>
  29. *> SQPT01 tests the QR-factorization with pivoting of a matrix A. The
  30. *> array AF contains the (possibly partial) QR-factorization of A, where
  31. *> the upper triangle of AF(1:k,1:k) is a partial triangular factor,
  32. *> the entries below the diagonal in the first k columns are the
  33. *> Householder vectors, and the rest of AF contains a partially updated
  34. *> matrix.
  35. *>
  36. *> This function returns ||A*P - Q*R|| / ( ||norm(A)||*eps*max(M,N) )
  37. *> where || . || is matrix one norm.
  38. *> \endverbatim
  39. *
  40. * Arguments:
  41. * ==========
  42. *
  43. *> \param[in] M
  44. *> \verbatim
  45. *> M is INTEGER
  46. *> The number of rows of the matrices A and AF.
  47. *> \endverbatim
  48. *>
  49. *> \param[in] N
  50. *> \verbatim
  51. *> N is INTEGER
  52. *> The number of columns of the matrices A and AF.
  53. *> \endverbatim
  54. *>
  55. *> \param[in] K
  56. *> \verbatim
  57. *> K is INTEGER
  58. *> The number of columns of AF that have been reduced
  59. *> to upper triangular form.
  60. *> \endverbatim
  61. *>
  62. *> \param[in] A
  63. *> \verbatim
  64. *> A is REAL array, dimension (LDA, N)
  65. *> The original matrix A.
  66. *> \endverbatim
  67. *>
  68. *> \param[in] AF
  69. *> \verbatim
  70. *> AF is REAL array, dimension (LDA,N)
  71. *> The (possibly partial) output of SGEQPF. The upper triangle
  72. *> of AF(1:k,1:k) is a partial triangular factor, the entries
  73. *> below the diagonal in the first k columns are the Householder
  74. *> vectors, and the rest of AF contains a partially updated
  75. *> matrix.
  76. *> \endverbatim
  77. *>
  78. *> \param[in] LDA
  79. *> \verbatim
  80. *> LDA is INTEGER
  81. *> The leading dimension of the arrays A and AF.
  82. *> \endverbatim
  83. *>
  84. *> \param[in] TAU
  85. *> \verbatim
  86. *> TAU is REAL array, dimension (K)
  87. *> Details of the Householder transformations as returned by
  88. *> SGEQPF.
  89. *> \endverbatim
  90. *>
  91. *> \param[in] JPVT
  92. *> \verbatim
  93. *> JPVT is INTEGER array, dimension (N)
  94. *> Pivot information as returned by SGEQPF.
  95. *> \endverbatim
  96. *>
  97. *> \param[out] WORK
  98. *> \verbatim
  99. *> WORK is REAL array, dimension (LWORK)
  100. *> \endverbatim
  101. *>
  102. *> \param[in] LWORK
  103. *> \verbatim
  104. *> LWORK is INTEGER
  105. *> The length of the array WORK. LWORK >= M*N+N.
  106. *> \endverbatim
  107. *
  108. * Authors:
  109. * ========
  110. *
  111. *> \author Univ. of Tennessee
  112. *> \author Univ. of California Berkeley
  113. *> \author Univ. of Colorado Denver
  114. *> \author NAG Ltd.
  115. *
  116. *> \ingroup single_lin
  117. *
  118. * =====================================================================
  119. REAL FUNCTION SQPT01( M, N, K, A, AF, LDA, TAU, JPVT,
  120. $ WORK, LWORK )
  121. *
  122. * -- LAPACK test routine --
  123. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  124. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  125. *
  126. * .. Scalar Arguments ..
  127. INTEGER K, LDA, LWORK, M, N
  128. * ..
  129. * .. Array Arguments ..
  130. INTEGER JPVT( * )
  131. REAL A( LDA, * ), AF( LDA, * ), TAU( * ),
  132. $ WORK( LWORK )
  133. * ..
  134. *
  135. * =====================================================================
  136. *
  137. * .. Parameters ..
  138. REAL ZERO, ONE
  139. PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
  140. * ..
  141. * .. Local Scalars ..
  142. INTEGER I, INFO, J
  143. REAL NORMA
  144. * ..
  145. * .. Local Arrays ..
  146. REAL RWORK( 1 )
  147. * ..
  148. * .. External Functions ..
  149. REAL SLAMCH, SLANGE
  150. EXTERNAL SLAMCH, SLANGE
  151. * ..
  152. * .. External Subroutines ..
  153. EXTERNAL SAXPY, SCOPY, SORMQR, XERBLA
  154. * ..
  155. * .. Intrinsic Functions ..
  156. INTRINSIC MAX, MIN, REAL
  157. * ..
  158. * .. Executable Statements ..
  159. *
  160. SQPT01 = ZERO
  161. *
  162. * Test if there is enough workspace
  163. *
  164. IF( LWORK.LT.M*N+N ) THEN
  165. CALL XERBLA( 'SQPT01', 10 )
  166. RETURN
  167. END IF
  168. *
  169. * Quick return if possible
  170. *
  171. IF( M.LE.0 .OR. N.LE.0 )
  172. $ RETURN
  173. *
  174. NORMA = SLANGE( 'One-norm', M, N, A, LDA, RWORK )
  175. *
  176. DO J = 1, K
  177. DO I = 1, MIN( J, M )
  178. WORK( ( J-1 )*M+I ) = AF( I, J )
  179. END DO
  180. DO I = J + 1, M
  181. WORK( ( J-1 )*M+I ) = ZERO
  182. END DO
  183. END DO
  184. DO J = K + 1, N
  185. CALL SCOPY( M, AF( 1, J ), 1, WORK( ( J-1 )*M+1 ), 1 )
  186. END DO
  187. *
  188. CALL SORMQR( 'Left', 'No transpose', M, N, K, AF, LDA, TAU, WORK,
  189. $ M, WORK( M*N+1 ), LWORK-M*N, INFO )
  190. *
  191. DO J = 1, N
  192. *
  193. * Compare i-th column of QR and jpvt(i)-th column of A
  194. *
  195. CALL SAXPY( M, -ONE, A( 1, JPVT( J ) ), 1, WORK( ( J-1 )*M+1 ),
  196. $ 1 )
  197. END DO
  198. *
  199. SQPT01 = SLANGE( 'One-norm', M, N, WORK, M, RWORK ) /
  200. $ ( REAL( MAX( M, N ) )*SLAMCH( 'Epsilon' ) )
  201. IF( NORMA.NE.ZERO )
  202. $ SQPT01 = SQPT01 / NORMA
  203. *
  204. RETURN
  205. *
  206. * End of SQPT01
  207. *
  208. END