masahi commented on a change in pull request #6759:
URL: https://github.com/apache/incubator-tvm/pull/6759#discussion_r511750722



##########
File path: src/relay/op/tensor/transform.cc
##########
@@ -1685,30 +1686,17 @@ bool WhereRel(const Array<Type>& types, int num_inputs, 
const Attrs& attrs,
     return false;
   }
 
-  const auto& cond_shape = condition->shape;
-  const auto& x_shape = x->shape;
-  const auto& y_shape = y->shape;
-  ICHECK(x_shape.size() == y_shape.size()) << "x and y must have the same 
size";
+  ICHECK_EQ(x->dtype, y->dtype) << "x and y must have the same dtype: " << 
x->dtype << " vs "
+                                << y->dtype;
 
-  if (cond_shape.size() != x_shape.size()) {
-    ICHECK_EQ(cond_shape.size(), 1) << "Shape of condition " << 
condition->shape
-                                    << " must be either equal to x or has 
dimension of 1.";
-  }
-  for (size_t i = 0; i < x_shape.size(); i++) {
-    ICHECK(reporter->AssertEQ(x_shape[i], y_shape[i]))
-        << "x and y must have the same shape: " << x_shape << " vs " << 
y_shape;
+  auto tensor_ty_condition = GetRef<TensorType>(condition);
+  auto tensor_ty_x = GetRef<TensorType>(x);
+  auto tensor_ty_y = GetRef<TensorType>(y);
 
-    if (i < cond_shape.size()) {
-      ICHECK(reporter->AssertEQ(cond_shape[i], x_shape[i]))
-          << "condition and x must have the same shape: " << cond_shape << " 
vs " << x_shape;
-    }
-  }
-  if (x_shape.size() == 0) {
-    // if x and y are scalar, the condition shape becomes the output shape
-    reporter->Assign(types[3], TensorType(cond_shape, x->dtype));
-  } else {
-    reporter->Assign(types[3], TensorType(x_shape, x->dtype));
-  }
+  auto b_ty = ConcreteBroadcast(tensor_ty_x, tensor_ty_y, x->dtype);
+  auto ret_ty = ConcreteBroadcast(tensor_ty_condition, b_ty, b_ty->dtype);

Review comment:
       @kevinthesun In this commit, 
https://github.com/apache/incubator-tvm/pull/6759/commits/5423c70152c088015a6e51c3c9805b12df2e1153,
 I added tests for `where` + any, and updated `where` shape func. To compute a 
shape tensor corresponding to the broadcasted shapes from condition, x, and y, 
I added a new helper function in topi cpp. 
   
   It pass all new tests I added that exercise the new shape func. But I'm not 
completely sure if the logic in `broadcast_shape_tensors` is correct. Can you 
have a look?
   
   Also it would be great if I can get more eyes on broadcasting + shape func 
logic @junrushao1994 @icemelon9  




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to