Open samuela opened 3 years ago
just confirmed on the latest at the time of writing:
[Taichi] version 0.6.40, llvm 10.0.0, commit 45f52a90, linux, python 3.6.9
Same thing using ti.Vector
instead of ti.Vector.field
. What's the difference between them btw?
import numpy as np
import taichi as ti
real = ti.f32
ti.init(default_fp=real)
x = ti.Vector(2, dt=real)
@ti.layout
def place():
ti.root.place(x)
if __name__ == "__main__":
x.from_numpy(np.zeros(2))
This also doesn't seem to work:
import numpy as np
import taichi as ti
real = ti.f32
ti.init(default_fp=real)
x = ti.Vector(2, dt=real)
@ti.layout
def place():
ti.root.dense(ti.i, 3).place(x)
if __name__ == "__main__":
x.from_numpy(np.zeros((3, 2), dtype=np.float32))
Ahhh, but this works:
import numpy as np
import taichi as ti
real = ti.f32
ti.init(default_fp=real)
x = ti.Vector.field(2, dtype=real)
@ti.layout
def place():
ti.root.place(x)
@ti.kernel
def noop():
pass
if __name__ == "__main__":
noop()
x.from_numpy(np.zeros((2, ), dtype=np.float32))
Hi, @ti.layout
is deprecated now.
We should directly invoke ti.root.place
without that decorator in latest version:
import numpy as np
import taichi as ti
real = ti.f32
ti.init(default_fp=real)
x = ti.Vector.field(2, dtype=real)
ti.root.place(x)
if __name__ == "__main__":
x.from_numpy(np.zeros(2))
Same thing using ti.Vector instead of ti.Vector.field. What's the difference between them btw?
The first is deprecated for #1500, you should get an warning when deprecated API like ti.Vector
and ti.layout
is used.
@archibate Ah, thanks for clarifying! I was working off of https://github.com/yuanming-hu/difftaichi/blob/master/examples/electric.py#L49-L61 but I guess that code is out of date now.
If I just want to place something on ti.root
, is it necessary to place it at all? Ie, the "Hello world" code (https://taichi.readthedocs.io/en/stable/hello.html) doesn't seem to do any places at all.
If I just want to place something on ti.root, is it necessary to place it at all? Ie, the "Hello world" code (https://taichi.readthedocs.io/en/stable/hello.html) doesn't seem to do any places at all.
Yes, for dense layouts, we can place them by shape=
argument:
x = ti.Vector.field(2, dtype=real, shape=()) # same as ti.root.place(x)
y = ti.Vector.field(2, dtype=real, shape=3) # same as ti.root.dense(ti.i, 3).place(y)
z = ti.Vector.field(2, dtype=real, shape=(3, 4)) # same as ti.root.dense(ti.i, (3, 4)).place(z)
Describe the bug
from_numpy
fails in simple case where a vector is placed onti.root
.To Reproduce
Log/Screenshots
Additional comments