I am developing a Python library in C++ using pybind11. This library is meant to be used with deep learning packages like TensorFlow, so some of the functions it exposes take TensorFlow objects as argument, and in particular tf.Tensor
instances. At C++ level, these functions are defined with the following prototype:
void f(const py11::object& theTensor) {
...
}
I'm looking for a way to get the C++ tensorflow::Tensor
wrapped by the py11::object
that is being passed.
My understanding of TensorFlow is that it uses SWIG to create the Python wrapper to the C++ interface. However, I couldn't find where the tf.Tensor
wrapper is defined, and I'm not familiar with the way SWIG exposes C++ classes as Python classes.
I should be able to retrieve a PyObject*
pointer from the py11::object
using theTensor.ptr()
, but then I don't know how to convert this into a pointer to a C++ Tensor object.