Skip to content

Commit

Permalink
[bug] Matrix refactor bug fix: Fix restrictions on BinaryOp/TernaryOp…
Browse files Browse the repository at this point in the history
… operands' broadcasting (taichi-dev#6805)

Issue: taichi-dev#5819

### Brief Summary
  • Loading branch information
jim19930609 authored and quadpixels committed May 13, 2023
1 parent b7e6bf7 commit abe623b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions taichi/ir/frontend_ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,17 @@ void UnaryOpExpression::flatten(FlattenContext *ctx) {
}

Expr to_broadcast_tensor(const Expr &elt, const DataType &dt) {
TI_ASSERT(dt->is<TensorType>());
if (elt->ret_type == dt) {
if (!elt->ret_type->is<TensorType>() && !dt->is<TensorType>())
return elt;
} else if (elt->ret_type->is<TensorType>()) {
TI_ERROR("Cannot broadcast tensor to tensor");

if (elt->ret_type->is<TensorType>() && dt->is<TensorType>()) {
// Only tensor shape will be checked here, since the dtype will
// be promoted later at irpass::type_check()
if (elt->ret_type.get_shape() != dt.get_shape()) {
TI_ERROR("Cannot broadcast tensor to tensor");
} else {
return elt;
}
}

auto tensor_type = dt->as<TensorType>();
Expand Down

0 comments on commit abe623b

Please sign in to comment.