Using the C++ libtorch api for Pytorch
I want to create a torch::Tensor from a C++ double[] array, legacy C/C++ pointer. I could not find a simple documentation about the subject not in docs nor in the forums.
Something like:
double array[5] = {1, 2, 3, 4, 5}; // or double *array;
auto tharray = torch::Tensor(array, 5, torch::Device(torch::kCUDA));
The only thing I found is to use torch::from_blob but then I would have to clone() and use to(device) if I wanted to use it with CUDA.
double array[] = { 1, 2, 3, 4, 5};. // or double *array;
auto options = torch::TensorOptions().dtype(torch::kFloat64);
torch::Tensor tharray = torch::from_blob(array, {5}, options);
Is there any cleaner way of doing so?
TensorOptionsto set the device at the same time you create your tensor? Something likeauto options = torch::TensorOptions().dtype(torch::kFloat64).device(torch::kCUDA, 1)