[libtorch] How to convert std::vector<torch::Tensor> to torch::TensorList?

How to convert std::vector<torch::Tensor> to torch::TensorList?

It works for me:

#include <torch/torch.h>
#include <iostream>


int main(){
    torch::Tensor x = torch::rand({2, 3, 2});
    std::cout << "Torch Tensor" << std::endl;
    std::cout << x << std::endl;
    std::vector<torch::Tensor> v;
    v.push_back(x);
    torch::TensorList z = torch::TensorList(v);
    std::cout << "Torch TensorList 1st element" << std::endl;
    std::cout << z[0] << std::endl;
    return 0;
}

And it should work always, since TensorList is an ArrayRef of tensors and ArrayRef implements a constructor from std::vector.

Thanks! After posting this post, I realized that I could cast std::vector<torch::Tensor> to torch::TensorList.