zhemm.c 16 KB

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