sspmv.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /* sspmv.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 sspmv_(char *uplo, integer *n, real *alpha, real *ap,
  14. real *x, integer *incx, real *beta, real *y, integer *incy)
  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. /* SSPMV performs the matrix-vector operation */
  30. /* y := alpha*A*x + beta*y, */
  31. /* where alpha and beta are scalars, x and y are n element vectors and */
  32. /* A is an 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. /* AP - REAL array of DIMENSION at least */
  52. /* ( ( n*( n + 1 ) )/2 ). */
  53. /* Before entry with UPLO = 'U' or 'u', the array AP must */
  54. /* contain the upper triangular part of the symmetric matrix */
  55. /* packed sequentially, column by column, so that AP( 1 ) */
  56. /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 ) */
  57. /* and a( 2, 2 ) respectively, and so on. */
  58. /* Before entry with UPLO = 'L' or 'l', the array AP must */
  59. /* contain the lower triangular part of the symmetric matrix */
  60. /* packed sequentially, column by column, so that AP( 1 ) */
  61. /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 ) */
  62. /* and a( 3, 1 ) respectively, and so on. */
  63. /* Unchanged on exit. */
  64. /* X - REAL array of dimension at least */
  65. /* ( 1 + ( n - 1 )*abs( INCX ) ). */
  66. /* Before entry, the incremented array X must contain the n */
  67. /* element vector x. */
  68. /* Unchanged on exit. */
  69. /* INCX - INTEGER. */
  70. /* On entry, INCX specifies the increment for the elements of */
  71. /* X. INCX must not be zero. */
  72. /* Unchanged on exit. */
  73. /* BETA - REAL . */
  74. /* On entry, BETA specifies the scalar beta. When BETA is */
  75. /* supplied as zero then Y need not be set on input. */
  76. /* Unchanged on exit. */
  77. /* Y - REAL array of dimension at least */
  78. /* ( 1 + ( n - 1 )*abs( INCY ) ). */
  79. /* Before entry, the incremented array Y must contain the n */
  80. /* element vector y. On exit, Y is overwritten by the updated */
  81. /* vector y. */
  82. /* INCY - INTEGER. */
  83. /* On entry, INCY specifies the increment for the elements of */
  84. /* Y. INCY must not be zero. */
  85. /* Unchanged on exit. */
  86. /* Level 2 Blas routine. */
  87. /* -- Written on 22-October-1986. */
  88. /* Jack Dongarra, Argonne National Lab. */
  89. /* Jeremy Du Croz, Nag Central Office. */
  90. /* Sven Hammarling, Nag Central Office. */
  91. /* Richard Hanson, Sandia National Labs. */
  92. /* .. Parameters .. */
  93. /* .. */
  94. /* .. Local Scalars .. */
  95. /* .. */
  96. /* .. External Functions .. */
  97. /* .. */
  98. /* .. External Subroutines .. */
  99. /* .. */
  100. /* Test the input parameters. */
  101. /* Parameter adjustments */
  102. --y;
  103. --x;
  104. --ap;
  105. /* Function Body */
  106. info = 0;
  107. if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
  108. info = 1;
  109. } else if (*n < 0) {
  110. info = 2;
  111. } else if (*incx == 0) {
  112. info = 6;
  113. } else if (*incy == 0) {
  114. info = 9;
  115. }
  116. if (info != 0) {
  117. xerbla_("SSPMV ", &info);
  118. return 0;
  119. }
  120. /* Quick return if possible. */
  121. if (*n == 0 || *alpha == 0.f && *beta == 1.f) {
  122. return 0;
  123. }
  124. /* Set up the start points in X and Y. */
  125. if (*incx > 0) {
  126. kx = 1;
  127. } else {
  128. kx = 1 - (*n - 1) * *incx;
  129. }
  130. if (*incy > 0) {
  131. ky = 1;
  132. } else {
  133. ky = 1 - (*n - 1) * *incy;
  134. }
  135. /* Start the operations. In this version the elements of the array AP */
  136. /* are accessed sequentially with one pass through AP. */
  137. /* First form y := beta*y. */
  138. if (*beta != 1.f) {
  139. if (*incy == 1) {
  140. if (*beta == 0.f) {
  141. i__1 = *n;
  142. for (i__ = 1; i__ <= i__1; ++i__) {
  143. y[i__] = 0.f;
  144. /* L10: */
  145. }
  146. } else {
  147. i__1 = *n;
  148. for (i__ = 1; i__ <= i__1; ++i__) {
  149. y[i__] = *beta * y[i__];
  150. /* L20: */
  151. }
  152. }
  153. } else {
  154. iy = ky;
  155. if (*beta == 0.f) {
  156. i__1 = *n;
  157. for (i__ = 1; i__ <= i__1; ++i__) {
  158. y[iy] = 0.f;
  159. iy += *incy;
  160. /* L30: */
  161. }
  162. } else {
  163. i__1 = *n;
  164. for (i__ = 1; i__ <= i__1; ++i__) {
  165. y[iy] = *beta * y[iy];
  166. iy += *incy;
  167. /* L40: */
  168. }
  169. }
  170. }
  171. }
  172. if (*alpha == 0.f) {
  173. return 0;
  174. }
  175. kk = 1;
  176. if (lsame_(uplo, "U")) {
  177. /* Form y when AP contains the upper triangle. */
  178. if (*incx == 1 && *incy == 1) {
  179. i__1 = *n;
  180. for (j = 1; j <= i__1; ++j) {
  181. temp1 = *alpha * x[j];
  182. temp2 = 0.f;
  183. k = kk;
  184. i__2 = j - 1;
  185. for (i__ = 1; i__ <= i__2; ++i__) {
  186. y[i__] += temp1 * ap[k];
  187. temp2 += ap[k] * x[i__];
  188. ++k;
  189. /* L50: */
  190. }
  191. y[j] = y[j] + temp1 * ap[kk + j - 1] + *alpha * temp2;
  192. kk += j;
  193. /* L60: */
  194. }
  195. } else {
  196. jx = kx;
  197. jy = ky;
  198. i__1 = *n;
  199. for (j = 1; j <= i__1; ++j) {
  200. temp1 = *alpha * x[jx];
  201. temp2 = 0.f;
  202. ix = kx;
  203. iy = ky;
  204. i__2 = kk + j - 2;
  205. for (k = kk; k <= i__2; ++k) {
  206. y[iy] += temp1 * ap[k];
  207. temp2 += ap[k] * x[ix];
  208. ix += *incx;
  209. iy += *incy;
  210. /* L70: */
  211. }
  212. y[jy] = y[jy] + temp1 * ap[kk + j - 1] + *alpha * temp2;
  213. jx += *incx;
  214. jy += *incy;
  215. kk += j;
  216. /* L80: */
  217. }
  218. }
  219. } else {
  220. /* Form y when AP contains the lower triangle. */
  221. if (*incx == 1 && *incy == 1) {
  222. i__1 = *n;
  223. for (j = 1; j <= i__1; ++j) {
  224. temp1 = *alpha * x[j];
  225. temp2 = 0.f;
  226. y[j] += temp1 * ap[kk];
  227. k = kk + 1;
  228. i__2 = *n;
  229. for (i__ = j + 1; i__ <= i__2; ++i__) {
  230. y[i__] += temp1 * ap[k];
  231. temp2 += ap[k] * x[i__];
  232. ++k;
  233. /* L90: */
  234. }
  235. y[j] += *alpha * temp2;
  236. kk += *n - j + 1;
  237. /* L100: */
  238. }
  239. } else {
  240. jx = kx;
  241. jy = ky;
  242. i__1 = *n;
  243. for (j = 1; j <= i__1; ++j) {
  244. temp1 = *alpha * x[jx];
  245. temp2 = 0.f;
  246. y[jy] += temp1 * ap[kk];
  247. ix = jx;
  248. iy = jy;
  249. i__2 = kk + *n - j;
  250. for (k = kk + 1; k <= i__2; ++k) {
  251. ix += *incx;
  252. iy += *incy;
  253. y[iy] += temp1 * ap[k];
  254. temp2 += ap[k] * x[ix];
  255. /* L110: */
  256. }
  257. y[jy] += *alpha * temp2;
  258. jx += *incx;
  259. jy += *incy;
  260. kk += *n - j + 1;
  261. /* L120: */
  262. }
  263. }
  264. }
  265. return 0;
  266. /* End of SSPMV . */
  267. } /* sspmv_ */