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.

ssygs2.f 8.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. *> \brief \b SSYGS2 reduces a symmetric definite generalized eigenproblem to standard form, using the factorization results obtained from spotrf (unblocked algorithm).
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SSYGS2 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssygs2.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssygs2.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssygs2.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SSYGS2( ITYPE, UPLO, N, A, LDA, B, LDB, INFO )
  22. *
  23. * .. Scalar Arguments ..
  24. * CHARACTER UPLO
  25. * INTEGER INFO, ITYPE, LDA, LDB, N
  26. * ..
  27. * .. Array Arguments ..
  28. * REAL A( LDA, * ), B( LDB, * )
  29. * ..
  30. *
  31. *
  32. *> \par Purpose:
  33. * =============
  34. *>
  35. *> \verbatim
  36. *>
  37. *> SSYGS2 reduces a real symmetric-definite generalized eigenproblem
  38. *> to standard form.
  39. *>
  40. *> If ITYPE = 1, the problem is A*x = lambda*B*x,
  41. *> and A is overwritten by inv(U**T)*A*inv(U) or inv(L)*A*inv(L**T)
  42. *>
  43. *> If ITYPE = 2 or 3, the problem is A*B*x = lambda*x or
  44. *> B*A*x = lambda*x, and A is overwritten by U*A*U**T or L**T *A*L.
  45. *>
  46. *> B must have been previously factorized as U**T *U or L*L**T by SPOTRF.
  47. *> \endverbatim
  48. *
  49. * Arguments:
  50. * ==========
  51. *
  52. *> \param[in] ITYPE
  53. *> \verbatim
  54. *> ITYPE is INTEGER
  55. *> = 1: compute inv(U**T)*A*inv(U) or inv(L)*A*inv(L**T);
  56. *> = 2 or 3: compute U*A*U**T or L**T *A*L.
  57. *> \endverbatim
  58. *>
  59. *> \param[in] UPLO
  60. *> \verbatim
  61. *> UPLO is CHARACTER*1
  62. *> Specifies whether the upper or lower triangular part of the
  63. *> symmetric matrix A is stored, and how B has been factorized.
  64. *> = 'U': Upper triangular
  65. *> = 'L': Lower triangular
  66. *> \endverbatim
  67. *>
  68. *> \param[in] N
  69. *> \verbatim
  70. *> N is INTEGER
  71. *> The order of the matrices A and B. N >= 0.
  72. *> \endverbatim
  73. *>
  74. *> \param[in,out] A
  75. *> \verbatim
  76. *> A is REAL array, dimension (LDA,N)
  77. *> On entry, the symmetric matrix A. If UPLO = 'U', the leading
  78. *> n by n upper triangular part of A contains the upper
  79. *> triangular part of the matrix A, and the strictly lower
  80. *> triangular part of A is not referenced. If UPLO = 'L', the
  81. *> leading n by n lower triangular part of A contains the lower
  82. *> triangular part of the matrix A, and the strictly upper
  83. *> triangular part of A is not referenced.
  84. *>
  85. *> On exit, if INFO = 0, the transformed matrix, stored in the
  86. *> same format as A.
  87. *> \endverbatim
  88. *>
  89. *> \param[in] LDA
  90. *> \verbatim
  91. *> LDA is INTEGER
  92. *> The leading dimension of the array A. LDA >= max(1,N).
  93. *> \endverbatim
  94. *>
  95. *> \param[in] B
  96. *> \verbatim
  97. *> B is REAL array, dimension (LDB,N)
  98. *> The triangular factor from the Cholesky factorization of B,
  99. *> as returned by SPOTRF.
  100. *> \endverbatim
  101. *>
  102. *> \param[in] LDB
  103. *> \verbatim
  104. *> LDB is INTEGER
  105. *> The leading dimension of the array B. LDB >= max(1,N).
  106. *> \endverbatim
  107. *>
  108. *> \param[out] INFO
  109. *> \verbatim
  110. *> INFO is INTEGER
  111. *> = 0: successful exit.
  112. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  113. *> \endverbatim
  114. *
  115. * Authors:
  116. * ========
  117. *
  118. *> \author Univ. of Tennessee
  119. *> \author Univ. of California Berkeley
  120. *> \author Univ. of Colorado Denver
  121. *> \author NAG Ltd.
  122. *
  123. *> \ingroup realSYcomputational
  124. *
  125. * =====================================================================
  126. SUBROUTINE SSYGS2( ITYPE, UPLO, N, A, LDA, B, LDB, INFO )
  127. *
  128. * -- LAPACK computational routine --
  129. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  130. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  131. *
  132. * .. Scalar Arguments ..
  133. CHARACTER UPLO
  134. INTEGER INFO, ITYPE, LDA, LDB, N
  135. * ..
  136. * .. Array Arguments ..
  137. REAL A( LDA, * ), B( LDB, * )
  138. * ..
  139. *
  140. * =====================================================================
  141. *
  142. * .. Parameters ..
  143. REAL ONE, HALF
  144. PARAMETER ( ONE = 1.0, HALF = 0.5 )
  145. * ..
  146. * .. Local Scalars ..
  147. LOGICAL UPPER
  148. INTEGER K
  149. REAL AKK, BKK, CT
  150. * ..
  151. * .. External Subroutines ..
  152. EXTERNAL SAXPY, SSCAL, SSYR2, STRMV, STRSV, XERBLA
  153. * ..
  154. * .. Intrinsic Functions ..
  155. INTRINSIC MAX
  156. * ..
  157. * .. External Functions ..
  158. LOGICAL LSAME
  159. EXTERNAL LSAME
  160. * ..
  161. * .. Executable Statements ..
  162. *
  163. * Test the input parameters.
  164. *
  165. INFO = 0
  166. UPPER = LSAME( UPLO, 'U' )
  167. IF( ITYPE.LT.1 .OR. ITYPE.GT.3 ) THEN
  168. INFO = -1
  169. ELSE IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  170. INFO = -2
  171. ELSE IF( N.LT.0 ) THEN
  172. INFO = -3
  173. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  174. INFO = -5
  175. ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
  176. INFO = -7
  177. END IF
  178. IF( INFO.NE.0 ) THEN
  179. CALL XERBLA( 'SSYGS2', -INFO )
  180. RETURN
  181. END IF
  182. *
  183. IF( ITYPE.EQ.1 ) THEN
  184. IF( UPPER ) THEN
  185. *
  186. * Compute inv(U**T)*A*inv(U)
  187. *
  188. DO 10 K = 1, N
  189. *
  190. * Update the upper triangle of A(k:n,k:n)
  191. *
  192. AKK = A( K, K )
  193. BKK = B( K, K )
  194. AKK = AKK / BKK**2
  195. A( K, K ) = AKK
  196. IF( K.LT.N ) THEN
  197. CALL SSCAL( N-K, ONE / BKK, A( K, K+1 ), LDA )
  198. CT = -HALF*AKK
  199. CALL SAXPY( N-K, CT, B( K, K+1 ), LDB, A( K, K+1 ),
  200. $ LDA )
  201. CALL SSYR2( UPLO, N-K, -ONE, A( K, K+1 ), LDA,
  202. $ B( K, K+1 ), LDB, A( K+1, K+1 ), LDA )
  203. CALL SAXPY( N-K, CT, B( K, K+1 ), LDB, A( K, K+1 ),
  204. $ LDA )
  205. CALL STRSV( UPLO, 'Transpose', 'Non-unit', N-K,
  206. $ B( K+1, K+1 ), LDB, A( K, K+1 ), LDA )
  207. END IF
  208. 10 CONTINUE
  209. ELSE
  210. *
  211. * Compute inv(L)*A*inv(L**T)
  212. *
  213. DO 20 K = 1, N
  214. *
  215. * Update the lower triangle of A(k:n,k:n)
  216. *
  217. AKK = A( K, K )
  218. BKK = B( K, K )
  219. AKK = AKK / BKK**2
  220. A( K, K ) = AKK
  221. IF( K.LT.N ) THEN
  222. CALL SSCAL( N-K, ONE / BKK, A( K+1, K ), 1 )
  223. CT = -HALF*AKK
  224. CALL SAXPY( N-K, CT, B( K+1, K ), 1, A( K+1, K ), 1 )
  225. CALL SSYR2( UPLO, N-K, -ONE, A( K+1, K ), 1,
  226. $ B( K+1, K ), 1, A( K+1, K+1 ), LDA )
  227. CALL SAXPY( N-K, CT, B( K+1, K ), 1, A( K+1, K ), 1 )
  228. CALL STRSV( UPLO, 'No transpose', 'Non-unit', N-K,
  229. $ B( K+1, K+1 ), LDB, A( K+1, K ), 1 )
  230. END IF
  231. 20 CONTINUE
  232. END IF
  233. ELSE
  234. IF( UPPER ) THEN
  235. *
  236. * Compute U*A*U**T
  237. *
  238. DO 30 K = 1, N
  239. *
  240. * Update the upper triangle of A(1:k,1:k)
  241. *
  242. AKK = A( K, K )
  243. BKK = B( K, K )
  244. CALL STRMV( UPLO, 'No transpose', 'Non-unit', K-1, B,
  245. $ LDB, A( 1, K ), 1 )
  246. CT = HALF*AKK
  247. CALL SAXPY( K-1, CT, B( 1, K ), 1, A( 1, K ), 1 )
  248. CALL SSYR2( UPLO, K-1, ONE, A( 1, K ), 1, B( 1, K ), 1,
  249. $ A, LDA )
  250. CALL SAXPY( K-1, CT, B( 1, K ), 1, A( 1, K ), 1 )
  251. CALL SSCAL( K-1, BKK, A( 1, K ), 1 )
  252. A( K, K ) = AKK*BKK**2
  253. 30 CONTINUE
  254. ELSE
  255. *
  256. * Compute L**T *A*L
  257. *
  258. DO 40 K = 1, N
  259. *
  260. * Update the lower triangle of A(1:k,1:k)
  261. *
  262. AKK = A( K, K )
  263. BKK = B( K, K )
  264. CALL STRMV( UPLO, 'Transpose', 'Non-unit', K-1, B, LDB,
  265. $ A( K, 1 ), LDA )
  266. CT = HALF*AKK
  267. CALL SAXPY( K-1, CT, B( K, 1 ), LDB, A( K, 1 ), LDA )
  268. CALL SSYR2( UPLO, K-1, ONE, A( K, 1 ), LDA, B( K, 1 ),
  269. $ LDB, A, LDA )
  270. CALL SAXPY( K-1, CT, B( K, 1 ), LDB, A( K, 1 ), LDA )
  271. CALL SSCAL( K-1, BKK, A( K, 1 ), LDA )
  272. A( K, K ) = AKK*BKK**2
  273. 40 CONTINUE
  274. END IF
  275. END IF
  276. RETURN
  277. *
  278. * End of SSYGS2
  279. *
  280. END