operator * method

Matrix2d operator *(
  1. dynamic other
)

Implementation

Matrix2d operator *(dynamic other) {
  if (other is num) {
    return Matrix2d(
        _rows,
        _cols,
        ValueVector(List.generate(_cols * _rows, (int index) {
          return data!.values[index] * other;
        })));
  } else if (other is Matrix2d) {
    if (_cols != other._rows) {
      throw ArgumentError("Matrix multiplication requires A.cols == B.rows.");
    }
    Matrix2d result = Matrix2d(_rows, other._cols);
    for (int i = 0; i < _rows; i++) {
      for (int j = 0; j < other._cols; j++) {
        Value sum = Value(0);
        for (int k = 0; k < _cols; k++) {
          sum += at(i, k) * other.at(k, j);
        }
        result.data!.values[(i * other._cols + j).toInt()] = sum;
      }
    }
    return result;
  } else {
    throw UnimplementedError(
        "Operation * not supported for: ${other.runtimeType}");
  }
}