cher2.f 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. *DECK CHER2
  2. SUBROUTINE CHER2 (UPLO, N, ALPHA, X, INCX, Y, INCY, A, LDA)
  3. C***BEGIN PROLOGUE CHER2
  4. C***PURPOSE Perform Hermitian rank 2 update of a complex Hermitian
  5. C matrix.
  6. C***LIBRARY SLATEC (BLAS)
  7. C***CATEGORY D1B4
  8. C***TYPE COMPLEX (SHER2-S, DHER2-D, CHER2-C)
  9. C***KEYWORDS LEVEL 2 BLAS, LINEAR ALGEBRA
  10. C***AUTHOR Dongarra, J. J., (ANL)
  11. C Du Croz, J., (NAG)
  12. C Hammarling, S., (NAG)
  13. C Hanson, R. J., (SNLA)
  14. C***DESCRIPTION
  15. C
  16. C CHER2 performs the hermitian rank 2 operation
  17. C
  18. C A := alpha*x*conjg( y') + conjg( alpha)*y*conjg( x') + A,
  19. C
  20. C where alpha is a scalar, x and y are n element vectors and A is an n
  21. C by n hermitian matrix.
  22. C
  23. C Parameters
  24. C ==========
  25. C
  26. C UPLO - CHARACTER*1.
  27. C On entry, UPLO specifies whether the upper or lower
  28. C triangular part of the array A is to be referenced as
  29. C follows:
  30. C
  31. C UPLO = 'U' or 'u' Only the upper triangular part of A
  32. C is to be referenced.
  33. C
  34. C UPLO = 'L' or 'l' Only the lower triangular part of A
  35. C is to be referenced.
  36. C
  37. C Unchanged on exit.
  38. C
  39. C N - INTEGER.
  40. C On entry, N specifies the order of the matrix A.
  41. C N must be at least zero.
  42. C Unchanged on exit.
  43. C
  44. C ALPHA - COMPLEX .
  45. C On entry, ALPHA specifies the scalar alpha.
  46. C Unchanged on exit.
  47. C
  48. C X - COMPLEX array of dimension at least
  49. C ( 1 + ( n - 1 )*abs( INCX ) ).
  50. C Before entry, the incremented array X must contain the n
  51. C element vector x.
  52. C Unchanged on exit.
  53. C
  54. C INCX - INTEGER.
  55. C On entry, INCX specifies the increment for the elements of
  56. C X. INCX must not be zero.
  57. C Unchanged on exit.
  58. C
  59. C Y - COMPLEX array of dimension at least
  60. C ( 1 + ( n - 1 )*abs( INCY ) ).
  61. C Before entry, the incremented array Y must contain the n
  62. C element vector y.
  63. C Unchanged on exit.
  64. C
  65. C INCY - INTEGER.
  66. C On entry, INCY specifies the increment for the elements of
  67. C Y. INCY must not be zero.
  68. C Unchanged on exit.
  69. C
  70. C A - COMPLEX array of DIMENSION ( LDA, n ).
  71. C Before entry with UPLO = 'U' or 'u', the leading n by n
  72. C upper triangular part of the array A must contain the upper
  73. C triangular part of the hermitian matrix and the strictly
  74. C lower triangular part of A is not referenced. On exit, the
  75. C upper triangular part of the array A is overwritten by the
  76. C upper triangular part of the updated matrix.
  77. C Before entry with UPLO = 'L' or 'l', the leading n by n
  78. C lower triangular part of the array A must contain the lower
  79. C triangular part of the hermitian matrix and the strictly
  80. C upper triangular part of A is not referenced. On exit, the
  81. C lower triangular part of the array A is overwritten by the
  82. C lower triangular part of the updated matrix.
  83. C Note that the imaginary parts of the diagonal elements need
  84. C not be set, they are assumed to be zero, and on exit they
  85. C are set to zero.
  86. C
  87. C LDA - INTEGER.
  88. C On entry, LDA specifies the first dimension of A as declared
  89. C in the calling (sub) program. LDA must be at least
  90. C max( 1, n ).
  91. C Unchanged on exit.
  92. C
  93. C***REFERENCES Dongarra, J. J., Du Croz, J., Hammarling, S., and
  94. C Hanson, R. J. An extended set of Fortran basic linear
  95. C algebra subprograms. ACM TOMS, Vol. 14, No. 1,
  96. C pp. 1-17, March 1988.
  97. C***ROUTINES CALLED LSAME, XERBLA
  98. C***REVISION HISTORY (YYMMDD)
  99. C 861022 DATE WRITTEN
  100. C 910605 Modified to meet SLATEC prologue standards. Only comment
  101. C lines were modified. (BKS)
  102. C***END PROLOGUE CHER2
  103. C .. Scalar Arguments ..
  104. COMPLEX ALPHA
  105. INTEGER INCX, INCY, LDA, N
  106. CHARACTER*1 UPLO
  107. C .. Array Arguments ..
  108. COMPLEX A( LDA, * ), X( * ), Y( * )
  109. C .. Parameters ..
  110. COMPLEX ZERO
  111. PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )
  112. C .. Local Scalars ..
  113. COMPLEX TEMP1, TEMP2
  114. INTEGER I, INFO, IX, IY, J, JX, JY, KX, KY
  115. C .. External Functions ..
  116. LOGICAL LSAME
  117. EXTERNAL LSAME
  118. C .. External Subroutines ..
  119. EXTERNAL XERBLA
  120. C .. Intrinsic Functions ..
  121. INTRINSIC CONJG, MAX, REAL
  122. C***FIRST EXECUTABLE STATEMENT CHER2
  123. C
  124. C Test the input parameters.
  125. C
  126. INFO = 0
  127. IF ( .NOT.LSAME( UPLO, 'U' ).AND.
  128. $ .NOT.LSAME( UPLO, 'L' ) )THEN
  129. INFO = 1
  130. ELSE IF( N.LT.0 )THEN
  131. INFO = 2
  132. ELSE IF( INCX.EQ.0 )THEN
  133. INFO = 5
  134. ELSE IF( INCY.EQ.0 )THEN
  135. INFO = 7
  136. ELSE IF( LDA.LT.MAX( 1, N ) )THEN
  137. INFO = 9
  138. END IF
  139. IF( INFO.NE.0 )THEN
  140. CALL XERBLA( 'CHER2 ', INFO )
  141. RETURN
  142. END IF
  143. C
  144. C Quick return if possible.
  145. C
  146. IF( ( N.EQ.0 ).OR.( ALPHA.EQ.ZERO ) )
  147. $ RETURN
  148. C
  149. C Set up the start points in X and Y if the increments are not both
  150. C unity.
  151. C
  152. IF( ( INCX.NE.1 ).OR.( INCY.NE.1 ) )THEN
  153. IF( INCX.GT.0 )THEN
  154. KX = 1
  155. ELSE
  156. KX = 1 - ( N - 1 )*INCX
  157. END IF
  158. IF( INCY.GT.0 )THEN
  159. KY = 1
  160. ELSE
  161. KY = 1 - ( N - 1 )*INCY
  162. END IF
  163. JX = KX
  164. JY = KY
  165. END IF
  166. C
  167. C Start the operations. In this version the elements of A are
  168. C accessed sequentially with one pass through the triangular part
  169. C of A.
  170. C
  171. IF( LSAME( UPLO, 'U' ) )THEN
  172. C
  173. C Form A when A is stored in the upper triangle.
  174. C
  175. IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN
  176. DO 20, J = 1, N
  177. IF( ( X( J ).NE.ZERO ).OR.( Y( J ).NE.ZERO ) )THEN
  178. TEMP1 = ALPHA*CONJG( Y( J ) )
  179. TEMP2 = CONJG( ALPHA*X( J ) )
  180. DO 10, I = 1, J - 1
  181. A( I, J ) = A( I, J ) + X( I )*TEMP1 + Y( I )*TEMP2
  182. 10 CONTINUE
  183. A( J, J ) = REAL( A( J, J ) ) +
  184. $ REAL( X( J )*TEMP1 + Y( J )*TEMP2 )
  185. ELSE
  186. A( J, J ) = REAL( A( J, J ) )
  187. END IF
  188. 20 CONTINUE
  189. ELSE
  190. DO 40, J = 1, N
  191. IF( ( X( JX ).NE.ZERO ).OR.( Y( JY ).NE.ZERO ) )THEN
  192. TEMP1 = ALPHA*CONJG( Y( JY ) )
  193. TEMP2 = CONJG( ALPHA*X( JX ) )
  194. IX = KX
  195. IY = KY
  196. DO 30, I = 1, J - 1
  197. A( I, J ) = A( I, J ) + X( IX )*TEMP1
  198. $ + Y( IY )*TEMP2
  199. IX = IX + INCX
  200. IY = IY + INCY
  201. 30 CONTINUE
  202. A( J, J ) = REAL( A( J, J ) ) +
  203. $ REAL( X( JX )*TEMP1 + Y( JY )*TEMP2 )
  204. ELSE
  205. A( J, J ) = REAL( A( J, J ) )
  206. END IF
  207. JX = JX + INCX
  208. JY = JY + INCY
  209. 40 CONTINUE
  210. END IF
  211. ELSE
  212. C
  213. C Form A when A is stored in the lower triangle.
  214. C
  215. IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN
  216. DO 60, J = 1, N
  217. IF( ( X( J ).NE.ZERO ).OR.( Y( J ).NE.ZERO ) )THEN
  218. TEMP1 = ALPHA*CONJG( Y( J ) )
  219. TEMP2 = CONJG( ALPHA*X( J ) )
  220. A( J, J ) = REAL( A( J, J ) ) +
  221. $ REAL( X( J )*TEMP1 + Y( J )*TEMP2 )
  222. DO 50, I = J + 1, N
  223. A( I, J ) = A( I, J ) + X( I )*TEMP1 + Y( I )*TEMP2
  224. 50 CONTINUE
  225. ELSE
  226. A( J, J ) = REAL( A( J, J ) )
  227. END IF
  228. 60 CONTINUE
  229. ELSE
  230. DO 80, J = 1, N
  231. IF( ( X( JX ).NE.ZERO ).OR.( Y( JY ).NE.ZERO ) )THEN
  232. TEMP1 = ALPHA*CONJG( Y( JY ) )
  233. TEMP2 = CONJG( ALPHA*X( JX ) )
  234. A( J, J ) = REAL( A( J, J ) ) +
  235. $ REAL( X( JX )*TEMP1 + Y( JY )*TEMP2 )
  236. IX = JX
  237. IY = JY
  238. DO 70, I = J + 1, N
  239. IX = IX + INCX
  240. IY = IY + INCY
  241. A( I, J ) = A( I, J ) + X( IX )*TEMP1
  242. $ + Y( IY )*TEMP2
  243. 70 CONTINUE
  244. ELSE
  245. A( J, J ) = REAL( A( J, J ) )
  246. END IF
  247. JX = JX + INCX
  248. JY = JY + INCY
  249. 80 CONTINUE
  250. END IF
  251. END IF
  252. C
  253. RETURN
  254. C
  255. C End of CHER2 .
  256. C
  257. END