operator / method

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

Returns the division of two matrices.

An exception is thrown if the column count of the source matrix does not match the row count of the other matrix.

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 division
  final flatMatrix = List.generate(
    rowCount * columnCount,
    (_) => 0.0,
    growable: false,
  );

  // Performing the division
  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,
  );
}