Ti.append()函数不支持浮点数嘛

我定义了两个相同的ti.field,一个ti.i32,一个ti.f32。在使用ti.append()函数时,发现在不同的dtype下计算结果有问题。代码如下:

import taichi as ti
ti.init(arch=ti.cpu,cpu_max_num_threads = 1)

@ti.data_oriented
class Test:
    def __init__(self):
        self.x   = ti.field(dtype=ti.i32)       
        self.lsx = ti.root.pointer(ti.j,2).dynamic(ti.i,5)    
        self.lsx.place(self.x)
        
        self.y   = ti.field(dtype=ti.f32)       
        self.lsy = ti.root.pointer(ti.j,2).dynamic(ti.i,5)    
        self.lsy.place(self.y)        

    @ti.kernel         
    def add(self):
        for i in range(4):           
            ti.append(self.lsx,0,10)
            ti.append(self.lsx,1,11)    
            
            ti.append(self.lsy,0,10)
            ti.append(self.lsy,1,11)               
            
    def check(self):
        print('ti.i32-origin',self.x)
        print('ti.f32-origin',self.y)
        self.add()
        print('ti.i32-append',self.x) 
        print('ti.f32-append',self.y)
    
if __name__ == '__main__':
    Test().check()

输出结果如下:

[Taichi] Starting on arch=x64
ti.i32-origin [[0 0]
 [0 0]
 [0 0]
 [0 0]
 [0 0]]
ti.f32-origin [[0. 0.]
 [0. 0.]
 [0. 0.]
 [0. 0.]
 [0. 0.]]
ti.i32-append [[10 11]
 [10 11]
 [10 11]
 [10 11]
 [ 0  0]]
ti.f32-append [[1.4e-44 1.5e-44]
 [1.4e-44 1.5e-44]
 [1.4e-44 1.5e-44]
 [1.4e-44 1.5e-44]
 [0.0e+00 0.0e+00]]

可以看出,在dtye=i32时,没问题。但是在dtye=f32时,出错了,可能是内存寻址出错,
所以程序没有报错,开始我就没发现,后来通过计算结果发现不对。我就怀疑ti.append()函数可能不支持浮点数。
我将ti.append(self.lsy,0,10) 改为ti.append(self.lsy,0,10.0),果然报错,如下:
parameter 2 mismatch: required=i32, provided=float
我就比较好奇,为什么添加数据,只能添加整型不能添加小数呢,是不是有什么修饰符可以添加浮点数呢?好奇怪。

大半夜的好不容易码了个帖子,论坛也报错了,把我全文卡没了,我又辛辛苦苦码了第二遍,(͡° ͜ʖ ͡°)。

一直在转动Saving,然后一直没成功,就没了,这是一个悲伤的故事。(¬‿¬)

谢谢反馈,我去看一下源代码

PS:我也遇到过论坛卡没的情况 :ghost:

ti.append确实目前不支持float类型的数据,源代码:here

我提一个Issue吧,非常感谢你,能一直发现问题 :grinning:

:grinning:刚好用到,希望Taichi越来越完善 :sunglasses: :