Open obust opened 10 months ago
As you just mentioned, "torch-scalar" is a "zero-dimension" tensor, so basically you still need to treat it as a Ndarray in Taichi:
import torch
import taichi as ti
ti.init(arch=ti.cpu)
@ti.kernel
def fill(out: ti.types.ndarray(), value: ti.types.ndarray()):
for I in ti.grouped(out):
out[I] = value[None]
out = torch.empty((10,), dtype=torch.int32)
value = torch.tensor(2, dtype=torch.int32) # torch scalar
fill(out, value)
Try this out.
Torch scalars are 0-dimensional tensors.
Currently taichi cannot convert a zero dimensional tensor (e.g.
torch.tensor(2, dtype=torch.int32)
) to taichi scalar (e.g.ti.int32
).Example
Suppose you have this
fill
kernel:We can pass a python scalar
We can also pass a
numpy
scalarbut we cannot pass a
torch
scalar