dsyr2k.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /* dsyr2k.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 dsyr2k_(char *uplo, char *trans, integer *n, integer *k,
  14. doublereal *alpha, doublereal *a, integer *lda, doublereal *b,
  15. integer *ldb, doublereal *beta, doublereal *c__, integer *ldc)
  16. {
  17. /* System generated locals */
  18. integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, i__1, i__2,
  19. i__3;
  20. /* Local variables */
  21. integer i__, j, l, info;
  22. doublereal temp1, temp2;
  23. extern logical lsame_(char *, char *);
  24. integer nrowa;
  25. logical upper;
  26. extern /* Subroutine */ int xerbla_(char *, integer *);
  27. /* .. Scalar Arguments .. */
  28. /* .. */
  29. /* .. Array Arguments .. */
  30. /* .. */
  31. /* Purpose */
  32. /* ======= */
  33. /* DSYR2K performs one of the symmetric rank 2k operations */
  34. /* C := alpha*A*B' + alpha*B*A' + beta*C, */
  35. /* or */
  36. /* C := alpha*A'*B + alpha*B'*A + beta*C, */
  37. /* where alpha and beta are scalars, C is an n by n symmetric matrix */
  38. /* and A and B are n by k matrices in the first case and k by n */
  39. /* matrices in the second case. */
  40. /* Arguments */
  41. /* ========== */
  42. /* UPLO - CHARACTER*1. */
  43. /* On entry, UPLO specifies whether the upper or lower */
  44. /* triangular part of the array C is to be referenced as */
  45. /* follows: */
  46. /* UPLO = 'U' or 'u' Only the upper triangular part of C */
  47. /* is to be referenced. */
  48. /* UPLO = 'L' or 'l' Only the lower triangular part of C */
  49. /* is to be referenced. */
  50. /* Unchanged on exit. */
  51. /* TRANS - CHARACTER*1. */
  52. /* On entry, TRANS specifies the operation to be performed as */
  53. /* follows: */
  54. /* TRANS = 'N' or 'n' C := alpha*A*B' + alpha*B*A' + */
  55. /* beta*C. */
  56. /* TRANS = 'T' or 't' C := alpha*A'*B + alpha*B'*A + */
  57. /* beta*C. */
  58. /* TRANS = 'C' or 'c' C := alpha*A'*B + alpha*B'*A + */
  59. /* beta*C. */
  60. /* Unchanged on exit. */
  61. /* N - INTEGER. */
  62. /* On entry, N specifies the order of the matrix C. N must be */
  63. /* at least zero. */
  64. /* Unchanged on exit. */
  65. /* K - INTEGER. */
  66. /* On entry with TRANS = 'N' or 'n', K specifies the number */
  67. /* of columns of the matrices A and B, and on entry with */
  68. /* TRANS = 'T' or 't' or 'C' or 'c', K specifies the number */
  69. /* of rows of the matrices A and B. K must be at least zero. */
  70. /* Unchanged on exit. */
  71. /* ALPHA - DOUBLE PRECISION. */
  72. /* On entry, ALPHA specifies the scalar alpha. */
  73. /* Unchanged on exit. */
  74. /* A - DOUBLE PRECISION array of DIMENSION ( LDA, ka ), where ka is */
  75. /* k when TRANS = 'N' or 'n', and is n otherwise. */
  76. /* Before entry with TRANS = 'N' or 'n', the leading n by k */
  77. /* part of the array A must contain the matrix A, otherwise */
  78. /* the leading k by n part of the array A must contain the */
  79. /* matrix A. */
  80. /* Unchanged on exit. */
  81. /* LDA - INTEGER. */
  82. /* On entry, LDA specifies the first dimension of A as declared */
  83. /* in the calling (sub) program. When TRANS = 'N' or 'n' */
  84. /* then LDA must be at least max( 1, n ), otherwise LDA must */
  85. /* be at least max( 1, k ). */
  86. /* Unchanged on exit. */
  87. /* B - DOUBLE PRECISION array of DIMENSION ( LDB, kb ), where kb is */
  88. /* k when TRANS = 'N' or 'n', and is n otherwise. */
  89. /* Before entry with TRANS = 'N' or 'n', the leading n by k */
  90. /* part of the array B must contain the matrix B, otherwise */
  91. /* the leading k by n part of the array B must contain the */
  92. /* matrix B. */
  93. /* Unchanged on exit. */
  94. /* LDB - INTEGER. */
  95. /* On entry, LDB specifies the first dimension of B as declared */
  96. /* in the calling (sub) program. When TRANS = 'N' or 'n' */
  97. /* then LDB must be at least max( 1, n ), otherwise LDB must */
  98. /* be at least max( 1, k ). */
  99. /* Unchanged on exit. */
  100. /* BETA - DOUBLE PRECISION. */
  101. /* On entry, BETA specifies the scalar beta. */
  102. /* Unchanged on exit. */
  103. /* C - DOUBLE PRECISION array of DIMENSION ( LDC, n ). */
  104. /* Before entry with UPLO = 'U' or 'u', the leading n by n */
  105. /* upper triangular part of the array C must contain the upper */
  106. /* triangular part of the symmetric matrix and the strictly */
  107. /* lower triangular part of C is not referenced. On exit, the */
  108. /* upper triangular part of the array C is overwritten by the */
  109. /* upper triangular part of the updated matrix. */
  110. /* Before entry with UPLO = 'L' or 'l', the leading n by n */
  111. /* lower triangular part of the array C must contain the lower */
  112. /* triangular part of the symmetric matrix and the strictly */
  113. /* upper triangular part of C is not referenced. On exit, the */
  114. /* lower triangular part of the array C is overwritten by the */
  115. /* lower triangular part of the updated matrix. */
  116. /* LDC - INTEGER. */
  117. /* On entry, LDC specifies the first dimension of C as declared */
  118. /* in the calling (sub) program. LDC must be at least */
  119. /* max( 1, n ). */
  120. /* Unchanged on exit. */
  121. /* Level 3 Blas routine. */
  122. /* -- Written on 8-February-1989. */
  123. /* Jack Dongarra, Argonne National Laboratory. */
  124. /* Iain Duff, AERE Harwell. */
  125. /* Jeremy Du Croz, Numerical Algorithms Group Ltd. */
  126. /* Sven Hammarling, Numerical Algorithms Group Ltd. */
  127. /* .. External Functions .. */
  128. /* .. */
  129. /* .. External Subroutines .. */
  130. /* .. */
  131. /* .. Intrinsic Functions .. */
  132. /* .. */
  133. /* .. Local Scalars .. */
  134. /* .. */
  135. /* .. Parameters .. */
  136. /* .. */
  137. /* Test the input parameters. */
  138. /* Parameter adjustments */
  139. a_dim1 = *lda;
  140. a_offset = 1 + a_dim1;
  141. a -= a_offset;
  142. b_dim1 = *ldb;
  143. b_offset = 1 + b_dim1;
  144. b -= b_offset;
  145. c_dim1 = *ldc;
  146. c_offset = 1 + c_dim1;
  147. c__ -= c_offset;
  148. /* Function Body */
  149. if (lsame_(trans, "N")) {
  150. nrowa = *n;
  151. } else {
  152. nrowa = *k;
  153. }
  154. upper = lsame_(uplo, "U");
  155. info = 0;
  156. if (! upper && ! lsame_(uplo, "L")) {
  157. info = 1;
  158. } else if (! lsame_(trans, "N") && ! lsame_(trans,
  159. "T") && ! lsame_(trans, "C")) {
  160. info = 2;
  161. } else if (*n < 0) {
  162. info = 3;
  163. } else if (*k < 0) {
  164. info = 4;
  165. } else if (*lda < max(1,nrowa)) {
  166. info = 7;
  167. } else if (*ldb < max(1,nrowa)) {
  168. info = 9;
  169. } else if (*ldc < max(1,*n)) {
  170. info = 12;
  171. }
  172. if (info != 0) {
  173. xerbla_("DSYR2K", &info);
  174. return 0;
  175. }
  176. /* Quick return if possible. */
  177. if (*n == 0 || (*alpha == 0. || *k == 0) && *beta == 1.) {
  178. return 0;
  179. }
  180. /* And when alpha.eq.zero. */
  181. if (*alpha == 0.) {
  182. if (upper) {
  183. if (*beta == 0.) {
  184. i__1 = *n;
  185. for (j = 1; j <= i__1; ++j) {
  186. i__2 = j;
  187. for (i__ = 1; i__ <= i__2; ++i__) {
  188. c__[i__ + j * c_dim1] = 0.;
  189. /* L10: */
  190. }
  191. /* L20: */
  192. }
  193. } else {
  194. i__1 = *n;
  195. for (j = 1; j <= i__1; ++j) {
  196. i__2 = j;
  197. for (i__ = 1; i__ <= i__2; ++i__) {
  198. c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
  199. /* L30: */
  200. }
  201. /* L40: */
  202. }
  203. }
  204. } else {
  205. if (*beta == 0.) {
  206. i__1 = *n;
  207. for (j = 1; j <= i__1; ++j) {
  208. i__2 = *n;
  209. for (i__ = j; i__ <= i__2; ++i__) {
  210. c__[i__ + j * c_dim1] = 0.;
  211. /* L50: */
  212. }
  213. /* L60: */
  214. }
  215. } else {
  216. i__1 = *n;
  217. for (j = 1; j <= i__1; ++j) {
  218. i__2 = *n;
  219. for (i__ = j; i__ <= i__2; ++i__) {
  220. c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
  221. /* L70: */
  222. }
  223. /* L80: */
  224. }
  225. }
  226. }
  227. return 0;
  228. }
  229. /* Start the operations. */
  230. if (lsame_(trans, "N")) {
  231. /* Form C := alpha*A*B' + alpha*B*A' + C. */
  232. if (upper) {
  233. i__1 = *n;
  234. for (j = 1; j <= i__1; ++j) {
  235. if (*beta == 0.) {
  236. i__2 = j;
  237. for (i__ = 1; i__ <= i__2; ++i__) {
  238. c__[i__ + j * c_dim1] = 0.;
  239. /* L90: */
  240. }
  241. } else if (*beta != 1.) {
  242. i__2 = j;
  243. for (i__ = 1; i__ <= i__2; ++i__) {
  244. c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
  245. /* L100: */
  246. }
  247. }
  248. i__2 = *k;
  249. for (l = 1; l <= i__2; ++l) {
  250. if (a[j + l * a_dim1] != 0. || b[j + l * b_dim1] != 0.) {
  251. temp1 = *alpha * b[j + l * b_dim1];
  252. temp2 = *alpha * a[j + l * a_dim1];
  253. i__3 = j;
  254. for (i__ = 1; i__ <= i__3; ++i__) {
  255. c__[i__ + j * c_dim1] = c__[i__ + j * c_dim1] + a[
  256. i__ + l * a_dim1] * temp1 + b[i__ + l *
  257. b_dim1] * temp2;
  258. /* L110: */
  259. }
  260. }
  261. /* L120: */
  262. }
  263. /* L130: */
  264. }
  265. } else {
  266. i__1 = *n;
  267. for (j = 1; j <= i__1; ++j) {
  268. if (*beta == 0.) {
  269. i__2 = *n;
  270. for (i__ = j; i__ <= i__2; ++i__) {
  271. c__[i__ + j * c_dim1] = 0.;
  272. /* L140: */
  273. }
  274. } else if (*beta != 1.) {
  275. i__2 = *n;
  276. for (i__ = j; i__ <= i__2; ++i__) {
  277. c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
  278. /* L150: */
  279. }
  280. }
  281. i__2 = *k;
  282. for (l = 1; l <= i__2; ++l) {
  283. if (a[j + l * a_dim1] != 0. || b[j + l * b_dim1] != 0.) {
  284. temp1 = *alpha * b[j + l * b_dim1];
  285. temp2 = *alpha * a[j + l * a_dim1];
  286. i__3 = *n;
  287. for (i__ = j; i__ <= i__3; ++i__) {
  288. c__[i__ + j * c_dim1] = c__[i__ + j * c_dim1] + a[
  289. i__ + l * a_dim1] * temp1 + b[i__ + l *
  290. b_dim1] * temp2;
  291. /* L160: */
  292. }
  293. }
  294. /* L170: */
  295. }
  296. /* L180: */
  297. }
  298. }
  299. } else {
  300. /* Form C := alpha*A'*B + alpha*B'*A + C. */
  301. if (upper) {
  302. i__1 = *n;
  303. for (j = 1; j <= i__1; ++j) {
  304. i__2 = j;
  305. for (i__ = 1; i__ <= i__2; ++i__) {
  306. temp1 = 0.;
  307. temp2 = 0.;
  308. i__3 = *k;
  309. for (l = 1; l <= i__3; ++l) {
  310. temp1 += a[l + i__ * a_dim1] * b[l + j * b_dim1];
  311. temp2 += b[l + i__ * b_dim1] * a[l + j * a_dim1];
  312. /* L190: */
  313. }
  314. if (*beta == 0.) {
  315. c__[i__ + j * c_dim1] = *alpha * temp1 + *alpha *
  316. temp2;
  317. } else {
  318. c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1]
  319. + *alpha * temp1 + *alpha * temp2;
  320. }
  321. /* L200: */
  322. }
  323. /* L210: */
  324. }
  325. } else {
  326. i__1 = *n;
  327. for (j = 1; j <= i__1; ++j) {
  328. i__2 = *n;
  329. for (i__ = j; i__ <= i__2; ++i__) {
  330. temp1 = 0.;
  331. temp2 = 0.;
  332. i__3 = *k;
  333. for (l = 1; l <= i__3; ++l) {
  334. temp1 += a[l + i__ * a_dim1] * b[l + j * b_dim1];
  335. temp2 += b[l + i__ * b_dim1] * a[l + j * a_dim1];
  336. /* L220: */
  337. }
  338. if (*beta == 0.) {
  339. c__[i__ + j * c_dim1] = *alpha * temp1 + *alpha *
  340. temp2;
  341. } else {
  342. c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1]
  343. + *alpha * temp1 + *alpha * temp2;
  344. }
  345. /* L230: */
  346. }
  347. /* L240: */
  348. }
  349. }
  350. }
  351. return 0;
  352. /* End of DSYR2K. */
  353. } /* dsyr2k_ */