chpr.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /* chpr.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 chpr_(char *uplo, integer *n, real *alpha, complex *x,
  14. integer *incx, complex *ap)
  15. {
  16. /* System generated locals */
  17. integer i__1, i__2, i__3, i__4, i__5;
  18. real r__1;
  19. complex q__1, q__2;
  20. /* Builtin functions */
  21. void r_cnjg(complex *, complex *);
  22. /* Local variables */
  23. integer i__, j, k, kk, ix, jx, kx, info;
  24. complex temp;
  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. /* CHPR performs the hermitian rank 1 operation */
  34. /* A := alpha*x*conjg( x' ) + A, */
  35. /* where alpha is a real scalar, x is an n element vector 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 - REAL . */
  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. /* AP - COMPLEX array of DIMENSION at least */
  65. /* ( ( n*( n + 1 ) )/2 ). */
  66. /* Before entry with UPLO = 'U' or 'u', the array AP must */
  67. /* contain the upper triangular part of the hermitian matrix */
  68. /* packed sequentially, column by column, so that AP( 1 ) */
  69. /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 ) */
  70. /* and a( 2, 2 ) respectively, and so on. On exit, the array */
  71. /* AP is overwritten by the upper triangular part of the */
  72. /* updated matrix. */
  73. /* Before entry with UPLO = 'L' or 'l', the array AP must */
  74. /* contain the lower triangular part of the hermitian matrix */
  75. /* packed sequentially, column by column, so that AP( 1 ) */
  76. /* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 ) */
  77. /* and a( 3, 1 ) respectively, and so on. On exit, the array */
  78. /* AP is overwritten by the lower triangular part of the */
  79. /* updated matrix. */
  80. /* Note that the imaginary parts of the diagonal elements need */
  81. /* not be set, they are assumed to be zero, and on exit they */
  82. /* are set to zero. */
  83. /* Level 2 Blas routine. */
  84. /* -- Written on 22-October-1986. */
  85. /* Jack Dongarra, Argonne National Lab. */
  86. /* Jeremy Du Croz, Nag Central Office. */
  87. /* Sven Hammarling, Nag Central Office. */
  88. /* Richard Hanson, Sandia National Labs. */
  89. /* .. Parameters .. */
  90. /* .. */
  91. /* .. Local Scalars .. */
  92. /* .. */
  93. /* .. External Functions .. */
  94. /* .. */
  95. /* .. External Subroutines .. */
  96. /* .. */
  97. /* .. Intrinsic Functions .. */
  98. /* .. */
  99. /* Test the input parameters. */
  100. /* Parameter adjustments */
  101. --ap;
  102. --x;
  103. /* Function Body */
  104. info = 0;
  105. if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
  106. info = 1;
  107. } else if (*n < 0) {
  108. info = 2;
  109. } else if (*incx == 0) {
  110. info = 5;
  111. }
  112. if (info != 0) {
  113. xerbla_("CHPR ", &info);
  114. return 0;
  115. }
  116. /* Quick return if possible. */
  117. if (*n == 0 || *alpha == 0.f) {
  118. return 0;
  119. }
  120. /* Set the start point in X if the increment is not unity. */
  121. if (*incx <= 0) {
  122. kx = 1 - (*n - 1) * *incx;
  123. } else if (*incx != 1) {
  124. kx = 1;
  125. }
  126. /* Start the operations. In this version the elements of the array AP */
  127. /* are accessed sequentially with one pass through AP. */
  128. kk = 1;
  129. if (lsame_(uplo, "U")) {
  130. /* Form A when upper triangle is stored in AP. */
  131. if (*incx == 1) {
  132. i__1 = *n;
  133. for (j = 1; j <= i__1; ++j) {
  134. i__2 = j;
  135. if (x[i__2].r != 0.f || x[i__2].i != 0.f) {
  136. r_cnjg(&q__2, &x[j]);
  137. q__1.r = *alpha * q__2.r, q__1.i = *alpha * q__2.i;
  138. temp.r = q__1.r, temp.i = q__1.i;
  139. k = kk;
  140. i__2 = j - 1;
  141. for (i__ = 1; i__ <= i__2; ++i__) {
  142. i__3 = k;
  143. i__4 = k;
  144. i__5 = i__;
  145. q__2.r = x[i__5].r * temp.r - x[i__5].i * temp.i,
  146. q__2.i = x[i__5].r * temp.i + x[i__5].i *
  147. temp.r;
  148. q__1.r = ap[i__4].r + q__2.r, q__1.i = ap[i__4].i +
  149. q__2.i;
  150. ap[i__3].r = q__1.r, ap[i__3].i = q__1.i;
  151. ++k;
  152. /* L10: */
  153. }
  154. i__2 = kk + j - 1;
  155. i__3 = kk + j - 1;
  156. i__4 = j;
  157. q__1.r = x[i__4].r * temp.r - x[i__4].i * temp.i, q__1.i =
  158. x[i__4].r * temp.i + x[i__4].i * temp.r;
  159. r__1 = ap[i__3].r + q__1.r;
  160. ap[i__2].r = r__1, ap[i__2].i = 0.f;
  161. } else {
  162. i__2 = kk + j - 1;
  163. i__3 = kk + j - 1;
  164. r__1 = ap[i__3].r;
  165. ap[i__2].r = r__1, ap[i__2].i = 0.f;
  166. }
  167. kk += j;
  168. /* L20: */
  169. }
  170. } else {
  171. jx = kx;
  172. i__1 = *n;
  173. for (j = 1; j <= i__1; ++j) {
  174. i__2 = jx;
  175. if (x[i__2].r != 0.f || x[i__2].i != 0.f) {
  176. r_cnjg(&q__2, &x[jx]);
  177. q__1.r = *alpha * q__2.r, q__1.i = *alpha * q__2.i;
  178. temp.r = q__1.r, temp.i = q__1.i;
  179. ix = kx;
  180. i__2 = kk + j - 2;
  181. for (k = kk; k <= i__2; ++k) {
  182. i__3 = k;
  183. i__4 = k;
  184. i__5 = ix;
  185. q__2.r = x[i__5].r * temp.r - x[i__5].i * temp.i,
  186. q__2.i = x[i__5].r * temp.i + x[i__5].i *
  187. temp.r;
  188. q__1.r = ap[i__4].r + q__2.r, q__1.i = ap[i__4].i +
  189. q__2.i;
  190. ap[i__3].r = q__1.r, ap[i__3].i = q__1.i;
  191. ix += *incx;
  192. /* L30: */
  193. }
  194. i__2 = kk + j - 1;
  195. i__3 = kk + j - 1;
  196. i__4 = jx;
  197. q__1.r = x[i__4].r * temp.r - x[i__4].i * temp.i, q__1.i =
  198. x[i__4].r * temp.i + x[i__4].i * temp.r;
  199. r__1 = ap[i__3].r + q__1.r;
  200. ap[i__2].r = r__1, ap[i__2].i = 0.f;
  201. } else {
  202. i__2 = kk + j - 1;
  203. i__3 = kk + j - 1;
  204. r__1 = ap[i__3].r;
  205. ap[i__2].r = r__1, ap[i__2].i = 0.f;
  206. }
  207. jx += *incx;
  208. kk += j;
  209. /* L40: */
  210. }
  211. }
  212. } else {
  213. /* Form A when lower triangle is stored in AP. */
  214. if (*incx == 1) {
  215. i__1 = *n;
  216. for (j = 1; j <= i__1; ++j) {
  217. i__2 = j;
  218. if (x[i__2].r != 0.f || x[i__2].i != 0.f) {
  219. r_cnjg(&q__2, &x[j]);
  220. q__1.r = *alpha * q__2.r, q__1.i = *alpha * q__2.i;
  221. temp.r = q__1.r, temp.i = q__1.i;
  222. i__2 = kk;
  223. i__3 = kk;
  224. i__4 = j;
  225. q__1.r = temp.r * x[i__4].r - temp.i * x[i__4].i, q__1.i =
  226. temp.r * x[i__4].i + temp.i * x[i__4].r;
  227. r__1 = ap[i__3].r + q__1.r;
  228. ap[i__2].r = r__1, ap[i__2].i = 0.f;
  229. k = kk + 1;
  230. i__2 = *n;
  231. for (i__ = j + 1; i__ <= i__2; ++i__) {
  232. i__3 = k;
  233. i__4 = k;
  234. i__5 = i__;
  235. q__2.r = x[i__5].r * temp.r - x[i__5].i * temp.i,
  236. q__2.i = x[i__5].r * temp.i + x[i__5].i *
  237. temp.r;
  238. q__1.r = ap[i__4].r + q__2.r, q__1.i = ap[i__4].i +
  239. q__2.i;
  240. ap[i__3].r = q__1.r, ap[i__3].i = q__1.i;
  241. ++k;
  242. /* L50: */
  243. }
  244. } else {
  245. i__2 = kk;
  246. i__3 = kk;
  247. r__1 = ap[i__3].r;
  248. ap[i__2].r = r__1, ap[i__2].i = 0.f;
  249. }
  250. kk = kk + *n - j + 1;
  251. /* L60: */
  252. }
  253. } else {
  254. jx = kx;
  255. i__1 = *n;
  256. for (j = 1; j <= i__1; ++j) {
  257. i__2 = jx;
  258. if (x[i__2].r != 0.f || x[i__2].i != 0.f) {
  259. r_cnjg(&q__2, &x[jx]);
  260. q__1.r = *alpha * q__2.r, q__1.i = *alpha * q__2.i;
  261. temp.r = q__1.r, temp.i = q__1.i;
  262. i__2 = kk;
  263. i__3 = kk;
  264. i__4 = jx;
  265. q__1.r = temp.r * x[i__4].r - temp.i * x[i__4].i, q__1.i =
  266. temp.r * x[i__4].i + temp.i * x[i__4].r;
  267. r__1 = ap[i__3].r + q__1.r;
  268. ap[i__2].r = r__1, ap[i__2].i = 0.f;
  269. ix = jx;
  270. i__2 = kk + *n - j;
  271. for (k = kk + 1; k <= i__2; ++k) {
  272. ix += *incx;
  273. i__3 = k;
  274. i__4 = k;
  275. i__5 = ix;
  276. q__2.r = x[i__5].r * temp.r - x[i__5].i * temp.i,
  277. q__2.i = x[i__5].r * temp.i + x[i__5].i *
  278. temp.r;
  279. q__1.r = ap[i__4].r + q__2.r, q__1.i = ap[i__4].i +
  280. q__2.i;
  281. ap[i__3].r = q__1.r, ap[i__3].i = q__1.i;
  282. /* L70: */
  283. }
  284. } else {
  285. i__2 = kk;
  286. i__3 = kk;
  287. r__1 = ap[i__3].r;
  288. ap[i__2].r = r__1, ap[i__2].i = 0.f;
  289. }
  290. jx += *incx;
  291. kk = kk + *n - j + 1;
  292. /* L80: */
  293. }
  294. }
  295. }
  296. return 0;
  297. /* End of CHPR . */
  298. } /* chpr_ */