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

Struct types cannot be used with type hints as arguments to @ti.func #6855

Closed
AmesingFlank opened this issue Dec 9, 2022 · 0 comments · Fixed by #6964
Closed

Struct types cannot be used with type hints as arguments to @ti.func #6855

AmesingFlank opened this issue Dec 9, 2022 · 0 comments · Fixed by #6964
Assignees

Comments

@AmesingFlank
Copy link
Collaborator

AmesingFlank commented Dec 9, 2022

The following code works:

import taichi as ti
ti.init(ti.cpu)

@ti.dataclass
class C:
    i: int

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

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

k()

while this doesn't:

import taichi as ti
ti.init(ti.cpu)

@ti.dataclass
class C:
    i: int

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

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

k()

The only difference is the type hint: c: C
When the type hint is added, the following error is thrown:

  File "/Users/dunfanlu/Code/Taichi/taichi/python/taichi/lang/kernel_impl.py", line 341, in extract_arguments
    raise TaichiSyntaxError(
taichi.lang.exception.TaichiSyntaxError: Invalid type annotation (argument 0) of Taichi function: <taichi.lang.struct.StructType object at 0x10875e220>
@taichi-gardener taichi-gardener moved this to Untriaged in Taichi Lang Dec 9, 2022
@FantasyVR FantasyVR moved this from Untriaged to Todo in Taichi Lang Dec 16, 2022
Repository owner moved this from Todo to Done in Taichi Lang Dec 23, 2022
strongoier added a commit that referenced this issue Dec 23, 2022
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.
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
Issue: fix taichi-dev#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants