user buffer_protocol() in pybind11 for a custom class #4980
AAUDI
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have a templated class and I have a method inside this class that return a pointer of the raw buffer.
I tried to use buffer_protocol to return a numpy array directly in python side from the raw buffer.
This way works well for standard types (float, int double, string, etc ..) but I need to used it for a custom type.
I used this code to bind what I say above :
It works well when I call my module like this :
But when I tried this :
export_Array1D<MyOwnClass>(m, "MyOwnClass");
I have this error :
error: ‘format’ is not a member of ‘pybind11::format_descriptor<MyOwnClass, void>’
Do we have any way that can resolve this problem? In other words, Can we use buffer_protocol and .def_buffer() to get the numpy array from a raw buffer of a custom type ?
Thank you
Beta Was this translation helpful? Give feedback.
All reactions