diff options
Diffstat (limited to 'src/lib/src/matrix.c')
-rw-r--r-- | src/lib/src/matrix.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lib/src/matrix.c b/src/lib/src/matrix.c index d5c3fcc..29511eb 100644 --- a/src/lib/src/matrix.c +++ b/src/lib/src/matrix.c | |||
@@ -189,6 +189,32 @@ void nnMatrixMulRows( | |||
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
192 | void nnMatrixMulOuter( | ||
193 | const nnMatrix* left, const nnMatrix* right, nnMatrix* out) { | ||
194 | assert(left != 0); | ||
195 | assert(right != 0); | ||
196 | assert(out != 0); | ||
197 | assert(out != left); | ||
198 | assert(out != right); | ||
199 | assert((left->rows == 1) || (left->cols == 1)); // Vector. | ||
200 | assert((right->rows == 1) || (right->cols == 1)); // Vector. | ||
201 | const int N = left->rows * left->cols; | ||
202 | const int M = right->rows * right->cols; | ||
203 | assert((out->rows == N) && (out->cols == M)); | ||
204 | |||
205 | const R* left_value = left->values; | ||
206 | R* out_value = out->values; | ||
207 | |||
208 | for (int i = 0; i < N; ++i) { | ||
209 | const R* right_value = right->values; | ||
210 | |||
211 | for (int j = 0; j < M; ++j) { | ||
212 | *out_value++ = *left_value * *right_value++; | ||
213 | } | ||
214 | left_value++; | ||
215 | } | ||
216 | } | ||
217 | |||
192 | void nnMatrixMulAdd( | 218 | void nnMatrixMulAdd( |
193 | const nnMatrix* left, const nnMatrix* right, R scale, nnMatrix* out) { | 219 | const nnMatrix* left, const nnMatrix* right, R scale, nnMatrix* out) { |
194 | assert(left); | 220 | assert(left); |