taichi
taichi copied to clipboard
Multiple return type hint with `@ti.func` not working on 1.7
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
...
I don't think we supports the standard square bracket type hints...
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.
Indeed, it works without type hinting. However, I would still prefer to use type hinting though.
Temporarily I switched my func
to real_func
.