在kernel中无法给data_oriented类中的变量赋值

我的代码如下:

@ti.data_oriented
class test:

    D:ti.f64

    def __init__(self):

        self.D = ti.math.nan

    @ti.func
    def f(self):
        self.D = 1


@ti.kernel
def q():

    t = test()
    print(t.D)
    t.f()
    print(t.D)

q()

代码运行结果如下:

        self.D = 1
        ^^^^^^^^^^
Variable 'self.D' cannot be assigned. Maybe it is not a Taichi object?

请问各位大佬,这里为什么不能给test类中的变量D赋值?

一般好像是只能给field类型和几个taichi自带类型(ti.vector, ti.ndarray之类)的赋值吧?
其他不是taichi类型的只能当常量用,没法赋值

1 个赞