PyTorch tensors from C++ to Python

(Daniele Molinari) #1

Hi everybody,
I need to embed a Python interpreter in my C++ application and I want to pass Tensor s back and forth from C++ and Python.
I know that Boost.Python should fit this purpose, but I’m puzzled on how should I handle the Tensors exchange. My guess is that it should be relatively easy, considering that the C++ and Python frontend probably use the same underlying types. Can somebody point me in the right direction?

(Will Feng) #2

THPVariable_Wrap(Variable var) in is how we wrap a Variable (can be cast from torch::Tensor) into a Python object. Using Boost.Python there might be a way to pass the Variable C++ object to Python and construct the Python object.

(Daniele Molinari) #3

Thank you! I will look at it!