I have a vector of tuples that I need to convert into a torch::Tensor
. What I have come up with so far, is the vanilla approach which is as follows :
std::vector<torch::Tensor> anchors;
std::vector<std::tuple<float, float, float, float>> anchors_raw;
//...
for (auto& rows: anchors_raw)
{
auto& [cx, cy, s_kx, s_ky] = rows;
anchors.emplace_back(std::move(torch::stack({ std::move(torch::tensor(cx)),
std::move(torch::tensor(cy)),
std::move(torch::tensor(s_kx)),
std::move(torch::tensor(s_ky))
}, 0)));
}
outo output = std::move(torch::stack(std::move(anchor)).view({ -1,4 }));
//...
I'm using Torch 1.7. Is there any other possibly more efficient way of doing this?