chpr2.c 13 KB

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