I have a compact D-dimensional index tensor indices
of shape (D, N)
. I would like to use them in index_put
to update a container tensor container
. In python this is simply achieved by container.index_put(tuple(indices), values)
, however I have to use the following code to achieve that in c++:
const std::vector<std::optional<at::Tensor>> tuple(const at::Tensor& tensor) {
std::vector<std::optional<at::Tensor>> vt;
for(int i = 0; i < tensor.size(0); i++) {
vt.emplace_back(tensor[i]);
}
return vt;
}
... some stuff creating the container and values tensor.
const c10::List<std::optional<at::Tensor>> x(tuple(indices));
container.index_put(x, values);
I’m wondering if there exist some convenient methods to achieve this?