C++ API for tensor construction

How do you construct a tensor from data in C++ API?

x = torch.Tensor([[1,2],[2,3],[3,4],[4,-1],[5,-5]])


std::vector<torch::jit::IValue> inputs;
auto input = torch::zeros({5,5});
input[0][0] = 1; // manually copy values one by one
input[0][1] = 2;

The problem is in the Python. The torch.Tensor constructor has been deprecated in PyTorch 0.4 or so. The new way is using torch.tensor instead, and that has an equivalent in C++. :slight_smile: