operator - method
Returns the difference 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 difference
final flatMatrix = List.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,
);
}