zhpr2.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /* zhpr2.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 zhpr2_(char *uplo, integer *n, doublecomplex *alpha,
  14. doublecomplex *x, integer *incx, doublecomplex *y, integer *incy,
  15. doublecomplex *ap)
  16. {
  17. /* System generated locals */
  18. integer i__1, i__2, i__3, i__4, i__5, i__6;
  19. doublereal d__1;
  20. doublecomplex z__1, z__2, z__3, z__4;
  21. /* Builtin functions */
  22. void d_cnjg(doublecomplex *, doublecomplex *);
  23. /* Local variables */
  24. integer i__, j, k, kk, ix, iy, jx, jy, kx, ky, info;
  25. doublecomplex 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. /* ZHPR2 performs the hermitian rank 2 operation */
  35. /* A := alpha*x*conjg( y' ) + conjg( alpha )*y*conjg( x' ) + A, */
  36. /* where alpha is a scalar, x and y are n element vectors and A is an */
  37. /* 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*16 . */
  54. /* On entry, ALPHA specifies the scalar alpha. */
  55. /* Unchanged on exit. */
  56. /* X - COMPLEX*16 array of dimension at least */
  57. /* ( 1 + ( n - 1 )*abs( INCX ) ). */
  58. /* Before entry, the incremented array X must contain the n */
  59. /* element vector x. */
  60. /* Unchanged on exit. */
  61. /* INCX - INTEGER. */
  62. /* On entry, INCX specifies the increment for the elements of */
  63. /* X. INCX must not be zero. */
  64. /* Unchanged on exit. */
  65. /* Y - COMPLEX*16 array of dimension at least */
  66. /* ( 1 + ( n - 1 )*abs( INCY ) ). */
  67. /* Before entry, the incremented array Y must contain the n */
  68. /* element vector y. */
  69. /* Unchanged on exit. */
  70. /* INCY - INTEGER. */
  71. /* On entry, INCY specifies the increment for the elements of */
  72. /* Y. INCY must not be zero. */
  73. /* Unchanged on exit. */
  74. /* AP - COMPLEX*16 array of DIMENSION at least */
  75. /* ( ( n*( n + 1 ) )/2 ). */
  76. /* Before entry with UPLO = 'U' or 'u', the array AP must */
  77. /* contain the upper triangular part of the hermitian matrix */
  78. /* packed sequentially, column by column, so that AP( 1 ) */
  79. /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 ) */
  80. /* and a( 2, 2 ) respectively, and so on. On exit, the array */
  81. /* AP is overwritten by the upper triangular part of the */
  82. /* updated matrix. */
  83. /* Before entry with UPLO = 'L' or 'l', the array AP must */
  84. /* contain the lower triangular part of the hermitian matrix */
  85. /* packed sequentially, column by column, so that AP( 1 ) */
  86. /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 ) */
  87. /* and a( 3, 1 ) respectively, and so on. On exit, the array */
  88. /* AP is overwritten by the lower triangular part of the */
  89. /* updated matrix. */
  90. /* Note that the imaginary parts of the diagonal elements need */
  91. /* not be set, they are assumed to be zero, and on exit they */
  92. /* are set to zero. */
  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. --ap;
  112. --y;
  113. --x;
  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 = 5;
  122. } else if (*incy == 0) {
  123. info = 7;
  124. }
  125. if (info != 0) {
  126. xerbla_("ZHPR2 ", &info);
  127. return 0;
  128. }
  129. /* Quick return if possible. */
  130. if (*n == 0 || alpha->r == 0. && alpha->i == 0.) {
  131. return 0;
  132. }
  133. /* Set up the start points in X and Y if the increments are not both */
  134. /* unity. */
  135. if (*incx != 1 || *incy != 1) {
  136. if (*incx > 0) {
  137. kx = 1;
  138. } else {
  139. kx = 1 - (*n - 1) * *incx;
  140. }
  141. if (*incy > 0) {
  142. ky = 1;
  143. } else {
  144. ky = 1 - (*n - 1) * *incy;
  145. }
  146. jx = kx;
  147. jy = ky;
  148. }
  149. /* Start the operations. In this version the elements of the array AP */
  150. /* are accessed sequentially with one pass through AP. */
  151. kk = 1;
  152. if (lsame_(uplo, "U")) {
  153. /* Form A when upper triangle is stored in AP. */
  154. if (*incx == 1 && *incy == 1) {
  155. i__1 = *n;
  156. for (j = 1; j <= i__1; ++j) {
  157. i__2 = j;
  158. i__3 = j;
  159. if (x[i__2].r != 0. || x[i__2].i != 0. || (y[i__3].r != 0. ||
  160. y[i__3].i != 0.)) {
  161. d_cnjg(&z__2, &y[j]);
  162. z__1.r = alpha->r * z__2.r - alpha->i * z__2.i, z__1.i =
  163. alpha->r * z__2.i + alpha->i * z__2.r;
  164. temp1.r = z__1.r, temp1.i = z__1.i;
  165. i__2 = j;
  166. z__2.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i,
  167. z__2.i = alpha->r * x[i__2].i + alpha->i * x[i__2]
  168. .r;
  169. d_cnjg(&z__1, &z__2);
  170. temp2.r = z__1.r, temp2.i = z__1.i;
  171. k = kk;
  172. i__2 = j - 1;
  173. for (i__ = 1; i__ <= i__2; ++i__) {
  174. i__3 = k;
  175. i__4 = k;
  176. i__5 = i__;
  177. z__3.r = x[i__5].r * temp1.r - x[i__5].i * temp1.i,
  178. z__3.i = x[i__5].r * temp1.i + x[i__5].i *
  179. temp1.r;
  180. z__2.r = ap[i__4].r + z__3.r, z__2.i = ap[i__4].i +
  181. z__3.i;
  182. i__6 = i__;
  183. z__4.r = y[i__6].r * temp2.r - y[i__6].i * temp2.i,
  184. z__4.i = y[i__6].r * temp2.i + y[i__6].i *
  185. temp2.r;
  186. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
  187. ap[i__3].r = z__1.r, ap[i__3].i = z__1.i;
  188. ++k;
  189. /* L10: */
  190. }
  191. i__2 = kk + j - 1;
  192. i__3 = kk + j - 1;
  193. i__4 = j;
  194. z__2.r = x[i__4].r * temp1.r - x[i__4].i * temp1.i,
  195. z__2.i = x[i__4].r * temp1.i + x[i__4].i *
  196. temp1.r;
  197. i__5 = j;
  198. z__3.r = y[i__5].r * temp2.r - y[i__5].i * temp2.i,
  199. z__3.i = y[i__5].r * temp2.i + y[i__5].i *
  200. temp2.r;
  201. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  202. d__1 = ap[i__3].r + z__1.r;
  203. ap[i__2].r = d__1, ap[i__2].i = 0.;
  204. } else {
  205. i__2 = kk + j - 1;
  206. i__3 = kk + j - 1;
  207. d__1 = ap[i__3].r;
  208. ap[i__2].r = d__1, ap[i__2].i = 0.;
  209. }
  210. kk += j;
  211. /* L20: */
  212. }
  213. } else {
  214. i__1 = *n;
  215. for (j = 1; j <= i__1; ++j) {
  216. i__2 = jx;
  217. i__3 = jy;
  218. if (x[i__2].r != 0. || x[i__2].i != 0. || (y[i__3].r != 0. ||
  219. y[i__3].i != 0.)) {
  220. d_cnjg(&z__2, &y[jy]);
  221. z__1.r = alpha->r * z__2.r - alpha->i * z__2.i, z__1.i =
  222. alpha->r * z__2.i + alpha->i * z__2.r;
  223. temp1.r = z__1.r, temp1.i = z__1.i;
  224. i__2 = jx;
  225. z__2.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i,
  226. z__2.i = alpha->r * x[i__2].i + alpha->i * x[i__2]
  227. .r;
  228. d_cnjg(&z__1, &z__2);
  229. temp2.r = z__1.r, temp2.i = z__1.i;
  230. ix = kx;
  231. iy = ky;
  232. i__2 = kk + j - 2;
  233. for (k = kk; k <= i__2; ++k) {
  234. i__3 = k;
  235. i__4 = k;
  236. i__5 = ix;
  237. z__3.r = x[i__5].r * temp1.r - x[i__5].i * temp1.i,
  238. z__3.i = x[i__5].r * temp1.i + x[i__5].i *
  239. temp1.r;
  240. z__2.r = ap[i__4].r + z__3.r, z__2.i = ap[i__4].i +
  241. z__3.i;
  242. i__6 = iy;
  243. z__4.r = y[i__6].r * temp2.r - y[i__6].i * temp2.i,
  244. z__4.i = y[i__6].r * temp2.i + y[i__6].i *
  245. temp2.r;
  246. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
  247. ap[i__3].r = z__1.r, ap[i__3].i = z__1.i;
  248. ix += *incx;
  249. iy += *incy;
  250. /* L30: */
  251. }
  252. i__2 = kk + j - 1;
  253. i__3 = kk + j - 1;
  254. i__4 = jx;
  255. z__2.r = x[i__4].r * temp1.r - x[i__4].i * temp1.i,
  256. z__2.i = x[i__4].r * temp1.i + x[i__4].i *
  257. temp1.r;
  258. i__5 = jy;
  259. z__3.r = y[i__5].r * temp2.r - y[i__5].i * temp2.i,
  260. z__3.i = y[i__5].r * temp2.i + y[i__5].i *
  261. temp2.r;
  262. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  263. d__1 = ap[i__3].r + z__1.r;
  264. ap[i__2].r = d__1, ap[i__2].i = 0.;
  265. } else {
  266. i__2 = kk + j - 1;
  267. i__3 = kk + j - 1;
  268. d__1 = ap[i__3].r;
  269. ap[i__2].r = d__1, ap[i__2].i = 0.;
  270. }
  271. jx += *incx;
  272. jy += *incy;
  273. kk += j;
  274. /* L40: */
  275. }
  276. }
  277. } else {
  278. /* Form A when lower triangle is stored in AP. */
  279. if (*incx == 1 && *incy == 1) {
  280. i__1 = *n;
  281. for (j = 1; j <= i__1; ++j) {
  282. i__2 = j;
  283. i__3 = j;
  284. if (x[i__2].r != 0. || x[i__2].i != 0. || (y[i__3].r != 0. ||
  285. y[i__3].i != 0.)) {
  286. d_cnjg(&z__2, &y[j]);
  287. z__1.r = alpha->r * z__2.r - alpha->i * z__2.i, z__1.i =
  288. alpha->r * z__2.i + alpha->i * z__2.r;
  289. temp1.r = z__1.r, temp1.i = z__1.i;
  290. i__2 = j;
  291. z__2.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i,
  292. z__2.i = alpha->r * x[i__2].i + alpha->i * x[i__2]
  293. .r;
  294. d_cnjg(&z__1, &z__2);
  295. temp2.r = z__1.r, temp2.i = z__1.i;
  296. i__2 = kk;
  297. i__3 = kk;
  298. i__4 = j;
  299. z__2.r = x[i__4].r * temp1.r - x[i__4].i * temp1.i,
  300. z__2.i = x[i__4].r * temp1.i + x[i__4].i *
  301. temp1.r;
  302. i__5 = j;
  303. z__3.r = y[i__5].r * temp2.r - y[i__5].i * temp2.i,
  304. z__3.i = y[i__5].r * temp2.i + y[i__5].i *
  305. temp2.r;
  306. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  307. d__1 = ap[i__3].r + z__1.r;
  308. ap[i__2].r = d__1, ap[i__2].i = 0.;
  309. k = kk + 1;
  310. i__2 = *n;
  311. for (i__ = j + 1; i__ <= i__2; ++i__) {
  312. i__3 = k;
  313. i__4 = k;
  314. i__5 = i__;
  315. z__3.r = x[i__5].r * temp1.r - x[i__5].i * temp1.i,
  316. z__3.i = x[i__5].r * temp1.i + x[i__5].i *
  317. temp1.r;
  318. z__2.r = ap[i__4].r + z__3.r, z__2.i = ap[i__4].i +
  319. z__3.i;
  320. i__6 = i__;
  321. z__4.r = y[i__6].r * temp2.r - y[i__6].i * temp2.i,
  322. z__4.i = y[i__6].r * temp2.i + y[i__6].i *
  323. temp2.r;
  324. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
  325. ap[i__3].r = z__1.r, ap[i__3].i = z__1.i;
  326. ++k;
  327. /* L50: */
  328. }
  329. } else {
  330. i__2 = kk;
  331. i__3 = kk;
  332. d__1 = ap[i__3].r;
  333. ap[i__2].r = d__1, ap[i__2].i = 0.;
  334. }
  335. kk = kk + *n - j + 1;
  336. /* L60: */
  337. }
  338. } else {
  339. i__1 = *n;
  340. for (j = 1; j <= i__1; ++j) {
  341. i__2 = jx;
  342. i__3 = jy;
  343. if (x[i__2].r != 0. || x[i__2].i != 0. || (y[i__3].r != 0. ||
  344. y[i__3].i != 0.)) {
  345. d_cnjg(&z__2, &y[jy]);
  346. z__1.r = alpha->r * z__2.r - alpha->i * z__2.i, z__1.i =
  347. alpha->r * z__2.i + alpha->i * z__2.r;
  348. temp1.r = z__1.r, temp1.i = z__1.i;
  349. i__2 = jx;
  350. z__2.r = alpha->r * x[i__2].r - alpha->i * x[i__2].i,
  351. z__2.i = alpha->r * x[i__2].i + alpha->i * x[i__2]
  352. .r;
  353. d_cnjg(&z__1, &z__2);
  354. temp2.r = z__1.r, temp2.i = z__1.i;
  355. i__2 = kk;
  356. i__3 = kk;
  357. i__4 = jx;
  358. z__2.r = x[i__4].r * temp1.r - x[i__4].i * temp1.i,
  359. z__2.i = x[i__4].r * temp1.i + x[i__4].i *
  360. temp1.r;
  361. i__5 = jy;
  362. z__3.r = y[i__5].r * temp2.r - y[i__5].i * temp2.i,
  363. z__3.i = y[i__5].r * temp2.i + y[i__5].i *
  364. temp2.r;
  365. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  366. d__1 = ap[i__3].r + z__1.r;
  367. ap[i__2].r = d__1, ap[i__2].i = 0.;
  368. ix = jx;
  369. iy = jy;
  370. i__2 = kk + *n - j;
  371. for (k = kk + 1; k <= i__2; ++k) {
  372. ix += *incx;
  373. iy += *incy;
  374. i__3 = k;
  375. i__4 = k;
  376. i__5 = ix;
  377. z__3.r = x[i__5].r * temp1.r - x[i__5].i * temp1.i,
  378. z__3.i = x[i__5].r * temp1.i + x[i__5].i *
  379. temp1.r;
  380. z__2.r = ap[i__4].r + z__3.r, z__2.i = ap[i__4].i +
  381. z__3.i;
  382. i__6 = iy;
  383. z__4.r = y[i__6].r * temp2.r - y[i__6].i * temp2.i,
  384. z__4.i = y[i__6].r * temp2.i + y[i__6].i *
  385. temp2.r;
  386. z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
  387. ap[i__3].r = z__1.r, ap[i__3].i = z__1.i;
  388. /* L70: */
  389. }
  390. } else {
  391. i__2 = kk;
  392. i__3 = kk;
  393. d__1 = ap[i__3].r;
  394. ap[i__2].r = d__1, ap[i__2].i = 0.;
  395. }
  396. jx += *incx;
  397. jy += *incy;
  398. kk = kk + *n - j + 1;
  399. /* L80: */
  400. }
  401. }
  402. }
  403. return 0;
  404. /* End of ZHPR2 . */
  405. } /* zhpr2_ */