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.

dqrt12.f 5.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. *> \brief \b DQRT12
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * DOUBLE PRECISION FUNCTION DQRT12( M, N, A, LDA, S, WORK, LWORK )
  12. *
  13. * .. Scalar Arguments ..
  14. * INTEGER LDA, LWORK, M, N
  15. * ..
  16. * .. Array Arguments ..
  17. * DOUBLE PRECISION A( LDA, * ), S( * ), WORK( LWORK )
  18. * ..
  19. *
  20. *
  21. *> \par Purpose:
  22. * =============
  23. *>
  24. *> \verbatim
  25. *>
  26. *> DQRT12 computes the singular values `svlues' of the upper trapezoid
  27. *> of A(1:M,1:N) and returns the ratio
  28. *>
  29. *> || svlues - s ||/(||s||*eps*max(M,N))
  30. *> \endverbatim
  31. *
  32. * Arguments:
  33. * ==========
  34. *
  35. *> \param[in] M
  36. *> \verbatim
  37. *> M is INTEGER
  38. *> The number of rows of the matrix A.
  39. *> \endverbatim
  40. *>
  41. *> \param[in] N
  42. *> \verbatim
  43. *> N is INTEGER
  44. *> The number of columns of the matrix A.
  45. *> \endverbatim
  46. *>
  47. *> \param[in] A
  48. *> \verbatim
  49. *> A is DOUBLE PRECISION array, dimension (LDA,N)
  50. *> The M-by-N matrix A. Only the upper trapezoid is referenced.
  51. *> \endverbatim
  52. *>
  53. *> \param[in] LDA
  54. *> \verbatim
  55. *> LDA is INTEGER
  56. *> The leading dimension of the array A.
  57. *> \endverbatim
  58. *>
  59. *> \param[in] S
  60. *> \verbatim
  61. *> S is DOUBLE PRECISION array, dimension (min(M,N))
  62. *> The singular values of the matrix A.
  63. *> \endverbatim
  64. *>
  65. *> \param[out] WORK
  66. *> \verbatim
  67. *> WORK is DOUBLE PRECISION array, dimension (LWORK)
  68. *> \endverbatim
  69. *>
  70. *> \param[in] LWORK
  71. *> \verbatim
  72. *> LWORK is INTEGER
  73. *> The length of the array WORK. LWORK >= max(M*N + 4*min(M,N) +
  74. *> max(M,N), M*N+2*MIN( M, N )+4*N).
  75. *> \endverbatim
  76. *
  77. * Authors:
  78. * ========
  79. *
  80. *> \author Univ. of Tennessee
  81. *> \author Univ. of California Berkeley
  82. *> \author Univ. of Colorado Denver
  83. *> \author NAG Ltd.
  84. *
  85. *> \ingroup double_lin
  86. *
  87. * =====================================================================
  88. DOUBLE PRECISION FUNCTION DQRT12( M, N, A, LDA, S, WORK, LWORK )
  89. *
  90. * -- LAPACK test routine --
  91. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  92. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  93. *
  94. * .. Scalar Arguments ..
  95. INTEGER LDA, LWORK, M, N
  96. * ..
  97. * .. Array Arguments ..
  98. DOUBLE PRECISION A( LDA, * ), S( * ), WORK( LWORK )
  99. * ..
  100. *
  101. * =====================================================================
  102. *
  103. * .. Parameters ..
  104. DOUBLE PRECISION ZERO, ONE
  105. PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
  106. * ..
  107. * .. Local Scalars ..
  108. INTEGER I, INFO, ISCL, J, MN
  109. DOUBLE PRECISION ANRM, BIGNUM, NRMSVL, SMLNUM
  110. * ..
  111. * .. External Functions ..
  112. DOUBLE PRECISION DASUM, DLAMCH, DLANGE, DNRM2
  113. EXTERNAL DASUM, DLAMCH, DLANGE, DNRM2
  114. * ..
  115. * .. External Subroutines ..
  116. EXTERNAL DAXPY, DBDSQR, DGEBD2, DLASCL, DLASET, XERBLA
  117. * ..
  118. * .. Intrinsic Functions ..
  119. INTRINSIC DBLE, MAX, MIN
  120. * ..
  121. * .. Local Arrays ..
  122. DOUBLE PRECISION DUMMY( 1 )
  123. * ..
  124. * .. Executable Statements ..
  125. *
  126. DQRT12 = ZERO
  127. *
  128. * Test that enough workspace is supplied
  129. *
  130. IF( LWORK.LT.MAX( M*N+4*MIN( M, N )+MAX( M, N ),
  131. $ M*N+2*MIN( M, N )+4*N) ) THEN
  132. CALL XERBLA( 'DQRT12', 7 )
  133. RETURN
  134. END IF
  135. *
  136. * Quick return if possible
  137. *
  138. MN = MIN( M, N )
  139. IF( MN.LE.ZERO )
  140. $ RETURN
  141. *
  142. NRMSVL = DNRM2( MN, S, 1 )
  143. *
  144. * Copy upper triangle of A into work
  145. *
  146. CALL DLASET( 'Full', M, N, ZERO, ZERO, WORK, M )
  147. DO J = 1, N
  148. DO I = 1, MIN( J, M )
  149. WORK( ( J-1 )*M+I ) = A( I, J )
  150. END DO
  151. END DO
  152. *
  153. * Get machine parameters
  154. *
  155. SMLNUM = DLAMCH( 'S' ) / DLAMCH( 'P' )
  156. BIGNUM = ONE / SMLNUM
  157. *
  158. * Scale work if max entry outside range [SMLNUM,BIGNUM]
  159. *
  160. ANRM = DLANGE( 'M', M, N, WORK, M, DUMMY )
  161. ISCL = 0
  162. IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
  163. *
  164. * Scale matrix norm up to SMLNUM
  165. *
  166. CALL DLASCL( 'G', 0, 0, ANRM, SMLNUM, M, N, WORK, M, INFO )
  167. ISCL = 1
  168. ELSE IF( ANRM.GT.BIGNUM ) THEN
  169. *
  170. * Scale matrix norm down to BIGNUM
  171. *
  172. CALL DLASCL( 'G', 0, 0, ANRM, BIGNUM, M, N, WORK, M, INFO )
  173. ISCL = 1
  174. END IF
  175. *
  176. IF( ANRM.NE.ZERO ) THEN
  177. *
  178. * Compute SVD of work
  179. *
  180. CALL DGEBD2( M, N, WORK, M, WORK( M*N+1 ), WORK( M*N+MN+1 ),
  181. $ WORK( M*N+2*MN+1 ), WORK( M*N+3*MN+1 ),
  182. $ WORK( M*N+4*MN+1 ), INFO )
  183. CALL DBDSQR( 'Upper', MN, 0, 0, 0, WORK( M*N+1 ),
  184. $ WORK( M*N+MN+1 ), DUMMY, MN, DUMMY, 1, DUMMY, MN,
  185. $ WORK( M*N+2*MN+1 ), INFO )
  186. *
  187. IF( ISCL.EQ.1 ) THEN
  188. IF( ANRM.GT.BIGNUM ) THEN
  189. CALL DLASCL( 'G', 0, 0, BIGNUM, ANRM, MN, 1,
  190. $ WORK( M*N+1 ), MN, INFO )
  191. END IF
  192. IF( ANRM.LT.SMLNUM ) THEN
  193. CALL DLASCL( 'G', 0, 0, SMLNUM, ANRM, MN, 1,
  194. $ WORK( M*N+1 ), MN, INFO )
  195. END IF
  196. END IF
  197. *
  198. ELSE
  199. *
  200. DO I = 1, MN
  201. WORK( M*N+I ) = ZERO
  202. END DO
  203. END IF
  204. *
  205. * Compare s and singular values of work
  206. *
  207. CALL DAXPY( MN, -ONE, S, 1, WORK( M*N+1 ), 1 )
  208. *
  209. DQRT12 = DASUM( MN, WORK( M*N+1 ), 1 ) /
  210. $ ( DLAMCH('Epsilon') * DBLE( MAX( M, N ) ) )
  211. *
  212. IF( NRMSVL.NE.ZERO )
  213. $ DQRT12 = DQRT12 / NRMSVL
  214. *
  215. RETURN
  216. *
  217. * End of DQRT12
  218. *
  219. END