How to create torch::tensor constant in c++?

there is a question about how to create a torch::Tensor constant in cpp?

I have some data table, like this:

const int a [] = {123, 456, 789};

but now , I want to translate the type of a into torch::Tensor, such as

#include <torch/extension.h>

torch::Tensor a = {123, 456, 789};

in this link https://pytorch.org/cppdocs/api/classat_1_1_tensor.html?highlight=torch%20tensor

I’m not find a good way to use it.

please help me, thanks.

from_blob should work:

  float data[] = {1, 2, 3, 4, 5, 6};

  auto f = from_blob(data, {1, 2, 3});

Make sure the data is alive as long as you are using f or clone() the data.

It’s awesome, Thanks. :grinning: