Using from_blob to create a tensor

I am getting the following error using from_blob. I just want to initiate a tensor with fixed values on GPU. How can I do it?

float _x[4] = {0.5,-1.2,3.4,2.2};
torch::Tensor x = torch::from_blob(_x, {4}).clone().to(torch::kCUDA);

But I end up receiving the following error

IndexError: select(): index 4 out of range for tensor of size [4] at dimension 0

I have also tried using this method to create a tensor on the GPU.

auto options = torch::TensorOptions().device(torch::kCUDA,0);```

I cannot reproduce the issue and your code runs fine:

#include <torch/script.h> // One-stop header.

#include <iostream>
#include <memory>

int main(int argc, const char* argv[]) {
  float _x[4] = {0.5,-1.2,3.4,2.2};
  torch::Tensor x = torch::from_blob(_x, {4}).clone().to(torch::kCUDA);

  std::cout << x << std::endl;
  return 0;
}

Output:

 0.5000
-1.2000
 3.4000
 2.2000
[ CUDAFloatType{4} ]