Last active
October 13, 2021 03:52
-
-
Save FantasyVR/49336cf9385b6b3899435aa8a915ae32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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