cher2.c 13 KB

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