gsl_cblas__source_gemm_r.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* blas/source_gemm_r.h
  2. *
  3. * Copyright (C) 2001, 2007 Brian Gough
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. {
  20. INDEX i, j, k;
  21. INDEX n1, n2;
  22. INDEX ldf, ldg;
  23. int TransF, TransG;
  24. const BASE *F, *G;
  25. if (alpha == 0.0 && beta == 1.0)
  26. return;
  27. if (Order == CblasRowMajor) {
  28. n1 = M;
  29. n2 = N;
  30. F = A;
  31. ldf = lda;
  32. TransF = (TransA == CblasConjTrans) ? CblasTrans : TransA;
  33. G = B;
  34. ldg = ldb;
  35. TransG = (TransB == CblasConjTrans) ? CblasTrans : TransB;
  36. } else {
  37. n1 = N;
  38. n2 = M;
  39. F = B;
  40. ldf = ldb;
  41. TransF = (TransB == CblasConjTrans) ? CblasTrans : TransB;
  42. G = A;
  43. ldg = lda;
  44. TransG = (TransA == CblasConjTrans) ? CblasTrans : TransA;
  45. }
  46. /* form y := beta*y */
  47. if (beta == 0.0) {
  48. for (i = 0; i < n1; i++) {
  49. for (j = 0; j < n2; j++) {
  50. C[ldc * i + j] = 0.0;
  51. }
  52. }
  53. } else if (beta != 1.0) {
  54. for (i = 0; i < n1; i++) {
  55. for (j = 0; j < n2; j++) {
  56. C[ldc * i + j] *= beta;
  57. }
  58. }
  59. }
  60. if (alpha == 0.0)
  61. return;
  62. if (TransF == CblasNoTrans && TransG == CblasNoTrans) {
  63. /* form C := alpha*A*B + C */
  64. for (k = 0; k < K; k++) {
  65. for (i = 0; i < n1; i++) {
  66. const BASE temp = alpha * F[ldf * i + k];
  67. if (temp != 0.0) {
  68. for (j = 0; j < n2; j++) {
  69. C[ldc * i + j] += temp * G[ldg * k + j];
  70. }
  71. }
  72. }
  73. }
  74. } else if (TransF == CblasNoTrans && TransG == CblasTrans) {
  75. /* form C := alpha*A*B' + C */
  76. for (i = 0; i < n1; i++) {
  77. for (j = 0; j < n2; j++) {
  78. BASE temp = 0.0;
  79. for (k = 0; k < K; k++) {
  80. temp += F[ldf * i + k] * G[ldg * j + k];
  81. }
  82. C[ldc * i + j] += alpha * temp;
  83. }
  84. }
  85. } else if (TransF == CblasTrans && TransG == CblasNoTrans) {
  86. for (k = 0; k < K; k++) {
  87. for (i = 0; i < n1; i++) {
  88. const BASE temp = alpha * F[ldf * k + i];
  89. if (temp != 0.0) {
  90. for (j = 0; j < n2; j++) {
  91. C[ldc * i + j] += temp * G[ldg * k + j];
  92. }
  93. }
  94. }
  95. }
  96. } else if (TransF == CblasTrans && TransG == CblasTrans) {
  97. for (i = 0; i < n1; i++) {
  98. for (j = 0; j < n2; j++) {
  99. BASE temp = 0.0;
  100. for (k = 0; k < K; k++) {
  101. temp += F[ldf * k + i] * G[ldg * j + k];
  102. }
  103. C[ldc * i + j] += alpha * temp;
  104. }
  105. }
  106. } else {
  107. BLAS_ERROR("unrecognized operation");
  108. }
  109. }