You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to create an extension library that creates subclasses of an existing class in an external library. I will use pytorch as a simplified example to demonstrate it.
Here I would like to inherit the torch Tensor class and create the MyTensor class. Later, I can pass MyTensor objects to external functions that takes a at::Tensor as an input.
#include<ATen/ATen.h>
#include<torch/extension.h>
#include<pybind11/pybind11.h>
#include<pybind11/stl.h>classMyTensor : publicat::Tensor {};
namespacepy= pybind11;
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
auto Base = py::module_::import("torch").attr("Tensor");
py::class_<MyTensor>(m, "MyTensor", Base);
}
This code crashes on import at this line with a nullptr passed to get_type_info. I am trying to follow the doc here, and PYBIND11_EXPORT does not seem to help.
Also a (possibly) related question, what is the preferred to way to use classes in an external library as parameters/return values in my extension library? pytorch appears to achieve this but I do not see exactly how it is done.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to create an extension library that creates subclasses of an existing class in an external library. I will use pytorch as a simplified example to demonstrate it.
Here I would like to inherit the torch Tensor class and create the MyTensor class. Later, I can pass MyTensor objects to external functions that takes a at::Tensor as an input.
This code crashes on import at this line with a nullptr passed to get_type_info. I am trying to follow the doc here, and PYBIND11_EXPORT does not seem to help.
Also a (possibly) related question, what is the preferred to way to use classes in an external library as parameters/return values in my extension library? pytorch appears to achieve this but I do not see exactly how it is done.
Beta Was this translation helpful? Give feedback.
All reactions