Debian Codegraph @

external/gsl/gsl_cblas__source_gemm_r.h

raw
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 {
21 INDEX i, j, k;
22 INDEX n1, n2;
23 INDEX ldf, ldg;
24 int TransF, TransG;
25 const BASE *F, *G;
26
27 if (alpha == 0.0 && beta == 1.0)
28 return;
29
30 if (Order == CblasRowMajor) {
31 n1 = M;
32 n2 = N;
33 F = A;
34 ldf = lda;
35 TransF = (TransA == CblasConjTrans) ? CblasTrans : TransA;
36 G = B;
37 ldg = ldb;
38 TransG = (TransB == CblasConjTrans) ? CblasTrans : TransB;
39 } else {
40 n1 = N;
41 n2 = M;
42 F = B;
43 ldf = ldb;
44 TransF = (TransB == CblasConjTrans) ? CblasTrans : TransB;
45 G = A;
46 ldg = lda;
47 TransG = (TransA == CblasConjTrans) ? CblasTrans : TransA;
48 }
49
50 /* form y := beta*y */
51 if (beta == 0.0) {
52 for (i = 0; i < n1; i++) {
53 for (j = 0; j < n2; j++) {
54 C[ldc * i + j] = 0.0;
55 }
56 }
57 } else if (beta != 1.0) {
58 for (i = 0; i < n1; i++) {
59 for (j = 0; j < n2; j++) {
60 C[ldc * i + j] *= beta;
61 }
62 }
63 }
64
65 if (alpha == 0.0)
66 return;
67
68 if (TransF == CblasNoTrans && TransG == CblasNoTrans) {
69
70 /* form C := alpha*A*B + C */
71
72 for (k = 0; k < K; k++) {
73 for (i = 0; i < n1; i++) {
74 const BASE temp = alpha * F[ldf * i + k];
75 if (temp != 0.0) {
76 for (j = 0; j < n2; j++) {
77 C[ldc * i + j] += temp * G[ldg * k + j];
78 }
79 }
80 }
81 }
82
83 } else if (TransF == CblasNoTrans && TransG == CblasTrans) {
84
85 /* form C := alpha*A*B' + C */
86
87 for (i = 0; i < n1; i++) {
88 for (j = 0; j < n2; j++) {
89 BASE temp = 0.0;
90 for (k = 0; k < K; k++) {
91 temp += F[ldf * i + k] * G[ldg * j + k];
92 }
93 C[ldc * i + j] += alpha * temp;
94 }
95 }
96
97 } else if (TransF == CblasTrans && TransG == CblasNoTrans) {
98
99 for (k = 0; k < K; k++) {
100 for (i = 0; i < n1; i++) {
101 const BASE temp = alpha * F[ldf * k + i];
102 if (temp != 0.0) {
103 for (j = 0; j < n2; j++) {
104 C[ldc * i + j] += temp * G[ldg * k + j];
105 }
106 }
107 }
108 }
109
110 } else if (TransF == CblasTrans && TransG == CblasTrans) {
111
112 for (i = 0; i < n1; i++) {
113 for (j = 0; j < n2; j++) {
114 BASE temp = 0.0;
115 for (k = 0; k < K; k++) {
116 temp += F[ldf * k + i] * G[ldg * j + k];
117 }
118 C[ldc * i + j] += alpha * temp;
119 }
120 }
121
122 } else {
123 BLAS_ERROR("unrecognized operation");
124 }
125 }