2 years ago

#63131

test-img

Osama Yousuf

Conversion - pyBind11 - Passing a torch.Tensor() in Python into a C++ method expecting a std::vector

For a project I am working on, I require passing a PyTorch tensor (with dtype torch.int16) to a C++ method which expects an std::vector (basically, a list of integers).

I have the binding figured out, and I am already able to accomplish this task if I first convert my tensor into a numpy array (and use pybind11's numpy support), but for optimizing my code I want to be able to do this without this conversion to a numpy array.

Based on my research, I assume that I will have to write a custom type-caster. How should I proceed?

python

c++

pytorch

tensor

pybind11

0 Answers

Your Answer

Accepted video resources