operator + method
Returns the sum of two matrices.
Implementation
@override
Matrix<double> operator +(Matrix<double> 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<double>.generate(
rowCount * columnCount,
(_) => 0.0,
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 RealMatrix.fromFlattenedData(
rows: rowCount,
columns: columnCount,
data: flatMatrix,
);
}