tensorflow/lite/delegates/coreml/builders/util.cc
// Determines if two tensor shapes are broadcastable. See comment of
// IsBinaryOpSupported for more info.
Determines if two tensor shapes are broadcastable. See comment of
IsBinaryOpSupported for more info.
Determines if two tensor shapes are broadcastable . See comment of IsBinaryOpSupported for more info .
bool IsBroadcastable(const TfLiteTensor* input_0, const TfLiteTensor* input_1) {
  std::vector<int> shape_0;
  std::vector<int> shape_1;
  Get4DShape(input_0, &shape_0);
  Get4DShape(input_1, &shape_1);
  const int B_0 = shape_0[0];
  const int B_1 = shape_1[0];
  const int H_0 = shape_0[1];
  const int H_1 = shape_1[1];
  const int W_0 = shape_0[2];
  const int W_1 = shape_1[2];
  const int C_0 = shape_0[3];
  const int C_1 = shape_1[3];
  if (B_0 != B_1) {
    if (!((IsConstantTensor(input_0) && NumElements(input_0) == 1) ||
          (IsConstantTensor(input_1) && NumElements(input_1) == 1)))
      return false;
  }
  if (H_0 != H_1 || W_0 != W_1) {
    if (!((H_0 == 1 && W_0 == 1) || (H_1 == 1 && W_1 == 1))) {
      return false;
    }
  }
  if (C_0 != C_1) {
    if (C_0 != 1 && C_1 != 1) return false;
  }
  return true;
}
bool IsBroadcastable ( const TfLiteTensor * input_0 , const TfLiteTensor * input_1 ) { std :: vector < int > shape_0 ; std :: vector < int > shape_1 ; Get4DShape ( input_0 , & shape_0 ) ; Get4DShape ( input_1 , & shape_1 ) ; const int B_0 = shape_0 [ 0 ] ; const int B_1 = shape_1 [ 0 ] ; const int H_0 = shape_0 [ 1 ] ; const int H_1 = shape_1 [ 1 ] ; const int W_0 = shape_0 [ 2 ] ; const int W_1 = shape_1 [ 2 ] ; const int C_0 = shape_0 [ 3 ] ; const int C_1 = shape_1 [ 3 ] ; if ( B_0 != B_1 ) { if ( ! ( ( IsConstantTensor ( input_0 ) && NumElements ( input_0 ) == 1 ) || ( IsConstantTensor ( input_1 ) && NumElements ( input_1 ) == 1 ) ) ) return false ; } if ( H_0 != H_1 || W_0 != W_1 ) { if ( ! ( ( H_0 == 1 && W_0 == 1 ) || ( H_1 == 1 && W_1 == 1 ) ) ) { return false ; } } if ( C_0 != C_1 ) { if ( C_0 != 1 && C_1 != 1 ) return false ; } return true ; }
Determines if two tensor shapes are broadcastable.
Determines if two tensor shapes are broadcastable .
// TFL tensor has [B, H, W, C] format. // comparing B: shape[0], (H, W): (shape[1], shape[2]), C: shape[3]. // When B is different, it's not supported unless // one of the tensor is size 1 constant tensor. // When (H, W) are different, one of the (H, W) should be (1, 1). // When C is different, one of the C should be 1.