我有一个接受 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/