Hello,
I’m trying to port over some Python code to (admittadly not C++) the Rust backend and I’ve got a problem where the indexing in the Python version results in a different tensor compared.
The python code is:
rand_ts = torch.arange(200).reshape(1, 2, 10, 10)
t2 = torch.Tensor([1, 2, 3]).to(int)
t3 = torch.Tensor([5, 6, 7]).to(int)
out = rand_ts[0, 1, t2, t3]
Results in a Tensor of shape [3]
. Which is what I’d like. However, in Rust:
let rand_t = Tensor::range(0, 199, (tch::Kind::Float, tch::Device::Cpu)).view([1, 2, 10, 10]);
let hindex = Tensor::of_slice(&[0, 1, 2]);
let windex = Tensor::of_slice(&[5, 6, 7]);
let subselected = rand_t.i((0, 1, &hindex, &windex));
This results in a Tensor of shape [3, 3]
.
Any thoughts on how I can get the Rust (or if you can provide an example, a C++) version to behave the way the Python version does?
Many thanks