title: How to populate torch::tensor with c++ array?
body: <p>This is very basic: I am normally using Eigen3 for my math operations, but need to use libtorch for a network forward pass. Now I want to populate the <code>torch::tensor</code> with the data from my Eigen3 (or pure C++ <code>array</code>), but without a <code>for</code> loop. How can I do this?</p>
  <p>Here is the solution with a loop:</p>
  <pre><code>Eigen::Matrix&lt;double, N, 1&gt; inputEigen;  // previously initialized
  
  torch::Tensor inputTorch = torch::ones({1, N});  // my torch tensor for the forward pass
  for (int i = 0; i &lt; N; i++) {
    inputTorch[0][i] = inputEigen[i];  // batch size == 1
  }
  
  std::vector&lt;torch::jit::IValue&gt; inputs;
  inputs.push_back(inputTorch);
  at::Tensor output = net.forward(inputs).toTensor();
  </code></pre>
  <p>This works fine for now, but <code>N</code> might become really large and I'm just looking for a way to directly set the underlying data of my <code>torch::tensor</code> with a previously used C++ <code>array</code></p>