cgemv.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /* cgemv.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 cgemv_(char *trans, integer *m, integer *n, complex *
  14. alpha, complex *a, integer *lda, complex *x, integer *incx, complex *
  15. beta, complex *y, integer *incy)
  16. {
  17. /* System generated locals */
  18. integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
  19. complex q__1, q__2, q__3;
  20. /* Builtin functions */
  21. void r_cnjg(complex *, complex *);
  22. /* Local variables */
  23. integer i__, j, ix, iy, jx, jy, kx, ky, info;
  24. complex temp;
  25. integer lenx, leny;
  26. extern logical lsame_(char *, char *);
  27. extern /* Subroutine */ int xerbla_(char *, integer *);
  28. logical noconj;
  29. /* .. Scalar Arguments .. */
  30. /* .. */
  31. /* .. Array Arguments .. */
  32. /* .. */
  33. /* Purpose */
  34. /* ======= */
  35. /* CGEMV performs one of the matrix-vector operations */
  36. /* y := alpha*A*x + beta*y, or y := alpha*A'*x + beta*y, or */
  37. /* y := alpha*conjg( A' )*x + beta*y, */
  38. /* where alpha and beta are scalars, x and y are vectors and A is an */
  39. /* m by n matrix. */
  40. /* Arguments */
  41. /* ========== */
  42. /* TRANS - CHARACTER*1. */
  43. /* On entry, TRANS specifies the operation to be performed as */
  44. /* follows: */
  45. /* TRANS = 'N' or 'n' y := alpha*A*x + beta*y. */
  46. /* TRANS = 'T' or 't' y := alpha*A'*x + beta*y. */
  47. /* TRANS = 'C' or 'c' y := alpha*conjg( A' )*x + beta*y. */
  48. /* Unchanged on exit. */
  49. /* M - INTEGER. */
  50. /* On entry, M specifies the number of rows of the matrix A. */
  51. /* M must be at least zero. */
  52. /* Unchanged on exit. */
  53. /* N - INTEGER. */
  54. /* On entry, N specifies the number of columns of the matrix A. */
  55. /* N must be at least zero. */
  56. /* Unchanged on exit. */
  57. /* ALPHA - COMPLEX . */
  58. /* On entry, ALPHA specifies the scalar alpha. */
  59. /* Unchanged on exit. */
  60. /* A - COMPLEX array of DIMENSION ( LDA, n ). */
  61. /* Before entry, the leading m by n part of the array A must */
  62. /* contain the matrix of coefficients. */
  63. /* Unchanged on exit. */
  64. /* LDA - INTEGER. */
  65. /* On entry, LDA specifies the first dimension of A as declared */
  66. /* in the calling (sub) program. LDA must be at least */
  67. /* max( 1, m ). */
  68. /* Unchanged on exit. */
  69. /* X - COMPLEX array of DIMENSION at least */
  70. /* ( 1 + ( n - 1 )*abs( INCX ) ) when TRANS = 'N' or 'n' */
  71. /* and at least */
  72. /* ( 1 + ( m - 1 )*abs( INCX ) ) otherwise. */
  73. /* Before entry, the incremented array X must contain the */
  74. /* vector x. */
  75. /* Unchanged on exit. */
  76. /* INCX - INTEGER. */
  77. /* On entry, INCX specifies the increment for the elements of */
  78. /* X. INCX must not be zero. */
  79. /* Unchanged on exit. */
  80. /* BETA - COMPLEX . */
  81. /* On entry, BETA specifies the scalar beta. When BETA is */
  82. /* supplied as zero then Y need not be set on input. */
  83. /* Unchanged on exit. */
  84. /* Y - COMPLEX array of DIMENSION at least */
  85. /* ( 1 + ( m - 1 )*abs( INCY ) ) when TRANS = 'N' or 'n' */
  86. /* and at least */
  87. /* ( 1 + ( n - 1 )*abs( INCY ) ) otherwise. */
  88. /* Before entry with BETA non-zero, the incremented array Y */
  89. /* must contain the vector y. On exit, Y is overwritten by the */
  90. /* updated vector y. */
  91. /* INCY - INTEGER. */
  92. /* On entry, INCY specifies the increment for the elements of */
  93. /* Y. INCY must not be zero. */
  94. /* Unchanged on exit. */
  95. /* Level 2 Blas routine. */
  96. /* -- Written on 22-October-1986. */
  97. /* Jack Dongarra, Argonne National Lab. */
  98. /* Jeremy Du Croz, Nag Central Office. */
  99. /* Sven Hammarling, Nag Central Office. */
  100. /* Richard Hanson, Sandia National Labs. */
  101. /* .. Parameters .. */
  102. /* .. */
  103. /* .. Local Scalars .. */
  104. /* .. */
  105. /* .. External Functions .. */
  106. /* .. */
  107. /* .. External Subroutines .. */
  108. /* .. */
  109. /* .. Intrinsic Functions .. */
  110. /* .. */
  111. /* Test the input parameters. */
  112. /* Parameter adjustments */
  113. a_dim1 = *lda;
  114. a_offset = 1 + a_dim1;
  115. a -= a_offset;
  116. --x;
  117. --y;
  118. /* Function Body */
  119. info = 0;
  120. if (! lsame_(trans, "N") && ! lsame_(trans, "T") && ! lsame_(trans, "C")
  121. ) {
  122. info = 1;
  123. } else if (*m < 0) {
  124. info = 2;
  125. } else if (*n < 0) {
  126. info = 3;
  127. } else if (*lda < max(1,*m)) {
  128. info = 6;
  129. } else if (*incx == 0) {
  130. info = 8;
  131. } else if (*incy == 0) {
  132. info = 11;
  133. }
  134. if (info != 0) {
  135. xerbla_("CGEMV ", &info);
  136. return 0;
  137. }
  138. /* Quick return if possible. */
  139. if (*m == 0 || *n == 0 || alpha->r == 0.f && alpha->i == 0.f && (beta->r
  140. == 1.f && beta->i == 0.f)) {
  141. return 0;
  142. }
  143. noconj = lsame_(trans, "T");
  144. /* Set LENX and LENY, the lengths of the vectors x and y, and set */
  145. /* up the start points in X and Y. */
  146. if (lsame_(trans, "N")) {
  147. lenx = *n;
  148. leny = *m;
  149. } else {
  150. lenx = *m;
  151. leny = *n;
  152. }
  153. if (*incx > 0) {
  154. kx = 1;
  155. } else {
  156. kx = 1 - (lenx - 1) * *incx;
  157. }
  158. if (*incy > 0) {
  159. ky = 1;
  160. } else {
  161. ky = 1 - (leny - 1) * *incy;
  162. }
  163. /* Start the operations. In this version the elements of A are */
  164. /* accessed sequentially with one pass through A. */
  165. /* First form y := beta*y. */
  166. if (beta->r != 1.f || beta->i != 0.f) {
  167. if (*incy == 1) {
  168. if (beta->r == 0.f && beta->i == 0.f) {
  169. i__1 = leny;
  170. for (i__ = 1; i__ <= i__1; ++i__) {
  171. i__2 = i__;
  172. y[i__2].r = 0.f, y[i__2].i = 0.f;
  173. /* L10: */
  174. }
  175. } else {
  176. i__1 = leny;
  177. for (i__ = 1; i__ <= i__1; ++i__) {
  178. i__2 = i__;
  179. i__3 = i__;
  180. q__1.r = beta->r * y[i__3].r - beta->i * y[i__3].i,
  181. q__1.i = beta->r * y[i__3].i + beta->i * y[i__3]
  182. .r;
  183. y[i__2].r = q__1.r, y[i__2].i = q__1.i;
  184. /* L20: */
  185. }
  186. }
  187. } else {
  188. iy = ky;
  189. if (beta->r == 0.f && beta->i == 0.f) {
  190. i__1 = leny;
  191. for (i__ = 1; i__ <= i__1; ++i__) {
  192. i__2 = iy;
  193. y[i__2].r = 0.f, y[i__2].i = 0.f;
  194. iy += *incy;
  195. /* L30: */
  196. }
  197. } else {
  198. i__1 = leny;
  199. for (i__ = 1; i__ <= i__1; ++i__) {
  200. i__2 = iy;
  201. i__3 = iy;
  202. q__1.r = beta->r * y[i__3].r - beta->i * y[i__3].i,
  203. q__1.i = beta->r * y[i__3].i + beta->i * y[i__3]
  204. .r;
  205. y[i__2].r = q__1.r, y[i__2].i = q__1.i;
  206. iy += *incy;
  207. /* L40: */
  208. }
  209. }
  210. }
  211. }
  212. if (alpha->r == 0.f && alpha->i == 0.f) {
  213. return 0;
  214. }
  215. if (lsame_(trans, "N")) {
  216. /* Form y := alpha*A*x + y. */
  217. jx = kx;
  218. if (*incy == 1) {
  219. i__1 = *n;
  220. for (j = 1; j <= i__1; ++j) {
  221. i__2 = jx;
  222. if (x[i__2].r != 0.f || x[i__2].i != 0.f) {
  223. i__2 = jx;
  224. q__1.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i,
  225. q__1.i = alpha->r * x[i__2].i + alpha->i * x[i__2]
  226. .r;
  227. temp.r = q__1.r, temp.i = q__1.i;
  228. i__2 = *m;
  229. for (i__ = 1; i__ <= i__2; ++i__) {
  230. i__3 = i__;
  231. i__4 = i__;
  232. i__5 = i__ + j * a_dim1;
  233. q__2.r = temp.r * a[i__5].r - temp.i * a[i__5].i,
  234. q__2.i = temp.r * a[i__5].i + temp.i * a[i__5]
  235. .r;
  236. q__1.r = y[i__4].r + q__2.r, q__1.i = y[i__4].i +
  237. q__2.i;
  238. y[i__3].r = q__1.r, y[i__3].i = q__1.i;
  239. /* L50: */
  240. }
  241. }
  242. jx += *incx;
  243. /* L60: */
  244. }
  245. } else {
  246. i__1 = *n;
  247. for (j = 1; j <= i__1; ++j) {
  248. i__2 = jx;
  249. if (x[i__2].r != 0.f || x[i__2].i != 0.f) {
  250. i__2 = jx;
  251. q__1.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i,
  252. q__1.i = alpha->r * x[i__2].i + alpha->i * x[i__2]
  253. .r;
  254. temp.r = q__1.r, temp.i = q__1.i;
  255. iy = ky;
  256. i__2 = *m;
  257. for (i__ = 1; i__ <= i__2; ++i__) {
  258. i__3 = iy;
  259. i__4 = iy;
  260. i__5 = i__ + j * a_dim1;
  261. q__2.r = temp.r * a[i__5].r - temp.i * a[i__5].i,
  262. q__2.i = temp.r * a[i__5].i + temp.i * a[i__5]
  263. .r;
  264. q__1.r = y[i__4].r + q__2.r, q__1.i = y[i__4].i +
  265. q__2.i;
  266. y[i__3].r = q__1.r, y[i__3].i = q__1.i;
  267. iy += *incy;
  268. /* L70: */
  269. }
  270. }
  271. jx += *incx;
  272. /* L80: */
  273. }
  274. }
  275. } else {
  276. /* Form y := alpha*A'*x + y or y := alpha*conjg( A' )*x + y. */
  277. jy = ky;
  278. if (*incx == 1) {
  279. i__1 = *n;
  280. for (j = 1; j <= i__1; ++j) {
  281. temp.r = 0.f, temp.i = 0.f;
  282. if (noconj) {
  283. i__2 = *m;
  284. for (i__ = 1; i__ <= i__2; ++i__) {
  285. i__3 = i__ + j * a_dim1;
  286. i__4 = i__;
  287. q__2.r = a[i__3].r * x[i__4].r - a[i__3].i * x[i__4]
  288. .i, q__2.i = a[i__3].r * x[i__4].i + a[i__3]
  289. .i * x[i__4].r;
  290. q__1.r = temp.r + q__2.r, q__1.i = temp.i + q__2.i;
  291. temp.r = q__1.r, temp.i = q__1.i;
  292. /* L90: */
  293. }
  294. } else {
  295. i__2 = *m;
  296. for (i__ = 1; i__ <= i__2; ++i__) {
  297. r_cnjg(&q__3, &a[i__ + j * a_dim1]);
  298. i__3 = i__;
  299. q__2.r = q__3.r * x[i__3].r - q__3.i * x[i__3].i,
  300. q__2.i = q__3.r * x[i__3].i + q__3.i * x[i__3]
  301. .r;
  302. q__1.r = temp.r + q__2.r, q__1.i = temp.i + q__2.i;
  303. temp.r = q__1.r, temp.i = q__1.i;
  304. /* L100: */
  305. }
  306. }
  307. i__2 = jy;
  308. i__3 = jy;
  309. q__2.r = alpha->r * temp.r - alpha->i * temp.i, q__2.i =
  310. alpha->r * temp.i + alpha->i * temp.r;
  311. q__1.r = y[i__3].r + q__2.r, q__1.i = y[i__3].i + q__2.i;
  312. y[i__2].r = q__1.r, y[i__2].i = q__1.i;
  313. jy += *incy;
  314. /* L110: */
  315. }
  316. } else {
  317. i__1 = *n;
  318. for (j = 1; j <= i__1; ++j) {
  319. temp.r = 0.f, temp.i = 0.f;
  320. ix = kx;
  321. if (noconj) {
  322. i__2 = *m;
  323. for (i__ = 1; i__ <= i__2; ++i__) {
  324. i__3 = i__ + j * a_dim1;
  325. i__4 = ix;
  326. q__2.r = a[i__3].r * x[i__4].r - a[i__3].i * x[i__4]
  327. .i, q__2.i = a[i__3].r * x[i__4].i + a[i__3]
  328. .i * x[i__4].r;
  329. q__1.r = temp.r + q__2.r, q__1.i = temp.i + q__2.i;
  330. temp.r = q__1.r, temp.i = q__1.i;
  331. ix += *incx;
  332. /* L120: */
  333. }
  334. } else {
  335. i__2 = *m;
  336. for (i__ = 1; i__ <= i__2; ++i__) {
  337. r_cnjg(&q__3, &a[i__ + j * a_dim1]);
  338. i__3 = ix;
  339. q__2.r = q__3.r * x[i__3].r - q__3.i * x[i__3].i,
  340. q__2.i = q__3.r * x[i__3].i + q__3.i * x[i__3]
  341. .r;
  342. q__1.r = temp.r + q__2.r, q__1.i = temp.i + q__2.i;
  343. temp.r = q__1.r, temp.i = q__1.i;
  344. ix += *incx;
  345. /* L130: */
  346. }
  347. }
  348. i__2 = jy;
  349. i__3 = jy;
  350. q__2.r = alpha->r * temp.r - alpha->i * temp.i, q__2.i =
  351. alpha->r * temp.i + alpha->i * temp.r;
  352. q__1.r = y[i__3].r + q__2.r, q__1.i = y[i__3].i + q__2.i;
  353. y[i__2].r = q__1.r, y[i__2].i = q__1.i;
  354. jy += *incy;
  355. /* L140: */
  356. }
  357. }
  358. }
  359. return 0;
  360. /* End of CGEMV . */
  361. } /* cgemv_ */