4 ms·
I often use C++ and pybind11 to do this. pybind11 takes an approach very similar to boost::python (template magic). It works rather well. Though most of the C
by jononor 7y ago
I often use C++ and pybind11 to do this. pybind11 takes an approach very similar to boost::python (template magic). It works rather well.
Though most of the C code I write can compile as C++ also.
Why write in C then? It's still the lingua franca in microcontroller land... Just want to reuse the code on PC and Embedded Linux, and Python makes high-level testing much nicer.
- atilaneves 7y agoBoth pybind11 and boost::python involve writing code. This solution doesn't, save for listing the names of the files to be made available to Python (or C#, or Excel, or...).
- oefrha 7y agoNeither ctypes nor cffi involves writing glue code. In fact you don’t even need another source file, let alone a whole other language toolchain (wait, you actually need two other source files plus your third-party dpp library).
- bachmeier 7y agoI'm not sure I understand your comment. Someone said they use pybind11, someone responded to that by saying pybind11 requires writing code, and you responded by saying ctypes and cffi don't. How is that relevant to a discussion of pybind11?
- oefrha 7y agoOP presents their solution as an “easy” solution that doesn’t require glue code. Except there are already established native solutions that actually don’t require glue code.
- loeg 7y agoIn what sense does ctypes not require writing glue code?
- oefrha 7y agoSure, I’ll be more specific: there’s no glue code for function calls. Whatever function you want to call doesn’t need to be declared up front, you just call it at runtime, and it’s looked up dynamically. However, data structures like arrays and structs need to be declared, if needed.
- atilaneves 7y agoSo... ctypes requires writing glue code. The solution in the article doesn't. "if needed" means "needed with any and all C APIs one would be interested in".
- aldanor 7y agoPretty much this. Add to that pybind11's exceptional numpy compatibility (including easily mapping C types to structured numpy dtypes that can be e.g. converted to a dataframe), and there's not many choices left if you're not planning on reinventing a wheel or two. (disclaimer: pybind11 contributor)
- pletnes 7y agoIs pybind numpy aware? This is interesting. Having never used pybind, where can I learn more?
- Nimitz14 7y agoCheck the github and the docs. Funny reading this now, I literally just implemented something in 15min using C++/pybind11 (and operates on numpy arrays) that is an order of magnitude faster than when I used numpy operations.