dspr2.f 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. *DECK DSPR2
  2. SUBROUTINE DSPR2 (UPLO, N, ALPHA, X, INCX, Y, INCY, AP)
  3. C***BEGIN PROLOGUE DSPR2
  4. C***PURPOSE Perform the symmetric rank 2 operation.
  5. C***LIBRARY SLATEC (BLAS)
  6. C***CATEGORY D1B4
  7. C***TYPE DOUBLE PRECISION (SSPR2-S, DSPR2-D, CSPR2-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 DSPR2 performs the symmetric rank 2 operation
  16. C
  17. C A := alpha*x*y' + alpha*y*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 symmetric 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 - DOUBLE PRECISION.
  44. C On entry, ALPHA specifies the scalar alpha.
  45. C Unchanged on exit.
  46. C
  47. C X - DOUBLE PRECISION 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 - DOUBLE PRECISION 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 - DOUBLE PRECISION 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 symmetric 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 symmetric 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
  86. C***REFERENCES Dongarra, J. J., Du Croz, J., Hammarling, S., and
  87. C Hanson, R. J. An extended set of Fortran basic linear
  88. C algebra subprograms. ACM TOMS, Vol. 14, No. 1,
  89. C pp. 1-17, March 1988.
  90. C***ROUTINES CALLED LSAME, XERBLA
  91. C***REVISION HISTORY (YYMMDD)
  92. C 861022 DATE WRITTEN
  93. C 910605 Modified to meet SLATEC prologue standards. Only comment
  94. C lines were modified. (BKS)
  95. C***END PROLOGUE DSPR2
  96. C .. Scalar Arguments ..
  97. DOUBLE PRECISION ALPHA
  98. INTEGER INCX, INCY, N
  99. CHARACTER*1 UPLO
  100. C .. Array Arguments ..
  101. DOUBLE PRECISION AP( * ), X( * ), Y( * )
  102. C .. Parameters ..
  103. DOUBLE PRECISION ZERO
  104. PARAMETER ( ZERO = 0.0D+0 )
  105. C .. Local Scalars ..
  106. DOUBLE PRECISION TEMP1, TEMP2
  107. INTEGER I, INFO, IX, IY, J, JX, JY, K, KK, KX, KY
  108. C .. External Functions ..
  109. LOGICAL LSAME
  110. EXTERNAL LSAME
  111. C .. External Subroutines ..
  112. EXTERNAL XERBLA
  113. C***FIRST EXECUTABLE STATEMENT DSPR2
  114. C
  115. C Test the input parameters.
  116. C
  117. INFO = 0
  118. IF ( .NOT.LSAME( UPLO, 'U' ).AND.
  119. $ .NOT.LSAME( UPLO, 'L' ) )THEN
  120. INFO = 1
  121. ELSE IF( N.LT.0 )THEN
  122. INFO = 2
  123. ELSE IF( INCX.EQ.0 )THEN
  124. INFO = 5
  125. ELSE IF( INCY.EQ.0 )THEN
  126. INFO = 7
  127. END IF
  128. IF( INFO.NE.0 )THEN
  129. CALL XERBLA( 'DSPR2 ', INFO )
  130. RETURN
  131. END IF
  132. C
  133. C Quick return if possible.
  134. C
  135. IF( ( N.EQ.0 ).OR.( ALPHA.EQ.ZERO ) )
  136. $ RETURN
  137. C
  138. C Set up the start points in X and Y if the increments are not both
  139. C unity.
  140. C
  141. IF( ( INCX.NE.1 ).OR.( INCY.NE.1 ) )THEN
  142. IF( INCX.GT.0 )THEN
  143. KX = 1
  144. ELSE
  145. KX = 1 - ( N - 1 )*INCX
  146. END IF
  147. IF( INCY.GT.0 )THEN
  148. KY = 1
  149. ELSE
  150. KY = 1 - ( N - 1 )*INCY
  151. END IF
  152. JX = KX
  153. JY = KY
  154. END IF
  155. C
  156. C Start the operations. In this version the elements of the array AP
  157. C are accessed sequentially with one pass through AP.
  158. C
  159. KK = 1
  160. IF( LSAME( UPLO, 'U' ) )THEN
  161. C
  162. C Form A when upper triangle is stored in AP.
  163. C
  164. IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN
  165. DO 20, J = 1, N
  166. IF( ( X( J ).NE.ZERO ).OR.( Y( J ).NE.ZERO ) )THEN
  167. TEMP1 = ALPHA*Y( J )
  168. TEMP2 = ALPHA*X( J )
  169. K = KK
  170. DO 10, I = 1, J
  171. AP( K ) = AP( K ) + X( I )*TEMP1 + Y( I )*TEMP2
  172. K = K + 1
  173. 10 CONTINUE
  174. END IF
  175. KK = KK + J
  176. 20 CONTINUE
  177. ELSE
  178. DO 40, J = 1, N
  179. IF( ( X( JX ).NE.ZERO ).OR.( Y( JY ).NE.ZERO ) )THEN
  180. TEMP1 = ALPHA*Y( JY )
  181. TEMP2 = ALPHA*X( JX )
  182. IX = KX
  183. IY = KY
  184. DO 30, K = KK, KK + J - 1
  185. AP( K ) = AP( K ) + X( IX )*TEMP1 + Y( IY )*TEMP2
  186. IX = IX + INCX
  187. IY = IY + INCY
  188. 30 CONTINUE
  189. END IF
  190. JX = JX + INCX
  191. JY = JY + INCY
  192. KK = KK + J
  193. 40 CONTINUE
  194. END IF
  195. ELSE
  196. C
  197. C Form A when lower triangle is stored in AP.
  198. C
  199. IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN
  200. DO 60, J = 1, N
  201. IF( ( X( J ).NE.ZERO ).OR.( Y( J ).NE.ZERO ) )THEN
  202. TEMP1 = ALPHA*Y( J )
  203. TEMP2 = ALPHA*X( J )
  204. K = KK
  205. DO 50, I = J, N
  206. AP( K ) = AP( K ) + X( I )*TEMP1 + Y( I )*TEMP2
  207. K = K + 1
  208. 50 CONTINUE
  209. END IF
  210. KK = KK + N - J + 1
  211. 60 CONTINUE
  212. ELSE
  213. DO 80, J = 1, N
  214. IF( ( X( JX ).NE.ZERO ).OR.( Y( JY ).NE.ZERO ) )THEN
  215. TEMP1 = ALPHA*Y( JY )
  216. TEMP2 = ALPHA*X( JX )
  217. IX = JX
  218. IY = JY
  219. DO 70, K = KK, KK + N - J
  220. AP( K ) = AP( K ) + X( IX )*TEMP1 + Y( IY )*TEMP2
  221. IX = IX + INCX
  222. IY = IY + INCY
  223. 70 CONTINUE
  224. END IF
  225. JX = JX + INCX
  226. JY = JY + INCY
  227. KK = KK + N - J + 1
  228. 80 CONTINUE
  229. END IF
  230. END IF
  231. C
  232. RETURN
  233. C
  234. C End of DSPR2 .
  235. C
  236. END