I have some code I am trying to convert to C++. What I am trying to understand is to convert this bit of code:
import torch
# first slice
X = torch.randn(32, 4468)
cond_mask = X <= 0
keep_val = torch.randn(32, 4468)
Y = torch.randn(32,4468)
Y[cond_mask] = keep_val[cond_mask]
# second slice
Z = torch.randn(32, 4468)
batch = 32
idx_l = torch.arange(0, 32, dtype=torch.long)
label = torch.tensor([3962, 3962, 1768, 1768, 3532, 3532, 245, 245, 201, 201, 900, 900,
4176, 4176, 1539, 1539, 1932, 1932, 4017, 4017, 1807, 1807, 4211, 4211,
4439, 4439, 701, 701, 554, 554, 1829, 1829])
Z[idx_l, label] = Y[idx_l, label]
I did not know what to do with the first slice, but I tried with the second.
I tried this on the second slice in c++, but this did not succeed.
auto tensoroptions = torch::TensorOptions().dtype(torch::kInt32);
auto idx_l = torch::arange(0, 32).to(tensoroptions);
Z.index_put({idx_l, label}, Y.slice(idx_l, label));
The reason i tried to change the datatype was to avoid thist error, but I still got the same error.
error: no viable conversion from ‘at::Tensor’ to
‘int64_t’ (aka ‘long long’)
output.index_put({idx_, label}, cos_theta_m.slice(idx_, label));
Hopefully someone can explain to me the way to go with slicing with assignment in C++.
Thank you in advance.