taichi-dev / taichi

Productive, portable, and performant GPU programming in Python.
https://taichi-lang.org
Apache License 2.0
25.35k stars 2.27k forks source link

Invalid type annotation exception #6144

Open giucesar opened 1 year ago

giucesar commented 1 year ago

Describe the bug I am getting invalid type annotation no matter how I write my kernel.

To Reproduce I got the example in the FAQ section (https://docs.taichi-lang.org/docs/faq), and it gives me:

taichi.lang.exception.TaichiSyntaxError: Invalid type annotation (argument 0) of Taichi kernel: ti.types.ndarray()

I even changed from python 3.10 to 3.9 and the exactly same exception persists.

import taichi as ti
import numpy as np
ti.init(arch=ti.cpu)
x = ti.field(ti.i32, shape=3)
array = np.array([10, 20, 30])
@ti.kernel
def test(arr: ti.types.ndarray()):
    for i in range(3):
        x[i] = arr[i]
test(array)
giucesar commented 1 year ago

Lucky! While testing again, I by mistake, removed the first line of the code:

from __future__ import annotations

it now works! looks like there is a conflict in how taichi interprets type hints with annotations enabled.