Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub fn matmul(a: var, b: var) [a.len][b[0].len]@typeOf(a[0][0]) {
- const T = @typeOf(a[0][0]);
- const M = a.len;
- const N = a[0].len;
- const P = b[0].len;
- if (T != @typeOf(b[0][0])) @compileError("element type mismatch");
- if (N != b.len) @compileError("size mismatch");
- var result = [_][P]T{[_]T{0} ** P} ** M;
- var m: u64 = 0;
- while (m < M) : (m += 1) {
- var n: u64 = 0;
- while (n < N) : (n += 1) {
- var p: u64 = 0;
- while (p < P) : (p += 1) {
- result[m][p] += a[m][n] * b[n][p];
- }
- }
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement