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 ((rowCount != other.rowCount) || (columnCount != other.columnCount)) {
    throw const MatrixException('Matrices shapes mismatch! The column count '
        'of the source matrix must match the row count of the other.');
  }

  // Performing the sum
  final flatMatrix = List.generate(
    rowCount * columnCount,
    (_) => const Complex.zero(),
    growable: false,
  );

  for (var i = 0; i < rowCount; ++i) {
    for (var j = 0; j < columnCount; ++j) {
      _setDataAt(flatMatrix, i, j, this(i, j) + other(i, j));
    }
  }

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