dsyr2.c 7.3 KB

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