zherk.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /* zherk.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 zherk_(char *uplo, char *trans, integer *n, integer *k,
  14. doublereal *alpha, doublecomplex *a, integer *lda, doublereal *beta,
  15. doublecomplex *c__, integer *ldc)
  16. {
  17. /* System generated locals */
  18. integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3, i__4, i__5,
  19. i__6;
  20. doublereal d__1;
  21. doublecomplex z__1, z__2, z__3;
  22. /* Builtin functions */
  23. void d_cnjg(doublecomplex *, doublecomplex *);
  24. /* Local variables */
  25. integer i__, j, l, info;
  26. doublecomplex temp;
  27. extern logical lsame_(char *, char *);
  28. integer nrowa;
  29. doublereal rtemp;
  30. logical upper;
  31. extern /* Subroutine */ int xerbla_(char *, integer *);
  32. /* .. Scalar Arguments .. */
  33. /* .. */
  34. /* .. Array Arguments .. */
  35. /* .. */
  36. /* Purpose */
  37. /* ======= */
  38. /* ZHERK performs one of the hermitian rank k operations */
  39. /* C := alpha*A*conjg( A' ) + beta*C, */
  40. /* or */
  41. /* C := alpha*conjg( A' )*A + beta*C, */
  42. /* where alpha and beta are real scalars, C is an n by n hermitian */
  43. /* matrix and A is an n by k matrix in the first case and a k by n */
  44. /* matrix in the second case. */
  45. /* Arguments */
  46. /* ========== */
  47. /* UPLO - CHARACTER*1. */
  48. /* On entry, UPLO specifies whether the upper or lower */
  49. /* triangular part of the array C is to be referenced as */
  50. /* follows: */
  51. /* UPLO = 'U' or 'u' Only the upper triangular part of C */
  52. /* is to be referenced. */
  53. /* UPLO = 'L' or 'l' Only the lower triangular part of C */
  54. /* is to be referenced. */
  55. /* Unchanged on exit. */
  56. /* TRANS - CHARACTER*1. */
  57. /* On entry, TRANS specifies the operation to be performed as */
  58. /* follows: */
  59. /* TRANS = 'N' or 'n' C := alpha*A*conjg( A' ) + beta*C. */
  60. /* TRANS = 'C' or 'c' C := alpha*conjg( A' )*A + beta*C. */
  61. /* Unchanged on exit. */
  62. /* N - INTEGER. */
  63. /* On entry, N specifies the order of the matrix C. N must be */
  64. /* at least zero. */
  65. /* Unchanged on exit. */
  66. /* K - INTEGER. */
  67. /* On entry with TRANS = 'N' or 'n', K specifies the number */
  68. /* of columns of the matrix A, and on entry with */
  69. /* TRANS = 'C' or 'c', K specifies the number of rows of the */
  70. /* matrix A. K must be at least zero. */
  71. /* Unchanged on exit. */
  72. /* ALPHA - DOUBLE PRECISION . */
  73. /* On entry, ALPHA specifies the scalar alpha. */
  74. /* Unchanged on exit. */
  75. /* A - COMPLEX*16 array of DIMENSION ( LDA, ka ), where ka is */
  76. /* k when TRANS = 'N' or 'n', and is n otherwise. */
  77. /* Before entry with TRANS = 'N' or 'n', the leading n by k */
  78. /* part of the array A must contain the matrix A, otherwise */
  79. /* the leading k by n part of the array A must contain the */
  80. /* matrix A. */
  81. /* Unchanged on exit. */
  82. /* LDA - INTEGER. */
  83. /* On entry, LDA specifies the first dimension of A as declared */
  84. /* in the calling (sub) program. When TRANS = 'N' or 'n' */
  85. /* then LDA must be at least max( 1, n ), otherwise LDA must */
  86. /* be at least max( 1, k ). */
  87. /* Unchanged on exit. */
  88. /* BETA - DOUBLE PRECISION. */
  89. /* On entry, BETA specifies the scalar beta. */
  90. /* Unchanged on exit. */
  91. /* C - COMPLEX*16 array of DIMENSION ( LDC, n ). */
  92. /* Before entry with UPLO = 'U' or 'u', the leading n by n */
  93. /* upper triangular part of the array C must contain the upper */
  94. /* triangular part of the hermitian matrix and the strictly */
  95. /* lower triangular part of C is not referenced. On exit, the */
  96. /* upper triangular part of the array C is overwritten by the */
  97. /* upper triangular part of the updated matrix. */
  98. /* Before entry with UPLO = 'L' or 'l', the leading n by n */
  99. /* lower triangular part of the array C must contain the lower */
  100. /* triangular part of the hermitian matrix and the strictly */
  101. /* upper triangular part of C is not referenced. On exit, the */
  102. /* lower triangular part of the array C is overwritten by the */
  103. /* lower triangular part of the updated matrix. */
  104. /* Note that the imaginary parts of the diagonal elements need */
  105. /* not be set, they are assumed to be zero, and on exit they */
  106. /* are set to zero. */
  107. /* LDC - INTEGER. */
  108. /* On entry, LDC specifies the first dimension of C as declared */
  109. /* in the calling (sub) program. LDC must be at least */
  110. /* max( 1, n ). */
  111. /* Unchanged on exit. */
  112. /* Level 3 Blas routine. */
  113. /* -- Written on 8-February-1989. */
  114. /* Jack Dongarra, Argonne National Laboratory. */
  115. /* Iain Duff, AERE Harwell. */
  116. /* Jeremy Du Croz, Numerical Algorithms Group Ltd. */
  117. /* Sven Hammarling, Numerical Algorithms Group Ltd. */
  118. /* -- Modified 8-Nov-93 to set C(J,J) to DBLE( C(J,J) ) when BETA = 1. */
  119. /* Ed Anderson, Cray Research Inc. */
  120. /* .. External Functions .. */
  121. /* .. */
  122. /* .. External Subroutines .. */
  123. /* .. */
  124. /* .. Intrinsic Functions .. */
  125. /* .. */
  126. /* .. Local Scalars .. */
  127. /* .. */
  128. /* .. Parameters .. */
  129. /* .. */
  130. /* Test the input parameters. */
  131. /* Parameter adjustments */
  132. a_dim1 = *lda;
  133. a_offset = 1 + a_dim1;
  134. a -= a_offset;
  135. c_dim1 = *ldc;
  136. c_offset = 1 + c_dim1;
  137. c__ -= c_offset;
  138. /* Function Body */
  139. if (lsame_(trans, "N")) {
  140. nrowa = *n;
  141. } else {
  142. nrowa = *k;
  143. }
  144. upper = lsame_(uplo, "U");
  145. info = 0;
  146. if (! upper && ! lsame_(uplo, "L")) {
  147. info = 1;
  148. } else if (! lsame_(trans, "N") && ! lsame_(trans,
  149. "C")) {
  150. info = 2;
  151. } else if (*n < 0) {
  152. info = 3;
  153. } else if (*k < 0) {
  154. info = 4;
  155. } else if (*lda < max(1,nrowa)) {
  156. info = 7;
  157. } else if (*ldc < max(1,*n)) {
  158. info = 10;
  159. }
  160. if (info != 0) {
  161. xerbla_("ZHERK ", &info);
  162. return 0;
  163. }
  164. /* Quick return if possible. */
  165. if (*n == 0 || (*alpha == 0. || *k == 0) && *beta == 1.) {
  166. return 0;
  167. }
  168. /* And when alpha.eq.zero. */
  169. if (*alpha == 0.) {
  170. if (upper) {
  171. if (*beta == 0.) {
  172. i__1 = *n;
  173. for (j = 1; j <= i__1; ++j) {
  174. i__2 = j;
  175. for (i__ = 1; i__ <= i__2; ++i__) {
  176. i__3 = i__ + j * c_dim1;
  177. c__[i__3].r = 0., c__[i__3].i = 0.;
  178. /* L10: */
  179. }
  180. /* L20: */
  181. }
  182. } else {
  183. i__1 = *n;
  184. for (j = 1; j <= i__1; ++j) {
  185. i__2 = j - 1;
  186. for (i__ = 1; i__ <= i__2; ++i__) {
  187. i__3 = i__ + j * c_dim1;
  188. i__4 = i__ + j * c_dim1;
  189. z__1.r = *beta * c__[i__4].r, z__1.i = *beta * c__[
  190. i__4].i;
  191. c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
  192. /* L30: */
  193. }
  194. i__2 = j + j * c_dim1;
  195. i__3 = j + j * c_dim1;
  196. d__1 = *beta * c__[i__3].r;
  197. c__[i__2].r = d__1, c__[i__2].i = 0.;
  198. /* L40: */
  199. }
  200. }
  201. } else {
  202. if (*beta == 0.) {
  203. i__1 = *n;
  204. for (j = 1; j <= i__1; ++j) {
  205. i__2 = *n;
  206. for (i__ = j; i__ <= i__2; ++i__) {
  207. i__3 = i__ + j * c_dim1;
  208. c__[i__3].r = 0., c__[i__3].i = 0.;
  209. /* L50: */
  210. }
  211. /* L60: */
  212. }
  213. } else {
  214. i__1 = *n;
  215. for (j = 1; j <= i__1; ++j) {
  216. i__2 = j + j * c_dim1;
  217. i__3 = j + j * c_dim1;
  218. d__1 = *beta * c__[i__3].r;
  219. c__[i__2].r = d__1, c__[i__2].i = 0.;
  220. i__2 = *n;
  221. for (i__ = j + 1; i__ <= i__2; ++i__) {
  222. i__3 = i__ + j * c_dim1;
  223. i__4 = i__ + j * c_dim1;
  224. z__1.r = *beta * c__[i__4].r, z__1.i = *beta * c__[
  225. i__4].i;
  226. c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
  227. /* L70: */
  228. }
  229. /* L80: */
  230. }
  231. }
  232. }
  233. return 0;
  234. }
  235. /* Start the operations. */
  236. if (lsame_(trans, "N")) {
  237. /* Form C := alpha*A*conjg( A' ) + beta*C. */
  238. if (upper) {
  239. i__1 = *n;
  240. for (j = 1; j <= i__1; ++j) {
  241. if (*beta == 0.) {
  242. i__2 = j;
  243. for (i__ = 1; i__ <= i__2; ++i__) {
  244. i__3 = i__ + j * c_dim1;
  245. c__[i__3].r = 0., c__[i__3].i = 0.;
  246. /* L90: */
  247. }
  248. } else if (*beta != 1.) {
  249. i__2 = j - 1;
  250. for (i__ = 1; i__ <= i__2; ++i__) {
  251. i__3 = i__ + j * c_dim1;
  252. i__4 = i__ + j * c_dim1;
  253. z__1.r = *beta * c__[i__4].r, z__1.i = *beta * c__[
  254. i__4].i;
  255. c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
  256. /* L100: */
  257. }
  258. i__2 = j + j * c_dim1;
  259. i__3 = j + j * c_dim1;
  260. d__1 = *beta * c__[i__3].r;
  261. c__[i__2].r = d__1, c__[i__2].i = 0.;
  262. } else {
  263. i__2 = j + j * c_dim1;
  264. i__3 = j + j * c_dim1;
  265. d__1 = c__[i__3].r;
  266. c__[i__2].r = d__1, c__[i__2].i = 0.;
  267. }
  268. i__2 = *k;
  269. for (l = 1; l <= i__2; ++l) {
  270. i__3 = j + l * a_dim1;
  271. if (a[i__3].r != 0. || a[i__3].i != 0.) {
  272. d_cnjg(&z__2, &a[j + l * a_dim1]);
  273. z__1.r = *alpha * z__2.r, z__1.i = *alpha * z__2.i;
  274. temp.r = z__1.r, temp.i = z__1.i;
  275. i__3 = j - 1;
  276. for (i__ = 1; i__ <= i__3; ++i__) {
  277. i__4 = i__ + j * c_dim1;
  278. i__5 = i__ + j * c_dim1;
  279. i__6 = i__ + l * a_dim1;
  280. z__2.r = temp.r * a[i__6].r - temp.i * a[i__6].i,
  281. z__2.i = temp.r * a[i__6].i + temp.i * a[
  282. i__6].r;
  283. z__1.r = c__[i__5].r + z__2.r, z__1.i = c__[i__5]
  284. .i + z__2.i;
  285. c__[i__4].r = z__1.r, c__[i__4].i = z__1.i;
  286. /* L110: */
  287. }
  288. i__3 = j + j * c_dim1;
  289. i__4 = j + j * c_dim1;
  290. i__5 = i__ + l * a_dim1;
  291. z__1.r = temp.r * a[i__5].r - temp.i * a[i__5].i,
  292. z__1.i = temp.r * a[i__5].i + temp.i * a[i__5]
  293. .r;
  294. d__1 = c__[i__4].r + z__1.r;
  295. c__[i__3].r = d__1, c__[i__3].i = 0.;
  296. }
  297. /* L120: */
  298. }
  299. /* L130: */
  300. }
  301. } else {
  302. i__1 = *n;
  303. for (j = 1; j <= i__1; ++j) {
  304. if (*beta == 0.) {
  305. i__2 = *n;
  306. for (i__ = j; i__ <= i__2; ++i__) {
  307. i__3 = i__ + j * c_dim1;
  308. c__[i__3].r = 0., c__[i__3].i = 0.;
  309. /* L140: */
  310. }
  311. } else if (*beta != 1.) {
  312. i__2 = j + j * c_dim1;
  313. i__3 = j + j * c_dim1;
  314. d__1 = *beta * c__[i__3].r;
  315. c__[i__2].r = d__1, c__[i__2].i = 0.;
  316. i__2 = *n;
  317. for (i__ = j + 1; i__ <= i__2; ++i__) {
  318. i__3 = i__ + j * c_dim1;
  319. i__4 = i__ + j * c_dim1;
  320. z__1.r = *beta * c__[i__4].r, z__1.i = *beta * c__[
  321. i__4].i;
  322. c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
  323. /* L150: */
  324. }
  325. } else {
  326. i__2 = j + j * c_dim1;
  327. i__3 = j + j * c_dim1;
  328. d__1 = c__[i__3].r;
  329. c__[i__2].r = d__1, c__[i__2].i = 0.;
  330. }
  331. i__2 = *k;
  332. for (l = 1; l <= i__2; ++l) {
  333. i__3 = j + l * a_dim1;
  334. if (a[i__3].r != 0. || a[i__3].i != 0.) {
  335. d_cnjg(&z__2, &a[j + l * a_dim1]);
  336. z__1.r = *alpha * z__2.r, z__1.i = *alpha * z__2.i;
  337. temp.r = z__1.r, temp.i = z__1.i;
  338. i__3 = j + j * c_dim1;
  339. i__4 = j + j * c_dim1;
  340. i__5 = j + l * a_dim1;
  341. z__1.r = temp.r * a[i__5].r - temp.i * a[i__5].i,
  342. z__1.i = temp.r * a[i__5].i + temp.i * a[i__5]
  343. .r;
  344. d__1 = c__[i__4].r + z__1.r;
  345. c__[i__3].r = d__1, c__[i__3].i = 0.;
  346. i__3 = *n;
  347. for (i__ = j + 1; i__ <= i__3; ++i__) {
  348. i__4 = i__ + j * c_dim1;
  349. i__5 = i__ + j * c_dim1;
  350. i__6 = i__ + l * a_dim1;
  351. z__2.r = temp.r * a[i__6].r - temp.i * a[i__6].i,
  352. z__2.i = temp.r * a[i__6].i + temp.i * a[
  353. i__6].r;
  354. z__1.r = c__[i__5].r + z__2.r, z__1.i = c__[i__5]
  355. .i + z__2.i;
  356. c__[i__4].r = z__1.r, c__[i__4].i = z__1.i;
  357. /* L160: */
  358. }
  359. }
  360. /* L170: */
  361. }
  362. /* L180: */
  363. }
  364. }
  365. } else {
  366. /* Form C := alpha*conjg( A' )*A + beta*C. */
  367. if (upper) {
  368. i__1 = *n;
  369. for (j = 1; j <= i__1; ++j) {
  370. i__2 = j - 1;
  371. for (i__ = 1; i__ <= i__2; ++i__) {
  372. temp.r = 0., temp.i = 0.;
  373. i__3 = *k;
  374. for (l = 1; l <= i__3; ++l) {
  375. d_cnjg(&z__3, &a[l + i__ * a_dim1]);
  376. i__4 = l + j * a_dim1;
  377. z__2.r = z__3.r * a[i__4].r - z__3.i * a[i__4].i,
  378. z__2.i = z__3.r * a[i__4].i + z__3.i * a[i__4]
  379. .r;
  380. z__1.r = temp.r + z__2.r, z__1.i = temp.i + z__2.i;
  381. temp.r = z__1.r, temp.i = z__1.i;
  382. /* L190: */
  383. }
  384. if (*beta == 0.) {
  385. i__3 = i__ + j * c_dim1;
  386. z__1.r = *alpha * temp.r, z__1.i = *alpha * temp.i;
  387. c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
  388. } else {
  389. i__3 = i__ + j * c_dim1;
  390. z__2.r = *alpha * temp.r, z__2.i = *alpha * temp.i;
  391. i__4 = i__ + j * c_dim1;
  392. z__3.r = *beta * c__[i__4].r, z__3.i = *beta * c__[
  393. i__4].i;
  394. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  395. c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
  396. }
  397. /* L200: */
  398. }
  399. rtemp = 0.;
  400. i__2 = *k;
  401. for (l = 1; l <= i__2; ++l) {
  402. d_cnjg(&z__3, &a[l + j * a_dim1]);
  403. i__3 = l + j * a_dim1;
  404. z__2.r = z__3.r * a[i__3].r - z__3.i * a[i__3].i, z__2.i =
  405. z__3.r * a[i__3].i + z__3.i * a[i__3].r;
  406. z__1.r = rtemp + z__2.r, z__1.i = z__2.i;
  407. rtemp = z__1.r;
  408. /* L210: */
  409. }
  410. if (*beta == 0.) {
  411. i__2 = j + j * c_dim1;
  412. d__1 = *alpha * rtemp;
  413. c__[i__2].r = d__1, c__[i__2].i = 0.;
  414. } else {
  415. i__2 = j + j * c_dim1;
  416. i__3 = j + j * c_dim1;
  417. d__1 = *alpha * rtemp + *beta * c__[i__3].r;
  418. c__[i__2].r = d__1, c__[i__2].i = 0.;
  419. }
  420. /* L220: */
  421. }
  422. } else {
  423. i__1 = *n;
  424. for (j = 1; j <= i__1; ++j) {
  425. rtemp = 0.;
  426. i__2 = *k;
  427. for (l = 1; l <= i__2; ++l) {
  428. d_cnjg(&z__3, &a[l + j * a_dim1]);
  429. i__3 = l + j * a_dim1;
  430. z__2.r = z__3.r * a[i__3].r - z__3.i * a[i__3].i, z__2.i =
  431. z__3.r * a[i__3].i + z__3.i * a[i__3].r;
  432. z__1.r = rtemp + z__2.r, z__1.i = z__2.i;
  433. rtemp = z__1.r;
  434. /* L230: */
  435. }
  436. if (*beta == 0.) {
  437. i__2 = j + j * c_dim1;
  438. d__1 = *alpha * rtemp;
  439. c__[i__2].r = d__1, c__[i__2].i = 0.;
  440. } else {
  441. i__2 = j + j * c_dim1;
  442. i__3 = j + j * c_dim1;
  443. d__1 = *alpha * rtemp + *beta * c__[i__3].r;
  444. c__[i__2].r = d__1, c__[i__2].i = 0.;
  445. }
  446. i__2 = *n;
  447. for (i__ = j + 1; i__ <= i__2; ++i__) {
  448. temp.r = 0., temp.i = 0.;
  449. i__3 = *k;
  450. for (l = 1; l <= i__3; ++l) {
  451. d_cnjg(&z__3, &a[l + i__ * a_dim1]);
  452. i__4 = l + j * a_dim1;
  453. z__2.r = z__3.r * a[i__4].r - z__3.i * a[i__4].i,
  454. z__2.i = z__3.r * a[i__4].i + z__3.i * a[i__4]
  455. .r;
  456. z__1.r = temp.r + z__2.r, z__1.i = temp.i + z__2.i;
  457. temp.r = z__1.r, temp.i = z__1.i;
  458. /* L240: */
  459. }
  460. if (*beta == 0.) {
  461. i__3 = i__ + j * c_dim1;
  462. z__1.r = *alpha * temp.r, z__1.i = *alpha * temp.i;
  463. c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
  464. } else {
  465. i__3 = i__ + j * c_dim1;
  466. z__2.r = *alpha * temp.r, z__2.i = *alpha * temp.i;
  467. i__4 = i__ + j * c_dim1;
  468. z__3.r = *beta * c__[i__4].r, z__3.i = *beta * c__[
  469. i__4].i;
  470. z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
  471. c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
  472. }
  473. /* L250: */
  474. }
  475. /* L260: */
  476. }
  477. }
  478. }
  479. return 0;
  480. /* End of ZHERK . */
  481. } /* zherk_ */