dspmv.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /* dspmv.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 dspmv_(char *uplo, integer *n, doublereal *alpha,
  14. doublereal *ap, doublereal *x, integer *incx, doublereal *beta,
  15. doublereal *y, integer *incy)
  16. {
  17. /* System generated locals */
  18. integer i__1, i__2;
  19. /* Local variables */
  20. integer i__, j, k, kk, 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. /* DSPMV performs the matrix-vector operation */
  31. /* y := alpha*A*x + beta*y, */
  32. /* where alpha and beta are scalars, x and y are n element vectors and */
  33. /* A is an n by n symmetric matrix, supplied in packed form. */
  34. /* Arguments */
  35. /* ========== */
  36. /* UPLO - CHARACTER*1. */
  37. /* On entry, UPLO specifies whether the upper or lower */
  38. /* triangular part of the matrix A is supplied in the packed */
  39. /* array AP as follows: */
  40. /* UPLO = 'U' or 'u' The upper triangular part of A is */
  41. /* supplied in AP. */
  42. /* UPLO = 'L' or 'l' The lower triangular part of A is */
  43. /* supplied in AP. */
  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. /* AP - DOUBLE PRECISION array of DIMENSION at least */
  53. /* ( ( n*( n + 1 ) )/2 ). */
  54. /* Before entry with UPLO = 'U' or 'u', the array AP must */
  55. /* contain the upper triangular part of the symmetric matrix */
  56. /* packed sequentially, column by column, so that AP( 1 ) */
  57. /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 ) */
  58. /* and a( 2, 2 ) respectively, and so on. */
  59. /* Before entry with UPLO = 'L' or 'l', the array AP must */
  60. /* contain the lower triangular part of the symmetric matrix */
  61. /* packed sequentially, column by column, so that AP( 1 ) */
  62. /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 ) */
  63. /* and a( 3, 1 ) respectively, and so on. */
  64. /* Unchanged on exit. */
  65. /* X - DOUBLE PRECISION array of dimension at least */
  66. /* ( 1 + ( n - 1 )*abs( INCX ) ). */
  67. /* Before entry, the incremented array X must contain the n */
  68. /* element vector x. */
  69. /* Unchanged on exit. */
  70. /* INCX - INTEGER. */
  71. /* On entry, INCX specifies the increment for the elements of */
  72. /* X. INCX must not be zero. */
  73. /* Unchanged on exit. */
  74. /* BETA - DOUBLE PRECISION. */
  75. /* On entry, BETA specifies the scalar beta. When BETA is */
  76. /* supplied as zero then Y need not be set on input. */
  77. /* Unchanged on exit. */
  78. /* Y - DOUBLE PRECISION array of dimension at least */
  79. /* ( 1 + ( n - 1 )*abs( INCY ) ). */
  80. /* Before entry, the incremented array Y must contain the n */
  81. /* element vector y. On exit, Y is overwritten by the updated */
  82. /* vector y. */
  83. /* INCY - INTEGER. */
  84. /* On entry, INCY specifies the increment for the elements of */
  85. /* Y. INCY must not be zero. */
  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. /* Test the input parameters. */
  102. /* Parameter adjustments */
  103. --y;
  104. --x;
  105. --ap;
  106. /* Function Body */
  107. info = 0;
  108. if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
  109. info = 1;
  110. } else if (*n < 0) {
  111. info = 2;
  112. } else if (*incx == 0) {
  113. info = 6;
  114. } else if (*incy == 0) {
  115. info = 9;
  116. }
  117. if (info != 0) {
  118. xerbla_("DSPMV ", &info);
  119. return 0;
  120. }
  121. /* Quick return if possible. */
  122. if (*n == 0 || *alpha == 0. && *beta == 1.) {
  123. return 0;
  124. }
  125. /* Set up the start points in X and Y. */
  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. /* Start the operations. In this version the elements of the array AP */
  137. /* are accessed sequentially with one pass through AP. */
  138. /* First form y := beta*y. */
  139. if (*beta != 1.) {
  140. if (*incy == 1) {
  141. if (*beta == 0.) {
  142. i__1 = *n;
  143. for (i__ = 1; i__ <= i__1; ++i__) {
  144. y[i__] = 0.;
  145. /* L10: */
  146. }
  147. } else {
  148. i__1 = *n;
  149. for (i__ = 1; i__ <= i__1; ++i__) {
  150. y[i__] = *beta * y[i__];
  151. /* L20: */
  152. }
  153. }
  154. } else {
  155. iy = ky;
  156. if (*beta == 0.) {
  157. i__1 = *n;
  158. for (i__ = 1; i__ <= i__1; ++i__) {
  159. y[iy] = 0.;
  160. iy += *incy;
  161. /* L30: */
  162. }
  163. } else {
  164. i__1 = *n;
  165. for (i__ = 1; i__ <= i__1; ++i__) {
  166. y[iy] = *beta * y[iy];
  167. iy += *incy;
  168. /* L40: */
  169. }
  170. }
  171. }
  172. }
  173. if (*alpha == 0.) {
  174. return 0;
  175. }
  176. kk = 1;
  177. if (lsame_(uplo, "U")) {
  178. /* Form y when AP contains the upper triangle. */
  179. if (*incx == 1 && *incy == 1) {
  180. i__1 = *n;
  181. for (j = 1; j <= i__1; ++j) {
  182. temp1 = *alpha * x[j];
  183. temp2 = 0.;
  184. k = kk;
  185. i__2 = j - 1;
  186. for (i__ = 1; i__ <= i__2; ++i__) {
  187. y[i__] += temp1 * ap[k];
  188. temp2 += ap[k] * x[i__];
  189. ++k;
  190. /* L50: */
  191. }
  192. y[j] = y[j] + temp1 * ap[kk + j - 1] + *alpha * temp2;
  193. kk += j;
  194. /* L60: */
  195. }
  196. } else {
  197. jx = kx;
  198. jy = ky;
  199. i__1 = *n;
  200. for (j = 1; j <= i__1; ++j) {
  201. temp1 = *alpha * x[jx];
  202. temp2 = 0.;
  203. ix = kx;
  204. iy = ky;
  205. i__2 = kk + j - 2;
  206. for (k = kk; k <= i__2; ++k) {
  207. y[iy] += temp1 * ap[k];
  208. temp2 += ap[k] * x[ix];
  209. ix += *incx;
  210. iy += *incy;
  211. /* L70: */
  212. }
  213. y[jy] = y[jy] + temp1 * ap[kk + j - 1] + *alpha * temp2;
  214. jx += *incx;
  215. jy += *incy;
  216. kk += j;
  217. /* L80: */
  218. }
  219. }
  220. } else {
  221. /* Form y when AP contains the lower triangle. */
  222. if (*incx == 1 && *incy == 1) {
  223. i__1 = *n;
  224. for (j = 1; j <= i__1; ++j) {
  225. temp1 = *alpha * x[j];
  226. temp2 = 0.;
  227. y[j] += temp1 * ap[kk];
  228. k = kk + 1;
  229. i__2 = *n;
  230. for (i__ = j + 1; i__ <= i__2; ++i__) {
  231. y[i__] += temp1 * ap[k];
  232. temp2 += ap[k] * x[i__];
  233. ++k;
  234. /* L90: */
  235. }
  236. y[j] += *alpha * temp2;
  237. kk += *n - j + 1;
  238. /* L100: */
  239. }
  240. } else {
  241. jx = kx;
  242. jy = ky;
  243. i__1 = *n;
  244. for (j = 1; j <= i__1; ++j) {
  245. temp1 = *alpha * x[jx];
  246. temp2 = 0.;
  247. y[jy] += temp1 * ap[kk];
  248. ix = jx;
  249. iy = jy;
  250. i__2 = kk + *n - j;
  251. for (k = kk + 1; k <= i__2; ++k) {
  252. ix += *incx;
  253. iy += *incy;
  254. y[iy] += temp1 * ap[k];
  255. temp2 += ap[k] * x[ix];
  256. /* L110: */
  257. }
  258. y[jy] += *alpha * temp2;
  259. jx += *incx;
  260. jy += *incy;
  261. kk += *n - j + 1;
  262. /* L120: */
  263. }
  264. }
  265. }
  266. return 0;
  267. /* End of DSPMV . */
  268. } /* dspmv_ */