dynamic_index = True

前辈们好,向请教关于ti.static在for loop中运用的问题。代码如下:

>   @ti.kernel
>     def streaming(self):
>         for I in ti.grouped(self.is_solid):
>                for s in ti.static(range(Q)):
>                     neighbor_pos = self.periodic_index(I + self.e[s])
>                     if (self.is_solid[neighbor_pos] == 0):
>                         self.f[neighbor_pos][s] = self.F[I][s]
>                     else:
>                         self.f[I][self.REVERSED_E[s]] = self.F[I][s]

其中self.REVERSED_E是一个constant scalar field. 运行时会报错:
The 0-th index of a Matrix/Vector must be a compile-time constant integer, got <class ‘taichi.lang.expr.Expr’>.\nThis is because matrix operations will be unrolled at compile-time for performance reason
除了设置dynamic_index=True之外还有什么办法么?这个class其他member function不需要dynamic_index =True, 会变慢。

非常感谢!!

请问你的 REVERSED_E 具体是什么样的 field 呢?里面的数值是编译期就已经知道的吗?

1 个赞

感谢大佬的回复! 如您所言我将reversed_e 改为 const后就成功了,抱歉一直没能回复您,