chemv.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /* chemv.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 chemv_(char *uplo, integer *n, complex *alpha, complex *
  14. a, integer *lda, complex *x, integer *incx, complex *beta, complex *y,
  15. integer *incy)
  16. {
  17. /* System generated locals */
  18. integer a_dim1, a_offset, 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, 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. /* CHEMV 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. */
  38. /* Arguments */
  39. /* ========== */
  40. /* UPLO - CHARACTER*1. */
  41. /* On entry, UPLO specifies whether the upper or lower */
  42. /* triangular part of the array A is to be referenced as */
  43. /* follows: */
  44. /* UPLO = 'U' or 'u' Only the upper triangular part of A */
  45. /* is to be referenced. */
  46. /* UPLO = 'L' or 'l' Only the lower triangular part of A */
  47. /* is to be referenced. */
  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. /* A - COMPLEX array of DIMENSION ( LDA, n ). */
  57. /* Before entry with UPLO = 'U' or 'u', the leading n by n */
  58. /* upper triangular part of the array A must contain the upper */
  59. /* triangular part of the hermitian matrix and the strictly */
  60. /* lower triangular part of A is not referenced. */
  61. /* Before entry with UPLO = 'L' or 'l', the leading n by n */
  62. /* lower triangular part of the array A must contain the lower */
  63. /* triangular part of the hermitian matrix and the strictly */
  64. /* upper triangular part of A is not referenced. */
  65. /* Note that the imaginary parts of the diagonal elements need */
  66. /* not be set and are assumed to be zero. */
  67. /* Unchanged on exit. */
  68. /* LDA - INTEGER. */
  69. /* On entry, LDA specifies the first dimension of A as declared */
  70. /* in the calling (sub) program. LDA must be at least */
  71. /* max( 1, n ). */
  72. /* Unchanged on exit. */
  73. /* X - COMPLEX array of dimension at least */
  74. /* ( 1 + ( n - 1 )*abs( INCX ) ). */
  75. /* Before entry, the incremented array X must contain the n */
  76. /* element vector x. */
  77. /* Unchanged on exit. */
  78. /* INCX - INTEGER. */
  79. /* On entry, INCX specifies the increment for the elements of */
  80. /* X. INCX must not be zero. */
  81. /* Unchanged on exit. */
  82. /* BETA - COMPLEX . */
  83. /* On entry, BETA specifies the scalar beta. When BETA is */
  84. /* supplied as zero then Y need not be set on input. */
  85. /* Unchanged on exit. */
  86. /* Y - COMPLEX array of dimension at least */
  87. /* ( 1 + ( n - 1 )*abs( INCY ) ). */
  88. /* Before entry, the incremented array Y must contain the n */
  89. /* element vector y. On exit, Y is overwritten by the updated */
  90. /* 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_(uplo, "U") && ! lsame_(uplo, "L")) {
  121. info = 1;
  122. } else if (*n < 0) {
  123. info = 2;
  124. } else if (*lda < max(1,*n)) {
  125. info = 5;
  126. } else if (*incx == 0) {
  127. info = 7;
  128. } else if (*incy == 0) {
  129. info = 10;
  130. }
  131. if (info != 0) {
  132. xerbla_("CHEMV ", &info);
  133. return 0;
  134. }
  135. /* Quick return if possible. */
  136. if (*n == 0 || alpha->r == 0.f && alpha->i == 0.f && (beta->r == 1.f &&
  137. beta->i == 0.f)) {
  138. return 0;
  139. }
  140. /* Set up the start points in X and Y. */
  141. if (*incx > 0) {
  142. kx = 1;
  143. } else {
  144. kx = 1 - (*n - 1) * *incx;
  145. }
  146. if (*incy > 0) {
  147. ky = 1;
  148. } else {
  149. ky = 1 - (*n - 1) * *incy;
  150. }
  151. /* Start the operations. In this version the elements of A are */
  152. /* accessed sequentially with one pass through the triangular part */
  153. /* of A. */
  154. /* First form y := beta*y. */
  155. if (beta->r != 1.f || beta->i != 0.f) {
  156. if (*incy == 1) {
  157. if (beta->r == 0.f && beta->i == 0.f) {
  158. i__1 = *n;
  159. for (i__ = 1; i__ <= i__1; ++i__) {
  160. i__2 = i__;
  161. y[i__2].r = 0.f, y[i__2].i = 0.f;
  162. /* L10: */
  163. }
  164. } else {
  165. i__1 = *n;
  166. for (i__ = 1; i__ <= i__1; ++i__) {
  167. i__2 = i__;
  168. i__3 = i__;
  169. q__1.r = beta->r * y[i__3].r - beta->i * y[i__3].i,
  170. q__1.i = beta->r * y[i__3].i + beta->i * y[i__3]
  171. .r;
  172. y[i__2].r = q__1.r, y[i__2].i = q__1.i;
  173. /* L20: */
  174. }
  175. }
  176. } else {
  177. iy = ky;
  178. if (beta->r == 0.f && beta->i == 0.f) {
  179. i__1 = *n;
  180. for (i__ = 1; i__ <= i__1; ++i__) {
  181. i__2 = iy;
  182. y[i__2].r = 0.f, y[i__2].i = 0.f;
  183. iy += *incy;
  184. /* L30: */
  185. }
  186. } else {
  187. i__1 = *n;
  188. for (i__ = 1; i__ <= i__1; ++i__) {
  189. i__2 = iy;
  190. i__3 = iy;
  191. q__1.r = beta->r * y[i__3].r - beta->i * y[i__3].i,
  192. q__1.i = beta->r * y[i__3].i + beta->i * y[i__3]
  193. .r;
  194. y[i__2].r = q__1.r, y[i__2].i = q__1.i;
  195. iy += *incy;
  196. /* L40: */
  197. }
  198. }
  199. }
  200. }
  201. if (alpha->r == 0.f && alpha->i == 0.f) {
  202. return 0;
  203. }
  204. if (lsame_(uplo, "U")) {
  205. /* Form y when A is stored in upper triangle. */
  206. if (*incx == 1 && *incy == 1) {
  207. i__1 = *n;
  208. for (j = 1; j <= i__1; ++j) {
  209. i__2 = j;
  210. q__1.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i, q__1.i =
  211. alpha->r * x[i__2].i + alpha->i * x[i__2].r;
  212. temp1.r = q__1.r, temp1.i = q__1.i;
  213. temp2.r = 0.f, temp2.i = 0.f;
  214. i__2 = j - 1;
  215. for (i__ = 1; i__ <= i__2; ++i__) {
  216. i__3 = i__;
  217. i__4 = i__;
  218. i__5 = i__ + j * a_dim1;
  219. q__2.r = temp1.r * a[i__5].r - temp1.i * a[i__5].i,
  220. q__2.i = temp1.r * a[i__5].i + temp1.i * a[i__5]
  221. .r;
  222. q__1.r = y[i__4].r + q__2.r, q__1.i = y[i__4].i + q__2.i;
  223. y[i__3].r = q__1.r, y[i__3].i = q__1.i;
  224. r_cnjg(&q__3, &a[i__ + j * a_dim1]);
  225. i__3 = i__;
  226. q__2.r = q__3.r * x[i__3].r - q__3.i * x[i__3].i, q__2.i =
  227. q__3.r * x[i__3].i + q__3.i * x[i__3].r;
  228. q__1.r = temp2.r + q__2.r, q__1.i = temp2.i + q__2.i;
  229. temp2.r = q__1.r, temp2.i = q__1.i;
  230. /* L50: */
  231. }
  232. i__2 = j;
  233. i__3 = j;
  234. i__4 = j + j * a_dim1;
  235. r__1 = a[i__4].r;
  236. q__3.r = r__1 * temp1.r, q__3.i = r__1 * temp1.i;
  237. q__2.r = y[i__3].r + q__3.r, q__2.i = y[i__3].i + q__3.i;
  238. q__4.r = alpha->r * temp2.r - alpha->i * temp2.i, q__4.i =
  239. alpha->r * temp2.i + alpha->i * temp2.r;
  240. q__1.r = q__2.r + q__4.r, q__1.i = q__2.i + q__4.i;
  241. y[i__2].r = q__1.r, y[i__2].i = q__1.i;
  242. /* L60: */
  243. }
  244. } else {
  245. jx = kx;
  246. jy = ky;
  247. i__1 = *n;
  248. for (j = 1; j <= i__1; ++j) {
  249. i__2 = jx;
  250. q__1.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i, q__1.i =
  251. alpha->r * x[i__2].i + alpha->i * x[i__2].r;
  252. temp1.r = q__1.r, temp1.i = q__1.i;
  253. temp2.r = 0.f, temp2.i = 0.f;
  254. ix = kx;
  255. iy = ky;
  256. i__2 = j - 1;
  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 = temp1.r * a[i__5].r - temp1.i * a[i__5].i,
  262. q__2.i = temp1.r * a[i__5].i + temp1.i * a[i__5]
  263. .r;
  264. q__1.r = y[i__4].r + q__2.r, q__1.i = y[i__4].i + q__2.i;
  265. y[i__3].r = q__1.r, y[i__3].i = q__1.i;
  266. r_cnjg(&q__3, &a[i__ + j * a_dim1]);
  267. i__3 = ix;
  268. q__2.r = q__3.r * x[i__3].r - q__3.i * x[i__3].i, q__2.i =
  269. q__3.r * x[i__3].i + q__3.i * x[i__3].r;
  270. q__1.r = temp2.r + q__2.r, q__1.i = temp2.i + q__2.i;
  271. temp2.r = q__1.r, temp2.i = q__1.i;
  272. ix += *incx;
  273. iy += *incy;
  274. /* L70: */
  275. }
  276. i__2 = jy;
  277. i__3 = jy;
  278. i__4 = j + j * a_dim1;
  279. r__1 = a[i__4].r;
  280. q__3.r = r__1 * temp1.r, q__3.i = r__1 * temp1.i;
  281. q__2.r = y[i__3].r + q__3.r, q__2.i = y[i__3].i + q__3.i;
  282. q__4.r = alpha->r * temp2.r - alpha->i * temp2.i, q__4.i =
  283. alpha->r * temp2.i + alpha->i * temp2.r;
  284. q__1.r = q__2.r + q__4.r, q__1.i = q__2.i + q__4.i;
  285. y[i__2].r = q__1.r, y[i__2].i = q__1.i;
  286. jx += *incx;
  287. jy += *incy;
  288. /* L80: */
  289. }
  290. }
  291. } else {
  292. /* Form y when A is stored in lower triangle. */
  293. if (*incx == 1 && *incy == 1) {
  294. i__1 = *n;
  295. for (j = 1; j <= i__1; ++j) {
  296. i__2 = j;
  297. q__1.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i, q__1.i =
  298. alpha->r * x[i__2].i + alpha->i * x[i__2].r;
  299. temp1.r = q__1.r, temp1.i = q__1.i;
  300. temp2.r = 0.f, temp2.i = 0.f;
  301. i__2 = j;
  302. i__3 = j;
  303. i__4 = j + j * a_dim1;
  304. r__1 = a[i__4].r;
  305. q__2.r = r__1 * temp1.r, q__2.i = r__1 * temp1.i;
  306. q__1.r = y[i__3].r + q__2.r, q__1.i = y[i__3].i + q__2.i;
  307. y[i__2].r = q__1.r, y[i__2].i = q__1.i;
  308. i__2 = *n;
  309. for (i__ = j + 1; i__ <= i__2; ++i__) {
  310. i__3 = i__;
  311. i__4 = i__;
  312. i__5 = i__ + j * a_dim1;
  313. q__2.r = temp1.r * a[i__5].r - temp1.i * a[i__5].i,
  314. q__2.i = temp1.r * a[i__5].i + temp1.i * a[i__5]
  315. .r;
  316. q__1.r = y[i__4].r + q__2.r, q__1.i = y[i__4].i + q__2.i;
  317. y[i__3].r = q__1.r, y[i__3].i = q__1.i;
  318. r_cnjg(&q__3, &a[i__ + j * a_dim1]);
  319. i__3 = i__;
  320. q__2.r = q__3.r * x[i__3].r - q__3.i * x[i__3].i, q__2.i =
  321. q__3.r * x[i__3].i + q__3.i * x[i__3].r;
  322. q__1.r = temp2.r + q__2.r, q__1.i = temp2.i + q__2.i;
  323. temp2.r = q__1.r, temp2.i = q__1.i;
  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. /* L100: */
  333. }
  334. } else {
  335. jx = kx;
  336. jy = ky;
  337. i__1 = *n;
  338. for (j = 1; j <= i__1; ++j) {
  339. i__2 = jx;
  340. q__1.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i, q__1.i =
  341. alpha->r * x[i__2].i + alpha->i * x[i__2].r;
  342. temp1.r = q__1.r, temp1.i = q__1.i;
  343. temp2.r = 0.f, temp2.i = 0.f;
  344. i__2 = jy;
  345. i__3 = jy;
  346. i__4 = j + j * a_dim1;
  347. r__1 = a[i__4].r;
  348. q__2.r = r__1 * temp1.r, q__2.i = r__1 * temp1.i;
  349. q__1.r = y[i__3].r + q__2.r, q__1.i = y[i__3].i + q__2.i;
  350. y[i__2].r = q__1.r, y[i__2].i = q__1.i;
  351. ix = jx;
  352. iy = jy;
  353. i__2 = *n;
  354. for (i__ = j + 1; i__ <= i__2; ++i__) {
  355. ix += *incx;
  356. iy += *incy;
  357. i__3 = iy;
  358. i__4 = iy;
  359. i__5 = i__ + j * a_dim1;
  360. q__2.r = temp1.r * a[i__5].r - temp1.i * a[i__5].i,
  361. q__2.i = temp1.r * a[i__5].i + temp1.i * a[i__5]
  362. .r;
  363. q__1.r = y[i__4].r + q__2.r, q__1.i = y[i__4].i + q__2.i;
  364. y[i__3].r = q__1.r, y[i__3].i = q__1.i;
  365. r_cnjg(&q__3, &a[i__ + j * a_dim1]);
  366. i__3 = ix;
  367. q__2.r = q__3.r * x[i__3].r - q__3.i * x[i__3].i, q__2.i =
  368. q__3.r * x[i__3].i + q__3.i * x[i__3].r;
  369. q__1.r = temp2.r + q__2.r, q__1.i = temp2.i + q__2.i;
  370. temp2.r = q__1.r, temp2.i = q__1.i;
  371. /* L110: */
  372. }
  373. i__2 = jy;
  374. i__3 = jy;
  375. q__2.r = alpha->r * temp2.r - alpha->i * temp2.i, q__2.i =
  376. alpha->r * temp2.i + alpha->i * temp2.r;
  377. q__1.r = y[i__3].r + q__2.r, q__1.i = y[i__3].i + q__2.i;
  378. y[i__2].r = q__1.r, y[i__2].i = q__1.i;
  379. jx += *incx;
  380. jy += *incy;
  381. /* L120: */
  382. }
  383. }
  384. }
  385. return 0;
  386. /* End of CHEMV . */
  387. } /* chemv_ */