matMul method

Array matMul(
  1. Array other
)

Implementation

Array matMul(Array other) {
  assert(this.shape.item2 == other.shape.item1);

  // "this" is a m x n matrix
  // "other" is a n x p matrix

  var m = this.shape.item1;
  var n = this.shape.item2;
  var p = other.shape.item2;

  var shape = Tuple2(this.shape.item1, other.shape.item2);

  var mat = Array.zeros(shape: shape);

  for (var i in range(end: m)) {
    for (var j in range(end: p)) {
      for (var k in range(end: n)) {
        mat.values[i][j] += values[i][k] * other.values[k][j];
      }
    }
  }

  return mat;
}