dgemm.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /* dgemm.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 dgemm_(char *transa, char *transb, integer *m, integer *
  14. n, integer *k, doublereal *alpha, doublereal *a, integer *lda,
  15. doublereal *b, integer *ldb, doublereal *beta, doublereal *c__,
  16. integer *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;
  21. /* Local variables */
  22. integer i__, j, l, info;
  23. logical nota, notb;
  24. doublereal temp;
  25. integer ncola;
  26. extern logical lsame_(char *, char *);
  27. integer nrowa, nrowb;
  28. extern /* Subroutine */ int xerbla_(char *, integer *);
  29. /* .. Scalar Arguments .. */
  30. /* .. */
  31. /* .. Array Arguments .. */
  32. /* .. */
  33. /* Purpose */
  34. /* ======= */
  35. /* DGEMM performs one of the matrix-matrix operations */
  36. /* C := alpha*op( A )*op( B ) + beta*C, */
  37. /* where op( X ) is one of */
  38. /* op( X ) = X or op( X ) = X', */
  39. /* alpha and beta are scalars, and A, B and C are matrices, with op( A ) */
  40. /* an m by k matrix, op( B ) a k by n matrix and C an m by n matrix. */
  41. /* Arguments */
  42. /* ========== */
  43. /* TRANSA - CHARACTER*1. */
  44. /* On entry, TRANSA specifies the form of op( A ) to be used in */
  45. /* the matrix multiplication as follows: */
  46. /* TRANSA = 'N' or 'n', op( A ) = A. */
  47. /* TRANSA = 'T' or 't', op( A ) = A'. */
  48. /* TRANSA = 'C' or 'c', op( A ) = A'. */
  49. /* Unchanged on exit. */
  50. /* TRANSB - CHARACTER*1. */
  51. /* On entry, TRANSB specifies the form of op( B ) to be used in */
  52. /* the matrix multiplication as follows: */
  53. /* TRANSB = 'N' or 'n', op( B ) = B. */
  54. /* TRANSB = 'T' or 't', op( B ) = B'. */
  55. /* TRANSB = 'C' or 'c', op( B ) = B'. */
  56. /* Unchanged on exit. */
  57. /* M - INTEGER. */
  58. /* On entry, M specifies the number of rows of the matrix */
  59. /* op( A ) and of the matrix C. M must be at least zero. */
  60. /* Unchanged on exit. */
  61. /* N - INTEGER. */
  62. /* On entry, N specifies the number of columns of the matrix */
  63. /* op( B ) and the number of columns of the matrix C. N must be */
  64. /* at least zero. */
  65. /* Unchanged on exit. */
  66. /* K - INTEGER. */
  67. /* On entry, K specifies the number of columns of the matrix */
  68. /* op( A ) and the number of rows of the matrix op( B ). K must */
  69. /* 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 TRANSA = 'N' or 'n', and is m otherwise. */
  76. /* Before entry with TRANSA = 'N' or 'n', the leading m by k */
  77. /* part of the array A must contain the matrix A, otherwise */
  78. /* the leading k by m 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 TRANSA = 'N' or 'n' then */
  84. /* LDA must be at least max( 1, m ), otherwise LDA must be at */
  85. /* least max( 1, k ). */
  86. /* Unchanged on exit. */
  87. /* B - DOUBLE PRECISION array of DIMENSION ( LDB, kb ), where kb is */
  88. /* n when TRANSB = 'N' or 'n', and is k otherwise. */
  89. /* Before entry with TRANSB = 'N' or 'n', the leading k by n */
  90. /* part of the array B must contain the matrix B, otherwise */
  91. /* the leading n by k 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 TRANSB = 'N' or 'n' then */
  97. /* LDB must be at least max( 1, k ), otherwise LDB must be at */
  98. /* least max( 1, n ). */
  99. /* Unchanged on exit. */
  100. /* BETA - DOUBLE PRECISION. */
  101. /* On entry, BETA specifies the scalar beta. When BETA is */
  102. /* supplied as zero then C need not be set on input. */
  103. /* Unchanged on exit. */
  104. /* C - DOUBLE PRECISION array of DIMENSION ( LDC, n ). */
  105. /* Before entry, the leading m by n part of the array C must */
  106. /* contain the matrix C, except when beta is zero, in which */
  107. /* case C need not be set on entry. */
  108. /* On exit, the array C is overwritten by the m by n matrix */
  109. /* ( alpha*op( A )*op( B ) + beta*C ). */
  110. /* LDC - INTEGER. */
  111. /* On entry, LDC specifies the first dimension of C as declared */
  112. /* in the calling (sub) program. LDC must be at least */
  113. /* max( 1, m ). */
  114. /* Unchanged on exit. */
  115. /* Level 3 Blas routine. */
  116. /* -- Written on 8-February-1989. */
  117. /* Jack Dongarra, Argonne National Laboratory. */
  118. /* Iain Duff, AERE Harwell. */
  119. /* Jeremy Du Croz, Numerical Algorithms Group Ltd. */
  120. /* Sven Hammarling, Numerical Algorithms Group Ltd. */
  121. /* .. External Functions .. */
  122. /* .. */
  123. /* .. External Subroutines .. */
  124. /* .. */
  125. /* .. Intrinsic Functions .. */
  126. /* .. */
  127. /* .. Local Scalars .. */
  128. /* .. */
  129. /* .. Parameters .. */
  130. /* .. */
  131. /* Set NOTA and NOTB as true if A and B respectively are not */
  132. /* transposed and set NROWA, NCOLA and NROWB as the number of rows */
  133. /* and columns of A and the number of rows of B respectively. */
  134. /* Parameter adjustments */
  135. a_dim1 = *lda;
  136. a_offset = 1 + a_dim1;
  137. a -= a_offset;
  138. b_dim1 = *ldb;
  139. b_offset = 1 + b_dim1;
  140. b -= b_offset;
  141. c_dim1 = *ldc;
  142. c_offset = 1 + c_dim1;
  143. c__ -= c_offset;
  144. /* Function Body */
  145. nota = lsame_(transa, "N");
  146. notb = lsame_(transb, "N");
  147. if (nota) {
  148. nrowa = *m;
  149. ncola = *k;
  150. } else {
  151. nrowa = *k;
  152. ncola = *m;
  153. }
  154. if (notb) {
  155. nrowb = *k;
  156. } else {
  157. nrowb = *n;
  158. }
  159. /* Test the input parameters. */
  160. info = 0;
  161. if (! nota && ! lsame_(transa, "C") && ! lsame_(
  162. transa, "T")) {
  163. info = 1;
  164. } else if (! notb && ! lsame_(transb, "C") && !
  165. lsame_(transb, "T")) {
  166. info = 2;
  167. } else if (*m < 0) {
  168. info = 3;
  169. } else if (*n < 0) {
  170. info = 4;
  171. } else if (*k < 0) {
  172. info = 5;
  173. } else if (*lda < max(1,nrowa)) {
  174. info = 8;
  175. } else if (*ldb < max(1,nrowb)) {
  176. info = 10;
  177. } else if (*ldc < max(1,*m)) {
  178. info = 13;
  179. }
  180. if (info != 0) {
  181. xerbla_("DGEMM ", &info);
  182. return 0;
  183. }
  184. /* Quick return if possible. */
  185. if (*m == 0 || *n == 0 || (*alpha == 0. || *k == 0) && *beta == 1.) {
  186. return 0;
  187. }
  188. /* And if alpha.eq.zero. */
  189. if (*alpha == 0.) {
  190. if (*beta == 0.) {
  191. i__1 = *n;
  192. for (j = 1; j <= i__1; ++j) {
  193. i__2 = *m;
  194. for (i__ = 1; i__ <= i__2; ++i__) {
  195. c__[i__ + j * c_dim1] = 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. c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
  206. /* L30: */
  207. }
  208. /* L40: */
  209. }
  210. }
  211. return 0;
  212. }
  213. /* Start the operations. */
  214. if (notb) {
  215. if (nota) {
  216. /* Form C := alpha*A*B + beta*C. */
  217. i__1 = *n;
  218. for (j = 1; j <= i__1; ++j) {
  219. if (*beta == 0.) {
  220. i__2 = *m;
  221. for (i__ = 1; i__ <= i__2; ++i__) {
  222. c__[i__ + j * c_dim1] = 0.;
  223. /* L50: */
  224. }
  225. } else if (*beta != 1.) {
  226. i__2 = *m;
  227. for (i__ = 1; i__ <= i__2; ++i__) {
  228. c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
  229. /* L60: */
  230. }
  231. }
  232. i__2 = *k;
  233. for (l = 1; l <= i__2; ++l) {
  234. if (b[l + j * b_dim1] != 0.) {
  235. temp = *alpha * b[l + j * b_dim1];
  236. i__3 = *m;
  237. for (i__ = 1; i__ <= i__3; ++i__) {
  238. c__[i__ + j * c_dim1] += temp * a[i__ + l *
  239. a_dim1];
  240. /* L70: */
  241. }
  242. }
  243. /* L80: */
  244. }
  245. /* L90: */
  246. }
  247. } else {
  248. /* Form C := alpha*A'*B + beta*C */
  249. i__1 = *n;
  250. for (j = 1; j <= i__1; ++j) {
  251. i__2 = *m;
  252. for (i__ = 1; i__ <= i__2; ++i__) {
  253. temp = 0.;
  254. i__3 = *k;
  255. for (l = 1; l <= i__3; ++l) {
  256. temp += a[l + i__ * a_dim1] * b[l + j * b_dim1];
  257. /* L100: */
  258. }
  259. if (*beta == 0.) {
  260. c__[i__ + j * c_dim1] = *alpha * temp;
  261. } else {
  262. c__[i__ + j * c_dim1] = *alpha * temp + *beta * c__[
  263. i__ + j * c_dim1];
  264. }
  265. /* L110: */
  266. }
  267. /* L120: */
  268. }
  269. }
  270. } else {
  271. if (nota) {
  272. /* Form C := alpha*A*B' + beta*C */
  273. i__1 = *n;
  274. for (j = 1; j <= i__1; ++j) {
  275. if (*beta == 0.) {
  276. i__2 = *m;
  277. for (i__ = 1; i__ <= i__2; ++i__) {
  278. c__[i__ + j * c_dim1] = 0.;
  279. /* L130: */
  280. }
  281. } else if (*beta != 1.) {
  282. i__2 = *m;
  283. for (i__ = 1; i__ <= i__2; ++i__) {
  284. c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
  285. /* L140: */
  286. }
  287. }
  288. i__2 = *k;
  289. for (l = 1; l <= i__2; ++l) {
  290. if (b[j + l * b_dim1] != 0.) {
  291. temp = *alpha * b[j + l * b_dim1];
  292. i__3 = *m;
  293. for (i__ = 1; i__ <= i__3; ++i__) {
  294. c__[i__ + j * c_dim1] += temp * a[i__ + l *
  295. a_dim1];
  296. /* L150: */
  297. }
  298. }
  299. /* L160: */
  300. }
  301. /* L170: */
  302. }
  303. } else {
  304. /* Form C := alpha*A'*B' + beta*C */
  305. i__1 = *n;
  306. for (j = 1; j <= i__1; ++j) {
  307. i__2 = *m;
  308. for (i__ = 1; i__ <= i__2; ++i__) {
  309. temp = 0.;
  310. i__3 = *k;
  311. for (l = 1; l <= i__3; ++l) {
  312. temp += a[l + i__ * a_dim1] * b[j + l * b_dim1];
  313. /* L180: */
  314. }
  315. if (*beta == 0.) {
  316. c__[i__ + j * c_dim1] = *alpha * temp;
  317. } else {
  318. c__[i__ + j * c_dim1] = *alpha * temp + *beta * c__[
  319. i__ + j * c_dim1];
  320. }
  321. /* L190: */
  322. }
  323. /* L200: */
  324. }
  325. }
  326. }
  327. return 0;
  328. /* End of DGEMM . */
  329. } /* dgemm_ */