chpr2.f 8.9 KB

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