operator * method

  1. @override
Matrix<double> operator *(
  1. Matrix<double> other
)
override

Returns the product of two matrices.

Implementation

@override
Matrix<double> operator *(Matrix<double> other) {
  if (columnCount != other.rowCount) {
    throw const MatrixException('Matrices shapes mismatch! The column count '
        'of the source matrix must match the row count of the other.');
  }

  // Performing the product
  final flatMatrix = List.generate(
    rowCount * columnCount,
    (_) => 0.0,
    growable: false,
  );

  // Performing the multiplication
  for (var i = 0; i < rowCount; i++) {
    for (var j = 0; j < other.columnCount; j++) {
      var sum = 0.0;
      for (var k = 0; k < rowCount; k++) {
        sum += this(i, k) * other(k, j);
      }
      _setDataAt(flatMatrix, i, j, sum);
    }
  }

  // Building the new matrix
  return RealMatrix.fromFlattenedData(
    rows: rowCount,
    columns: columnCount,
    data: flatMatrix,
  );
}