multiply method

ValueMatrix multiply(
  1. ValueMatrix other
)

Implementation

ValueMatrix multiply(ValueMatrix other) {
  if (cols != other.rows) {
    throw ArgumentError(
        "Number of columns in first matrix must match number of rows in second matrix.");
  }

  final result = List<List<Value>>.generate(rows, (r) {
    return List<Value>.generate(other.cols, (c) {
      Value sum = Value(0.0);
      for (int i = 0; i < cols; i++) {
        sum += _data[r][i] * other._data[i][c];
      }
      return sum;
    });
  });
  return ValueMatrix(result);
}