Skip to content

Commit

Permalink
[bug] Allow StructType as type hint to ti.func (#6964)
Browse files Browse the repository at this point in the history
Issue: fix #6855

### Brief Summary

Note that this PR is a quick hack to allow the type hint but doesn't
check invalid cases. We would like to wait for the upcoming new struct
type representation to officially support struct type as kernel/func
parameters.
  • Loading branch information
strongoier committed Dec 23, 2022
1 parent 5ac1e05 commit 6268cfb
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 6268cfb

Please sign in to comment.