zgemv.c 11 KB

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