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

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