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.

cbdt05.f 5.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. * =========== DOCUMENTATION ===========
  2. *
  3. * Online html documentation available at
  4. * http://www.netlib.org/lapack/explore-html/
  5. *
  6. * Definition:
  7. * ===========
  8. *
  9. * SUBROUTINE CBDT05( M, N, A, LDA, S, NS, U, LDU,
  10. * VT, LDVT, WORK, RESID )
  11. *
  12. * .. Scalar Arguments ..
  13. * INTEGER LDA, LDU, LDVT, N, NS
  14. * REAL RESID
  15. * ..
  16. * .. Array Arguments ..
  17. * REAL S( * )
  18. * COMPLEX A( LDA, * ), U( * ), VT( LDVT, * ), WORK( * )
  19. * ..
  20. *
  21. *> \par Purpose:
  22. * =============
  23. *>
  24. *> \verbatim
  25. *>
  26. *> CBDT05 reconstructs a bidiagonal matrix B from its (partial) SVD:
  27. *> S = U' * B * V
  28. *> where U and V are orthogonal matrices and S is diagonal.
  29. *>
  30. *> The test ratio to test the singular value decomposition is
  31. *> RESID = norm( S - U' * B * V ) / ( n * norm(B) * EPS )
  32. *> where VT = V' and EPS is the machine precision.
  33. *> \endverbatim
  34. *
  35. * Arguments:
  36. * ==========
  37. *
  38. *> \param[in] M
  39. *> \verbatim
  40. *> M is INTEGER
  41. *> The number of rows of the matrices A and U.
  42. *> \endverbatim
  43. *>
  44. *> \param[in] N
  45. *> \verbatim
  46. *> N is INTEGER
  47. *> The number of columns of the matrices A and VT.
  48. *> \endverbatim
  49. *>
  50. *> \param[in] A
  51. *> \verbatim
  52. *> A is COMPLEX array, dimension (LDA,N)
  53. *> The m by n matrix A.
  54. *>
  55. *> \param[in] LDA
  56. *> \verbatim
  57. *> LDA is INTEGER
  58. *> The leading dimension of the array A. LDA >= max(1,M).
  59. *> \endverbatim
  60. *>
  61. *> \param[in] S
  62. *> \verbatim
  63. *> S is REAL array, dimension (NS)
  64. *> The singular values from the (partial) SVD of B, sorted in
  65. *> decreasing order.
  66. *> \endverbatim
  67. *>
  68. *> \param[in] NS
  69. *> \verbatim
  70. *> NS is INTEGER
  71. *> The number of singular values/vectors from the (partial)
  72. *> SVD of B.
  73. *> \endverbatim
  74. *>
  75. *> \param[in] U
  76. *> \verbatim
  77. *> U is COMPLEX array, dimension (LDU,NS)
  78. *> The n by ns orthogonal matrix U in S = U' * B * V.
  79. *> \endverbatim
  80. *>
  81. *> \param[in] LDU
  82. *> \verbatim
  83. *> LDU is INTEGER
  84. *> The leading dimension of the array U. LDU >= max(1,N)
  85. *> \endverbatim
  86. *>
  87. *> \param[in] VT
  88. *> \verbatim
  89. *> VT is COMPLEX array, dimension (LDVT,N)
  90. *> The n by ns orthogonal matrix V in S = U' * B * V.
  91. *> \endverbatim
  92. *>
  93. *> \param[in] LDVT
  94. *> \verbatim
  95. *> LDVT is INTEGER
  96. *> The leading dimension of the array VT.
  97. *> \endverbatim
  98. *>
  99. *> \param[out] WORK
  100. *> \verbatim
  101. *> WORK is COMPLEX array, dimension (M,N)
  102. *> \endverbatim
  103. *>
  104. *> \param[out] RESID
  105. *> \verbatim
  106. *> RESID is REAL
  107. *> The test ratio: norm(S - U' * A * V) / ( n * norm(A) * EPS )
  108. *> \endverbatim
  109. *
  110. * Authors:
  111. * ========
  112. *
  113. *> \author Univ. of Tennessee
  114. *> \author Univ. of California Berkeley
  115. *> \author Univ. of Colorado Denver
  116. *> \author NAG Ltd.
  117. *
  118. *> \date November 2011
  119. *
  120. *> \ingroup double_eig
  121. *
  122. * =====================================================================
  123. SUBROUTINE CBDT05( M, N, A, LDA, S, NS, U, LDU,
  124. $ VT, LDVT, WORK, RESID )
  125. *
  126. * -- LAPACK test routine (version 3.4.0) --
  127. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  128. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  129. * November 2011
  130. *
  131. * .. Scalar Arguments ..
  132. CHARACTER UPLO
  133. INTEGER LDA, LDU, LDVT, M, N, NS
  134. REAL RESID
  135. * ..
  136. * .. Array Arguments ..
  137. REAL S( * )
  138. COMPLEX A( LDA, * ), U( * ), VT( LDVT, * ), WORK( * )
  139. * ..
  140. *
  141. * ======================================================================
  142. *
  143. * .. Parameters ..
  144. REAL ZERO, ONE
  145. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
  146. COMPLEX CZERO, CONE
  147. PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ),
  148. $ CONE = ( 1.0E+0, 0.0E+0 ) )
  149. * ..
  150. * .. Local Scalars ..
  151. INTEGER I, J
  152. REAL ANORM, EPS
  153. * ..
  154. * .. Local Arrays ..
  155. REAL DUM( 1 )
  156. * ..
  157. * .. External Functions ..
  158. LOGICAL LSAME
  159. INTEGER ISAMAX
  160. REAL SASUM, SLAMCH, CLANGE
  161. EXTERNAL LSAME, ISAMAX, SASUM, SLAMCH, CLANGE
  162. REAL SCASUM
  163. * ..
  164. * .. External Subroutines ..
  165. EXTERNAL CGEMM
  166. * ..
  167. * .. Intrinsic Functions ..
  168. INTRINSIC ABS, REAL, MAX, MIN
  169. * ..
  170. * .. Executable Statements ..
  171. *
  172. * Quick return if possible.
  173. *
  174. RESID = ZERO
  175. IF( MIN( M, N ).LE.0 .OR. NS.LE.0 )
  176. $ RETURN
  177. *
  178. EPS = SLAMCH( 'Precision' )
  179. ANORM = CLANGE( 'M', M, N, A, LDA, DUM )
  180. *
  181. * Compute U' * A * V.
  182. *
  183. CALL CGEMM( 'N', 'C', M, NS, N, CONE, A, LDA, VT,
  184. $ LDVT, CZERO, WORK( 1+NS*NS ), M )
  185. CALL CGEMM( 'C', 'N', NS, NS, M, -CONE, U, LDU, WORK( 1+NS*NS ),
  186. $ M, CZERO, WORK, NS )
  187. *
  188. * norm(S - U' * B * V)
  189. *
  190. J = 0
  191. DO 10 I = 1, NS
  192. WORK( J+I ) = WORK( J+I ) + CMPLX( S( I ), ZERO )
  193. RESID = MAX( RESID, SCASUM( NS, WORK( J+1 ), 1 ) )
  194. J = J + NS
  195. 10 CONTINUE
  196. *
  197. IF( ANORM.LE.ZERO ) THEN
  198. IF( RESID.NE.ZERO )
  199. $ RESID = ONE / EPS
  200. ELSE
  201. IF( ANORM.GE.RESID ) THEN
  202. RESID = ( RESID / ANORM ) / ( REAL( N )*EPS )
  203. ELSE
  204. IF( ANORM.LT.ONE ) THEN
  205. RESID = ( MIN( RESID, REAL( N )*ANORM ) / ANORM ) /
  206. $ ( REAL( N )*EPS )
  207. ELSE
  208. RESID = MIN( RESID / ANORM, REAL( N ) ) /
  209. $ ( REAL( N )*EPS )
  210. END IF
  211. END IF
  212. END IF
  213. *
  214. RETURN
  215. *
  216. * End of CBDT05
  217. *
  218. END