-
In c++ I defined:
I tried to bind with pybind11 in this way:
When I try to use it on python:
it gives me this error:
Any idea on how to solve it? |
Beta Was this translation helpful? Give feedback.
Answered by
jiwaszki
Jul 17, 2024
Replies: 1 comment 1 reply
-
Hi @xliuk , one way to make it work is to make types opaque. The thing is that you are using typedef of std::tuple, which during compilation substitutes both typedef std::tuple<int, int, int> Type;
typedef std::tuple<int, int, int, int> Shape;
PYBIND11_MAKE_OPAQUE(Type);
PYBIND11_MAKE_OPAQUE(Shape); In [1]: import mymodule
...:
...: type = mymodule.Type(0,8,1)
...: shape = mymodule.Shape(10,10,10,10)
...: prop = mymodule.Properties(type, shape)
...:
...: print(prop.type, prop.shape)
(0, 8, 1) (10, 10, 10, 10) Here is more info on it: https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html#making-opaque-types |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
xliuk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @xliuk , one way to make it work is to make types opaque. The thing is that you are using typedef of std::tuple, which during compilation substitutes both
Type
andShape
to tuple -- thus you can seeTuple[...]
in signature of the init.What you need to add on top of your bindings:
Here is more info on it: https://p…