chpmv.c 12 KB

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