Skip to content

Instantly share code, notes, and snippets.

@FantasyVR
Last active October 13, 2021 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FantasyVR/49336cf9385b6b3899435aa8a915ae32 to your computer and use it in GitHub Desktop.
Save FantasyVR/49336cf9385b6b3899435aa8a915ae32 to your computer and use it in GitHub Desktop.
import taichi as ti
ti.init(arch=ti.cpu, packed=True)
a = ti.field(dtype=ti.i32)
ti.root.dense(ti.ij, (2, 3)).dense(ti.ij, (2,3)).place(a)
@ti.kernel
def fill():
for i, j in a:
base = ti.get_addr(a.snode, [0, 0])
a[i, j] = int(ti.get_addr(a.snode, [i, j]) - base) // 4
fill()
print(a.to_numpy())
import taichi as ti
ti.init(arch=ti.cpu, packed=True)
a = ti.field(dtype=ti.i32)
b = ti.field(dtype=ti.i32)
ti.root.dense(ti.i, 2).dense(ti.j, 3).place(a) # row-major
ti.root.dense(ti.j, 3).dense(ti.i, 2).place(b) # column-major
@ti.kernel
def fill(f: ti.template()):
for i, j in f:
base = ti.get_addr(f.snode, [0,0])
f[i,j] = int(ti.get_addr(f.snode, [i,j]) - base) // 4
fill(a)
fill(b)
print(f"row-major: \n {a.to_numpy()}")
print(f"column-major: \n {b.to_numpy()}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment