Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. pub fn matmul(a: var, b: var) [a.len][b[0].len]@typeOf(a[0][0]) {
  2. const T = @typeOf(a[0][0]);
  3. const M = a.len;
  4. const N = a[0].len;
  5. const P = b[0].len;
  6. if (T != @typeOf(b[0][0])) @compileError("element type mismatch");
  7. if (N != b.len) @compileError("size mismatch");
  8. var result = [_][P]T{[_]T{0} ** P} ** M;
  9. var m: u64 = 0;
  10. while (m < M) : (m += 1) {
  11. var n: u64 = 0;
  12. while (n < N) : (n += 1) {
  13. var p: u64 = 0;
  14. while (p < P) : (p += 1) {
  15. result[m][p] += a[m][n] * b[n][p];
  16. }
  17. }
  18. }
  19. return result;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement