How to transfer data between Aramdillo matrix and LibTorch tensor?

27 views Asked by At

I am trying to transfer data between Aramdillo matrix and LibTorch tensor.

I referenced this project, but the conversion failed in my Linux environment.

Then I tried to convert using the from_blob interface provided by libtorch and it still failed.

Here is my code.

arma::mat matrix{{1, 2, 3}, {7, 8, 9}};
cout << "armadillo matrix: \n";
cout << matrix << endl;
auto t = torch::from_blob(matrix.memptr(), {2, 3});
cout << "libtorch tensor: \n";
cout << t << endl

Here is the output.

armadillo matrix:
   1.0000   2.0000   3.0000
   7.0000   8.0000   9.0000

libtorch tensor:
 0.0000  1.8750  0.0000
 2.4375  0.0000  2.0000
[ CPUFloatType{2,3} ]

Transfer data between Aramdillo matrix and LibTorch tensor.

0

There are 0 answers