Hi,
I am trying to learn how to use the C++ API and for that I am porting basic examples from the “Deep Learning with PyTorch” book.
I am stuck with simple things like iterating through the values of a 1-D tensor to put them on a std::vector. I have not been successful in finding any documentation with such examples.
For example, let’s say that I have this:
auto X = torch::tensor({3.3,4.4,5.5,6.71,6.93,4.168,9.779,6.182,
7.59,2.167, 7.042,10.791,5.313,7.997,5.654,9.27,
3.1},
torch::requires_grad(false).dtype(torch::kFloat32))
.view({17,1});
How can I write a loop looking like:
std::vector<float> vec;
for(const auto& element : X) vec.push_back(element);
I guess I have to access the scalar data in X. I have tried storage()
or data()
, but it does not work.
Is there a place where I could look up some examples?
Thanks.