sspr2.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /* sspr2.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 sspr2_(char *uplo, integer *n, real *alpha, real *x,
  14. integer *incx, real *y, integer *incy, real *ap)
  15. {
  16. /* System generated locals */
  17. integer i__1, i__2;
  18. /* Local variables */
  19. integer i__, j, k, kk, 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. /* SSPR2 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 */
  32. /* n by n symmetric matrix, supplied in packed form. */
  33. /* Arguments */
  34. /* ========== */
  35. /* UPLO - CHARACTER*1. */
  36. /* On entry, UPLO specifies whether the upper or lower */
  37. /* triangular part of the matrix A is supplied in the packed */
  38. /* array AP as follows: */
  39. /* UPLO = 'U' or 'u' The upper triangular part of A is */
  40. /* supplied in AP. */
  41. /* UPLO = 'L' or 'l' The lower triangular part of A is */
  42. /* supplied in AP. */
  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. /* AP - REAL array of DIMENSION at least */
  70. /* ( ( n*( n + 1 ) )/2 ). */
  71. /* Before entry with UPLO = 'U' or 'u', the array AP must */
  72. /* contain the upper triangular part of the symmetric matrix */
  73. /* packed sequentially, column by column, so that AP( 1 ) */
  74. /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 ) */
  75. /* and a( 2, 2 ) respectively, and so on. On exit, the array */
  76. /* AP is overwritten by the upper triangular part of the */
  77. /* updated matrix. */
  78. /* Before entry with UPLO = 'L' or 'l', the array AP must */
  79. /* contain the lower triangular part of the symmetric matrix */
  80. /* packed sequentially, column by column, so that AP( 1 ) */
  81. /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 ) */
  82. /* and a( 3, 1 ) respectively, and so on. On exit, the array */
  83. /* AP is overwritten by the lower triangular part of the */
  84. /* updated matrix. */
  85. /* Level 2 Blas routine. */
  86. /* -- Written on 22-October-1986. */
  87. /* Jack Dongarra, Argonne National Lab. */
  88. /* Jeremy Du Croz, Nag Central Office. */
  89. /* Sven Hammarling, Nag Central Office. */
  90. /* Richard Hanson, Sandia National Labs. */
  91. /* .. Parameters .. */
  92. /* .. */
  93. /* .. Local Scalars .. */
  94. /* .. */
  95. /* .. External Functions .. */
  96. /* .. */
  97. /* .. External Subroutines .. */
  98. /* .. */
  99. /* Test the input parameters. */
  100. /* Parameter adjustments */
  101. --ap;
  102. --y;
  103. --x;
  104. /* Function Body */
  105. info = 0;
  106. if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
  107. info = 1;
  108. } else if (*n < 0) {
  109. info = 2;
  110. } else if (*incx == 0) {
  111. info = 5;
  112. } else if (*incy == 0) {
  113. info = 7;
  114. }
  115. if (info != 0) {
  116. xerbla_("SSPR2 ", &info);
  117. return 0;
  118. }
  119. /* Quick return if possible. */
  120. if (*n == 0 || *alpha == 0.f) {
  121. return 0;
  122. }
  123. /* Set up the start points in X and Y if the increments are not both */
  124. /* unity. */
  125. if (*incx != 1 || *incy != 1) {
  126. if (*incx > 0) {
  127. kx = 1;
  128. } else {
  129. kx = 1 - (*n - 1) * *incx;
  130. }
  131. if (*incy > 0) {
  132. ky = 1;
  133. } else {
  134. ky = 1 - (*n - 1) * *incy;
  135. }
  136. jx = kx;
  137. jy = ky;
  138. }
  139. /* Start the operations. In this version the elements of the array AP */
  140. /* are accessed sequentially with one pass through AP. */
  141. kk = 1;
  142. if (lsame_(uplo, "U")) {
  143. /* Form A when upper triangle is stored in AP. */
  144. if (*incx == 1 && *incy == 1) {
  145. i__1 = *n;
  146. for (j = 1; j <= i__1; ++j) {
  147. if (x[j] != 0.f || y[j] != 0.f) {
  148. temp1 = *alpha * y[j];
  149. temp2 = *alpha * x[j];
  150. k = kk;
  151. i__2 = j;
  152. for (i__ = 1; i__ <= i__2; ++i__) {
  153. ap[k] = ap[k] + x[i__] * temp1 + y[i__] * temp2;
  154. ++k;
  155. /* L10: */
  156. }
  157. }
  158. kk += j;
  159. /* L20: */
  160. }
  161. } else {
  162. i__1 = *n;
  163. for (j = 1; j <= i__1; ++j) {
  164. if (x[jx] != 0.f || y[jy] != 0.f) {
  165. temp1 = *alpha * y[jy];
  166. temp2 = *alpha * x[jx];
  167. ix = kx;
  168. iy = ky;
  169. i__2 = kk + j - 1;
  170. for (k = kk; k <= i__2; ++k) {
  171. ap[k] = ap[k] + x[ix] * temp1 + y[iy] * temp2;
  172. ix += *incx;
  173. iy += *incy;
  174. /* L30: */
  175. }
  176. }
  177. jx += *incx;
  178. jy += *incy;
  179. kk += j;
  180. /* L40: */
  181. }
  182. }
  183. } else {
  184. /* Form A when lower triangle is stored in AP. */
  185. if (*incx == 1 && *incy == 1) {
  186. i__1 = *n;
  187. for (j = 1; j <= i__1; ++j) {
  188. if (x[j] != 0.f || y[j] != 0.f) {
  189. temp1 = *alpha * y[j];
  190. temp2 = *alpha * x[j];
  191. k = kk;
  192. i__2 = *n;
  193. for (i__ = j; i__ <= i__2; ++i__) {
  194. ap[k] = ap[k] + x[i__] * temp1 + y[i__] * temp2;
  195. ++k;
  196. /* L50: */
  197. }
  198. }
  199. kk = kk + *n - j + 1;
  200. /* L60: */
  201. }
  202. } else {
  203. i__1 = *n;
  204. for (j = 1; j <= i__1; ++j) {
  205. if (x[jx] != 0.f || y[jy] != 0.f) {
  206. temp1 = *alpha * y[jy];
  207. temp2 = *alpha * x[jx];
  208. ix = jx;
  209. iy = jy;
  210. i__2 = kk + *n - j;
  211. for (k = kk; k <= i__2; ++k) {
  212. ap[k] = ap[k] + x[ix] * temp1 + y[iy] * temp2;
  213. ix += *incx;
  214. iy += *incy;
  215. /* L70: */
  216. }
  217. }
  218. jx += *incx;
  219. jy += *incy;
  220. kk = kk + *n - j + 1;
  221. /* L80: */
  222. }
  223. }
  224. }
  225. return 0;
  226. /* End of SSPR2 . */
  227. } /* sspr2_ */