isCompatibleForBroadcastWith method

bool isCompatibleForBroadcastWith(
  1. Matrix b
)

Determines whether the current matrix and matrix b are compatible for broadcasting.

Two matrices are compatible for broadcasting if, for each dimension, the dimension sizes are either equal or one of them is 1.

b The matrix to be checked for compatibility with the current matrix.

Returns true if the matrices are compatible for broadcasting, and false otherwise.

Implementation

bool isCompatibleForBroadcastWith(Matrix b) {
  return (rowCount == b.rowCount || rowCount == 1 || b.rowCount == 1) &&
      (columnCount == b.columnCount ||
          columnCount == 1 ||
          b.columnCount == 1);
}