python - 将简单的 C++ 函数与 Python 接口(interface)的最快方法

标签 python c++ interface wrapper

我有一个接受 std::vector<std::vector<double> > X 的 C++ 函数并对 X 做一些操作并输出 std::vector<std::vector<double> > X_mod .

我希望能够快速创建一个接口(interface),这样我就可以将一个 Python numpy 数组传递给这个 C++ 函数,然后让 C++ 函数返回 X_mod进入 Python。

我简单地看了看 Boost,对于这个简单的目的来说它似乎太复杂了?

关于如何为此编写快速界面还有其他建议吗?

最佳答案

正如评论中所建议的,Pybind11 可用于为 python 编写 C++ 绑定(bind) Pybind Documentation , Pybind Github Repo , Example how to use it .

为什么每个人都建议使用 Pybind 而不是 Boost 的原因可以在他们的自述文件中找到:

The main issue with Boost.Python—and the reason for creating such a similar project—is Boost. Boost is an enormously large and complex suite of utility libraries that works with almost every C++ compiler in existence. This compatibility has its cost: arcane template tricks and workarounds are necessary to support the oldest and buggiest of compiler specimens. Now that C++11-compatible compilers are widely available, this heavy machinery has become an excessively large and unnecessary dependency.

关于python - 将简单的 C++ 函数与 Python 接口(interface)的最快方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53732298/

相关文章:

.net - 如何以编程方式(在运行时)向类添加接口(interface)

c# - 使用 C# 的 Interface<T> 接口(interface)

python - 钩子(Hook)将命令添加到 distutils 构建?

c++ - 将接口(interface)和实现与普通功能分离

c++ - Win32 Window Wrapper 错误(参数不正确)

c++ - 使用 NVAPI 从 NVidia GPU 获取温度

java - 如何在不定义新类的情况下在 Swift 中实现 Objective-C

python - 检查列表元素中的多个字符串

python - 在 Bokeh 图中添加可点击的圆圈

python - 带有 Python 错误的 OpenCV - binary_op 中的断言失败((mask.type()== CV_8UC1 || mask.type()== CV_8SC1))