一个奇怪的越组问题

import taichi as ti
ti.init(arch=ti.cpu,default_fp=ti.f32,default_ip=ti.i32)

@ti.kernel
def cycle():
    M=ti.Matrix.identity(float,8)
    for i0,j0 in ti.static(ti.ndrange(2, 2)):
        for i1,j1 in ti.static(ti.ndrange(2, 2)):
            for i2,j2 in ti.static(ti.ndrange(2, 2)):
                    if  i1==j1==1 and i0 != j0 : 
                        m,n=2*i0 + 6*j0 + i2, 4 + j2                    
                        print(m,n,'d1')
                        # M[2*i0 + 6*j0 + i2,4 + j2]=1
cycle()

print出来的m,n是没有>8的数的,但是当我用M这个矩阵时,报了这个错误,想问一下什么情况。
image

代码是这个样子的
image

看起来确实可能有 bug,可以考虑去 github 仓库上发一个 issue。
在判断条件上加一个 ti.static 也许可以部分解决你的问题:

import taichi as ti
ti.init(arch=ti.cpu,default_fp=ti.f32,default_ip=ti.i32)

@ti.kernel
def cycle():
    M=ti.Matrix.identity(float,8)
    for i0,j0 in ti.static(ti.ndrange(2, 2)):
        for i1,j1 in ti.static(ti.ndrange(2, 2)):
            for i2,j2 in ti.static(ti.ndrange(2, 2)):
                if  ti.static(i1==j1==1 and i0 != j0): 
                    m,n=2*i0 + 6*j0 + i2, 4 + j2                    
                    print(m,n,'d1')
                    M[2*i0 + 6*j0 + i2,4 + j2]=1
cycle()