Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fix ret_type and cast_type of UnaryOpStmt in Scalarize #7082

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions taichi/transforms/scalarize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ class Scalarize : public BasicStmtVisitor {

std::vector<Stmt *> matrix_init_values;
int num_elements = operand_tensor_type->get_num_elements();
auto primitive_type = operand_tensor_type->get_element_type();
auto primitive_type = stmt->ret_type.get_element_type();
for (size_t i = 0; i < num_elements; i++) {
auto unary_stmt = std::make_unique<UnaryOpStmt>(
stmt->op_type, operand_matrix_init_stmt->values[i]);
if (stmt->is_cast()) {
unary_stmt->cast_type = stmt->cast_type;
unary_stmt->cast_type = stmt->cast_type.get_element_type();
}
unary_stmt->ret_type = primitive_type;
matrix_init_values.push_back(unary_stmt.get());
Expand Down
6 changes: 3 additions & 3 deletions tests/python/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,8 +1048,8 @@ def test_atomic_op_scalarize():
@ti.func
def func(x: ti.template()):
x[0] = [1., 2., 3.]
tmp = ti.Vector([3., 2., 1.])
z = ti.atomic_add(x[0], tmp)
tmp = ti.Vector([3, 2, 1])
z = ti.atomic_sub(x[0], tmp)
assert z[0] == 1.
assert z[1] == 2.
assert z[2] == 3.
Expand All @@ -1062,7 +1062,7 @@ def func(x: ti.template()):
assert g[2] == 1.

def verify(x):
assert (x[0] == [4., 4., 4.]).all()
assert (x[0] == [-2., 0., 2.]).all()
assert (x[1] == [3., 3., 3.]).all()

field = ti.Vector.field(n=3, dtype=ti.f32, shape=10)
Expand Down