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

Multiple return type hint with @ti.func not working on 1.7 #8457

Open
kmarchais opened this issue Dec 28, 2023 · 3 comments
Open

Multiple return type hint with @ti.func not working on 1.7 #8457

kmarchais opened this issue Dec 28, 2023 · 3 comments

Comments

@kmarchais
Copy link

Hello

Describe the bug
Since updating taichi to 1.7, I can't use type hinting for return tuple using a @ti.func, it was working under 1.6. Same behaviour with @ti.pyfunc. It works with @ti.real_func though.
Is it the expected behaviour?

To Reproduce

import taichi as ti
import taichi.math as tm

ti.init(arch=ti.cpu, debug=True)


@ti.func
def foo() -> tuple[int, tm.vec3]:
    a = 1
    b = tm.vec3(1.0, 2.0, 3.0)
    return a, b


@ti.kernel
def kernel() -> tuple[int, tm.vec3]:
    return foo()


print(kernel())

Log/Screenshots

$ python .\test-new-dev.py
[Taichi] version 1.7.0, llvm 15.0.1, commit 2fd24490, win, python 3.11.7  
[Taichi] Starting on arch=x64
Traceback (most recent call last):
  File "C:\Users\kevin\dev\taichi\test-new-dev.py", line 19, in <module>  
    print(kernel())
          ^^^^^^^^
  File "C:\Users\kevin\miniforge3\envs\taichi\Lib\site-packages\taichi\lang\kernel_impl.py", line 1107, in wrapped
    raise type(e)("\n" + str(e)) from None
taichi.lang.exception.TaichiCompilationError:
File "C:\Users\kevin\dev\taichi\test-new-dev.py", line 16, in kernel:     
    return foo()
           ^^^^^
File "C:\Users\kevin\dev\taichi\test-new-dev.py", line 11, in foo:        
    return a, b
    ^^^^^^^^^^^
Traceback (most recent call last):
  File "C:\Users\kevin\miniforge3\envs\taichi\Lib\site-packages\taichi\lang\ast\ast_transformer_utils.py", line 27, in __call__
    return method(ctx, node)
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\kevin\miniforge3\envs\taichi\Lib\site-packages\taichi\lang\ast\ast_transformer.py", line 928, in build_Return
    ctx.return_data[i] = ti_ops.cast(ctx.return_data[i], return_type)     
    ~~~~~~~~~~~~~~~^^^
TypeError: 'tuple' object does not support item assignment
...
@bobcao3
Copy link
Collaborator

bobcao3 commented Dec 28, 2023

I don't think we supports the standard square bracket type hints...

@lin-hitonami
Copy link
Contributor

I don't think we supports the standard square bracket type hints...

We do support them in v1.7.0. Maybe we forgot to add support for the ti.func. However the type hint of ti.func isn't mandatory. You can remove the return type hint for now.

@kmarchais
Copy link
Author

Indeed, it works without type hinting. However, I would still prefer to use type hinting though.
Temporarily I switched my func to real_func.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Untriaged
Development

No branches or pull requests

3 participants