Tensor to C++ vector

Is there a way to turn a 2d libtorch torch::Tensor into vector< vector > ?

This may not be sufficiently general, because it really relies on contiguous data storage: If you know the data type and sizes of the tensor, and the origin (available through data_ptr()), it’s straightforward to step through memory and build up row vectors, and then vectors of these as column vectors. (I might have it backward, but I’ve been able to get such a procedure to work for me.)

1 Like