dspr.f 6.4 KB

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