Skip to content

Commit

Permalink
[bug] Fix recompilation of filling a matrix field with the same matrix (
Browse files Browse the repository at this point in the history
taichi-dev#6951)

Issue: fix taichi-dev#6950

### Brief Summary

The change to `fill()` in taichi-dev#6892 (skips turning a `ti.Matrix` into a
tuple) accidentally disallows compilation caching when the argument is a
`ti.Matrix`, which causes taichi-dev#6950. This PR puts that behavior back.
  • Loading branch information
strongoier authored and quadpixels committed May 13, 2023
1 parent 9ea9962 commit e18affc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions python/taichi/lang/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,12 +1284,13 @@ def fill(self, val):
else:
assert self.ndim == 1
val = tuple(val for _ in range(self.n))
elif isinstance(val, Matrix) or (isinstance(val, expr.Expr)
and val.is_tensor()):
elif isinstance(val, expr.Expr) and val.is_tensor():
assert val.n == self.n
if self.ndim != 1:
assert val.m == self.m
else:
if isinstance(val, Matrix):
val = val.to_list()
assert isinstance(val, (list, tuple))
val = tuple(tuple(x) if isinstance(x, list) else x for x in val)
assert len(val) == self.n
Expand Down
10 changes: 10 additions & 0 deletions tests/python/test_fill.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from taichi.lang import impl

import taichi as ti
from tests import test_utils

Expand Down Expand Up @@ -65,3 +67,11 @@ def fill_in_kernel(v: ti.types.matrix(2, 3, ti.i32)):
for i in range(n):
for j in range(m):
assert (val[i, j] == mat).all()


@test_utils.test()
def test_fill_vector_field_recompile():
a = ti.Vector.field(2, ti.i32, shape=3)
for i in range(2):
a.fill(ti.Vector([0, 0]))
assert impl.get_runtime().get_num_compiled_functions() == 1

0 comments on commit e18affc

Please sign in to comment.