ssyr.f 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. *DECK SSYR
  2. SUBROUTINE SSYR (UPLO, N, ALPHA, X, INCX, A, LDA)
  3. C***BEGIN PROLOGUE SSYR
  4. C***PURPOSE Perform symmetric rank 1 update of a real symmetric matrix.
  5. C***LIBRARY SLATEC (BLAS)
  6. C***CATEGORY D1B4
  7. C***TYPE SINGLE PRECISION (SSYR-S)
  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 SSYR performs the symmetric rank 1 operation
  16. C
  17. C A := alpha*x*x' + A,
  18. C
  19. C where alpha is a real scalar, x is an n element vector and A is an
  20. C n by n symmetric matrix.
  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 array A is to be referenced as
  28. C follows:
  29. C
  30. C UPLO = 'U' or 'u' Only the upper triangular part of A
  31. C is to be referenced.
  32. C
  33. C UPLO = 'L' or 'l' Only the lower triangular part of A
  34. C is to be referenced.
  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 - REAL .
  44. C On entry, ALPHA specifies the scalar alpha.
  45. C Unchanged on exit.
  46. C
  47. C X - REAL 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 A - REAL array of DIMENSION ( LDA, n ).
  59. C Before entry with UPLO = 'U' or 'u', the leading n by n
  60. C upper triangular part of the array A must contain the upper
  61. C triangular part of the symmetric matrix and the strictly
  62. C lower triangular part of A is not referenced. On exit, the
  63. C upper triangular part of the array A is overwritten by the
  64. C upper triangular part of the updated matrix.
  65. C Before entry with UPLO = 'L' or 'l', the leading n by n
  66. C lower triangular part of the array A must contain the lower
  67. C triangular part of the symmetric matrix and the strictly
  68. C upper triangular part of A is not referenced. On exit, the
  69. C lower triangular part of the array A is overwritten by the
  70. C lower triangular part of the updated matrix.
  71. C
  72. C LDA - INTEGER.
  73. C On entry, LDA specifies the first dimension of A as declared
  74. C in the calling (sub) program. LDA must be at least
  75. C max( 1, n ).
  76. C Unchanged on exit.
  77. C
  78. C***REFERENCES Dongarra, J. J., Du Croz, J., Hammarling, S., and
  79. C Hanson, R. J. An extended set of Fortran basic linear
  80. C algebra subprograms. ACM TOMS, Vol. 14, No. 1,
  81. C pp. 1-17, March 1988.
  82. C***ROUTINES CALLED LSAME, XERBLA
  83. C***REVISION HISTORY (YYMMDD)
  84. C 861022 DATE WRITTEN
  85. C 910605 Modified to meet SLATEC prologue standards. Only comment
  86. C lines were modified. (BKS)
  87. C***END PROLOGUE SSYR
  88. C .. Scalar Arguments ..
  89. REAL ALPHA
  90. INTEGER INCX, LDA, N
  91. CHARACTER*1 UPLO
  92. C .. Array Arguments ..
  93. REAL A( LDA, * ), X( * )
  94. C .. Parameters ..
  95. REAL ZERO
  96. PARAMETER ( ZERO = 0.0E+0 )
  97. C .. Local Scalars ..
  98. REAL TEMP
  99. INTEGER I, INFO, IX, J, JX, KX
  100. C .. External Functions ..
  101. LOGICAL LSAME
  102. EXTERNAL LSAME
  103. C .. External Subroutines ..
  104. EXTERNAL XERBLA
  105. C .. Intrinsic Functions ..
  106. INTRINSIC MAX
  107. C***FIRST EXECUTABLE STATEMENT SSYR
  108. C
  109. C Test the input parameters.
  110. C
  111. INFO = 0
  112. IF ( .NOT.LSAME( UPLO, 'U' ).AND.
  113. $ .NOT.LSAME( UPLO, 'L' ) )THEN
  114. INFO = 1
  115. ELSE IF( N.LT.0 )THEN
  116. INFO = 2
  117. ELSE IF( INCX.EQ.0 )THEN
  118. INFO = 5
  119. ELSE IF( LDA.LT.MAX( 1, N ) )THEN
  120. INFO = 7
  121. END IF
  122. IF( INFO.NE.0 )THEN
  123. CALL XERBLA( 'SSYR ', INFO )
  124. RETURN
  125. END IF
  126. C
  127. C Quick return if possible.
  128. C
  129. IF( ( N.EQ.0 ).OR.( ALPHA.EQ.ZERO ) )
  130. $ RETURN
  131. C
  132. C Set the start point in X if the increment is not unity.
  133. C
  134. IF( INCX.LE.0 )THEN
  135. KX = 1 - ( N - 1 )*INCX
  136. ELSE IF( INCX.NE.1 )THEN
  137. KX = 1
  138. END IF
  139. C
  140. C Start the operations. In this version the elements of A are
  141. C accessed sequentially with one pass through the triangular part
  142. C of A.
  143. C
  144. IF( LSAME( UPLO, 'U' ) )THEN
  145. C
  146. C Form A when A is stored in upper triangle.
  147. C
  148. IF( INCX.EQ.1 )THEN
  149. DO 20, J = 1, N
  150. IF( X( J ).NE.ZERO )THEN
  151. TEMP = ALPHA*X( J )
  152. DO 10, I = 1, J
  153. A( I, J ) = A( I, J ) + X( I )*TEMP
  154. 10 CONTINUE
  155. END IF
  156. 20 CONTINUE
  157. ELSE
  158. JX = KX
  159. DO 40, J = 1, N
  160. IF( X( JX ).NE.ZERO )THEN
  161. TEMP = ALPHA*X( JX )
  162. IX = KX
  163. DO 30, I = 1, J
  164. A( I, J ) = A( I, J ) + X( IX )*TEMP
  165. IX = IX + INCX
  166. 30 CONTINUE
  167. END IF
  168. JX = JX + INCX
  169. 40 CONTINUE
  170. END IF
  171. ELSE
  172. C
  173. C Form A when A is stored in lower triangle.
  174. C
  175. IF( INCX.EQ.1 )THEN
  176. DO 60, J = 1, N
  177. IF( X( J ).NE.ZERO )THEN
  178. TEMP = ALPHA*X( J )
  179. DO 50, I = J, N
  180. A( I, J ) = A( I, J ) + X( I )*TEMP
  181. 50 CONTINUE
  182. END IF
  183. 60 CONTINUE
  184. ELSE
  185. JX = KX
  186. DO 80, J = 1, N
  187. IF( X( JX ).NE.ZERO )THEN
  188. TEMP = ALPHA*X( JX )
  189. IX = JX
  190. DO 70, I = J, N
  191. A( I, J ) = A( I, J ) + X( IX )*TEMP
  192. IX = IX + INCX
  193. 70 CONTINUE
  194. END IF
  195. JX = JX + INCX
  196. 80 CONTINUE
  197. END IF
  198. END IF
  199. C
  200. RETURN
  201. C
  202. C End of SSYR .
  203. C
  204. END