ssyr2.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* ssyr2.f -- translated by f2c (version 20061008).
  2. You must link the resulting object file with libf2c:
  3. on Microsoft Windows system, link with libf2c.lib;
  4. on Linux or Unix systems, link with .../path/to/libf2c.a -lm
  5. or, if you install libf2c.a in a standard place, with -lf2c -lm
  6. -- in that order, at the end of the command line, as in
  7. cc *.o -lf2c -lm
  8. Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
  9. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. /* Subroutine */ int ssyr2_(char *uplo, integer *n, real *alpha, real *x,
  14. integer *incx, real *y, integer *incy, real *a, integer *lda)
  15. {
  16. /* System generated locals */
  17. integer a_dim1, a_offset, i__1, i__2;
  18. /* Local variables */
  19. integer i__, j, ix, iy, jx, jy, kx, ky, info;
  20. real temp1, temp2;
  21. extern logical lsame_(char *, char *);
  22. extern /* Subroutine */ int xerbla_(char *, integer *);
  23. /* .. Scalar Arguments .. */
  24. /* .. */
  25. /* .. Array Arguments .. */
  26. /* .. */
  27. /* Purpose */
  28. /* ======= */
  29. /* SSYR2 performs the symmetric rank 2 operation */
  30. /* A := alpha*x*y' + alpha*y*x' + A, */
  31. /* where alpha is a scalar, x and y are n element vectors and A is an n */
  32. /* by n symmetric matrix. */
  33. /* Arguments */
  34. /* ========== */
  35. /* UPLO - CHARACTER*1. */
  36. /* On entry, UPLO specifies whether the upper or lower */
  37. /* triangular part of the array A is to be referenced as */
  38. /* follows: */
  39. /* UPLO = 'U' or 'u' Only the upper triangular part of A */
  40. /* is to be referenced. */
  41. /* UPLO = 'L' or 'l' Only the lower triangular part of A */
  42. /* is to be referenced. */
  43. /* Unchanged on exit. */
  44. /* N - INTEGER. */
  45. /* On entry, N specifies the order of the matrix A. */
  46. /* N must be at least zero. */
  47. /* Unchanged on exit. */
  48. /* ALPHA - REAL . */
  49. /* On entry, ALPHA specifies the scalar alpha. */
  50. /* Unchanged on exit. */
  51. /* X - REAL array of dimension at least */
  52. /* ( 1 + ( n - 1 )*abs( INCX ) ). */
  53. /* Before entry, the incremented array X must contain the n */
  54. /* element vector x. */
  55. /* Unchanged on exit. */
  56. /* INCX - INTEGER. */
  57. /* On entry, INCX specifies the increment for the elements of */
  58. /* X. INCX must not be zero. */
  59. /* Unchanged on exit. */
  60. /* Y - REAL array of dimension at least */
  61. /* ( 1 + ( n - 1 )*abs( INCY ) ). */
  62. /* Before entry, the incremented array Y must contain the n */
  63. /* element vector y. */
  64. /* Unchanged on exit. */
  65. /* INCY - INTEGER. */
  66. /* On entry, INCY specifies the increment for the elements of */
  67. /* Y. INCY must not be zero. */
  68. /* Unchanged on exit. */
  69. /* A - REAL array of DIMENSION ( LDA, n ). */
  70. /* Before entry with UPLO = 'U' or 'u', the leading n by n */
  71. /* upper triangular part of the array A must contain the upper */
  72. /* triangular part of the symmetric matrix and the strictly */
  73. /* lower triangular part of A is not referenced. On exit, the */
  74. /* upper triangular part of the array A is overwritten by the */
  75. /* upper triangular part of the updated matrix. */
  76. /* Before entry with UPLO = 'L' or 'l', the leading n by n */
  77. /* lower triangular part of the array A must contain the lower */
  78. /* triangular part of the symmetric matrix and the strictly */
  79. /* upper triangular part of A is not referenced. On exit, the */
  80. /* lower triangular part of the array A is overwritten by the */
  81. /* lower triangular part of the updated matrix. */
  82. /* LDA - INTEGER. */
  83. /* On entry, LDA specifies the first dimension of A as declared */
  84. /* in the calling (sub) program. LDA must be at least */
  85. /* max( 1, n ). */
  86. /* Unchanged on exit. */
  87. /* Level 2 Blas routine. */
  88. /* -- Written on 22-October-1986. */
  89. /* Jack Dongarra, Argonne National Lab. */
  90. /* Jeremy Du Croz, Nag Central Office. */
  91. /* Sven Hammarling, Nag Central Office. */
  92. /* Richard Hanson, Sandia National Labs. */
  93. /* .. Parameters .. */
  94. /* .. */
  95. /* .. Local Scalars .. */
  96. /* .. */
  97. /* .. External Functions .. */
  98. /* .. */
  99. /* .. External Subroutines .. */
  100. /* .. */
  101. /* .. Intrinsic Functions .. */
  102. /* .. */
  103. /* Test the input parameters. */
  104. /* Parameter adjustments */
  105. --x;
  106. --y;
  107. a_dim1 = *lda;
  108. a_offset = 1 + a_dim1;
  109. a -= a_offset;
  110. /* Function Body */
  111. info = 0;
  112. if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
  113. info = 1;
  114. } else if (*n < 0) {
  115. info = 2;
  116. } else if (*incx == 0) {
  117. info = 5;
  118. } else if (*incy == 0) {
  119. info = 7;
  120. } else if (*lda < max(1,*n)) {
  121. info = 9;
  122. }
  123. if (info != 0) {
  124. xerbla_("SSYR2 ", &info);
  125. return 0;
  126. }
  127. /* Quick return if possible. */
  128. if (*n == 0 || *alpha == 0.f) {
  129. return 0;
  130. }
  131. /* Set up the start points in X and Y if the increments are not both */
  132. /* unity. */
  133. if (*incx != 1 || *incy != 1) {
  134. if (*incx > 0) {
  135. kx = 1;
  136. } else {
  137. kx = 1 - (*n - 1) * *incx;
  138. }
  139. if (*incy > 0) {
  140. ky = 1;
  141. } else {
  142. ky = 1 - (*n - 1) * *incy;
  143. }
  144. jx = kx;
  145. jy = ky;
  146. }
  147. /* Start the operations. In this version the elements of A are */
  148. /* accessed sequentially with one pass through the triangular part */
  149. /* of A. */
  150. if (lsame_(uplo, "U")) {
  151. /* Form A when A is stored in the upper triangle. */
  152. if (*incx == 1 && *incy == 1) {
  153. i__1 = *n;
  154. for (j = 1; j <= i__1; ++j) {
  155. if (x[j] != 0.f || y[j] != 0.f) {
  156. temp1 = *alpha * y[j];
  157. temp2 = *alpha * x[j];
  158. i__2 = j;
  159. for (i__ = 1; i__ <= i__2; ++i__) {
  160. a[i__ + j * a_dim1] = a[i__ + j * a_dim1] + x[i__] *
  161. temp1 + y[i__] * temp2;
  162. /* L10: */
  163. }
  164. }
  165. /* L20: */
  166. }
  167. } else {
  168. i__1 = *n;
  169. for (j = 1; j <= i__1; ++j) {
  170. if (x[jx] != 0.f || y[jy] != 0.f) {
  171. temp1 = *alpha * y[jy];
  172. temp2 = *alpha * x[jx];
  173. ix = kx;
  174. iy = ky;
  175. i__2 = j;
  176. for (i__ = 1; i__ <= i__2; ++i__) {
  177. a[i__ + j * a_dim1] = a[i__ + j * a_dim1] + x[ix] *
  178. temp1 + y[iy] * temp2;
  179. ix += *incx;
  180. iy += *incy;
  181. /* L30: */
  182. }
  183. }
  184. jx += *incx;
  185. jy += *incy;
  186. /* L40: */
  187. }
  188. }
  189. } else {
  190. /* Form A when A is stored in the lower triangle. */
  191. if (*incx == 1 && *incy == 1) {
  192. i__1 = *n;
  193. for (j = 1; j <= i__1; ++j) {
  194. if (x[j] != 0.f || y[j] != 0.f) {
  195. temp1 = *alpha * y[j];
  196. temp2 = *alpha * x[j];
  197. i__2 = *n;
  198. for (i__ = j; i__ <= i__2; ++i__) {
  199. a[i__ + j * a_dim1] = a[i__ + j * a_dim1] + x[i__] *
  200. temp1 + y[i__] * temp2;
  201. /* L50: */
  202. }
  203. }
  204. /* L60: */
  205. }
  206. } else {
  207. i__1 = *n;
  208. for (j = 1; j <= i__1; ++j) {
  209. if (x[jx] != 0.f || y[jy] != 0.f) {
  210. temp1 = *alpha * y[jy];
  211. temp2 = *alpha * x[jx];
  212. ix = jx;
  213. iy = jy;
  214. i__2 = *n;
  215. for (i__ = j; i__ <= i__2; ++i__) {
  216. a[i__ + j * a_dim1] = a[i__ + j * a_dim1] + x[ix] *
  217. temp1 + y[iy] * temp2;
  218. ix += *incx;
  219. iy += *incy;
  220. /* L70: */
  221. }
  222. }
  223. jx += *incx;
  224. jy += *incy;
  225. /* L80: */
  226. }
  227. }
  228. }
  229. return 0;
  230. /* End of SSYR2 . */
  231. } /* ssyr2_ */