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.

dbdt04.f 6.7 kB

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