Skip to content

Commit

Permalink
[bug] Allow StructType as type hint to ti.func
Browse files Browse the repository at this point in the history
  • Loading branch information
strongoier committed Dec 22, 2022
1 parent be15358 commit 8538a61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/taichi/lang/kernel_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ def extract_arguments(self):
pass
elif isinstance(annotation, MatrixType):
pass
elif isinstance(annotation, StructType):
pass
elif id(annotation) in primitive_types.type_ids:
pass
elif isinstance(annotation, template):
Expand Down
18 changes: 18 additions & 0 deletions tests/python/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,24 @@ def test_error():
test_error()


@test_utils.test(debug=True)
def test_func_struct_arg():
@ti.dataclass
class C:
i: int

@ti.func
def f(c: C):
return c.i

@ti.kernel
def k():
c = C(i=2)
assert f(c) == 2

k()


@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_real_func_matrix_arg():
@ti.experimental.real_func
Expand Down

0 comments on commit 8538a61

Please sign in to comment.