我试图让pybind11接受一个3D无符号整数numpy数组,可以是u8、u16、u32或u64。但是,在编译之后,我得到了一个RuntimeError。我试图启用详细的错误消息,但是没有成功。有人看到我的错误了吗?
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#define PYBIND11_DETAILED_ERROR_MESSAGES
#include <vector>
#include "crackle.hpp"
#include "cc3d.hpp"
namespace py = pybind11;
py::tuple connected_components(const py::array &labels) {
return py::make_tuple(...);
}
PYBIND11_MODULE(example, m) {
m.doc() = "comments.";
m.def(
"connected_components",
&connected_components,
"Perform 4-connected components in layers on a 3D array."
);
}
在运行时:
results = example.connected_components(labels)
运行时错误:无法将调用参数转换为Python对象(#define PYBIND11_DETAILED_ERROR_MESSAGES或在调试模式下编译以获取详细信息)
这是我的setup.py:
import setuptools
from pybind11.setup_helpers import Pybind11Extension, build_ext
ext_modules = [
Pybind11Extension(
"example",
["src/example.cpp"],
extra_compile_args=["-std=c++17"],
),
]
setuptools.setup(
setup_requires=['pbr'],
cmdclass={"build_ext": build_ext},
ext_modules=ext_modules,
pbr=True
)
1条答案
按热度按时间ie3xauqp1#
我还需要写:
没有它,Pybind11无法将向量转换为列表。