operator * method

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

Returns the sum of two matrices.

Implementation

@override
Matrix<Complex> operator *(Matrix<Complex> 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<Complex>.generate(
    rowCount * other.columnCount,
    (_) => const Complex.zero(),
    growable: false,
  );

  // Performing the multiplication
  for (var i = 0; i < rowCount; i++) {
    for (var j = 0; j < other.columnCount; j++) {
      var sum = const Complex.zero();
      for (var k = 0; k < other.rowCount; k++) {
        sum += this(i, k) * other(k, j);
      }
      flatMatrix[other.columnCount * i + j] = sum;
    }
  }

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