error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Dp> class std::unique_ptr’
error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Dp> class std::unique_ptr’
在我们开始之前,我是 C++11 的完全菜鸟,几年前使用过 C。
我正在尝试使用 pybind11 编写 C++11 代码的 python 绑定,但出现 subjected 错误。我基本上是在关注 Nvidia 人员的这个 guide 并且陷入了这个错误。
有好心人能给我指出正确的方向吗?
定义:
template<int zoom_factor>
class UpSamplePlugin: public nvinfer1::IPluginExt
{
public:
UpSamplePlugin() {}
// Create the plugin at runtime from a byte stream.
UpSamplePlugin(const void* buffer, size_t size)
{
assert(size == sizeof(mInputDims)); // assert datatype of input
mInputDims = *reinterpret_cast<const nvinfer1::Dims*>(buffer);
}
...
}
致电:
py::class_<UpSamplePlugin, nvinfer1::IPluginExt, std::unique_ptr<UpSamplePlugin, py::nodelete>>(m, "UpSamplePlugin")
// Bind the normal constructor as well as the one which deserializes the plugin
//.def(py::init<const nvinfer1::Weights*, int>())
.def(py::init<const void*, size_t>())
;
错误:
/media/.../plugin/pyUpSample.cpp: In function ‘void pybind11_init_upsampleplugin(pybind11::module&)’:
/media/.../plugin/pyUpSample.cpp:13:90: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Dp> class std::unique_ptr’
py::class_<UpSamplePlugin, nvinfer1::IPluginExt, std::unique_ptr<UpSamplePlugin, py::nodelete>>(m, "UpSamplePlugin")
^
/media/.../plugin/pyUpSample.cpp:13:90: note: expected a type, got ‘UpSamplePlugin’
没有名为 UpSamplePlugin
的类型,这只是一个模板。
所以你必须做类似 UpSamplePlugin<T>
的事情。在你的情况下应该是 UpSamplePlugin<zoom_factor>
尝试以下代码,如果此声明在模板内:
py::class_<UpSamplePlugin<zoom_factor>, nvinfer1::IPluginExt, std::unique_ptr<UpSamplePlugin, py::nodelete>>(m, "UpSamplePlugin")
// Bind the normal constructor as well as the one which deserializes the plugin
//.def(py::init<const nvinfer1::Weights*, int>())
.def(py::init<const void*, size_t>())
;
编译器将"create"一个对应于UpSamplePlugin<zoom_factor>
的新类型。
如果不在模板内:
创建另一个模板(它可以是模板函数),可以用 zoom_factor 调用为任何常量类型:
template<int zoom_factor>
void doSomething() {
py::class_<UpSamplePlugin<zoom_factor>, nvinfer1::IPluginExt, std::unique_ptr<UpSamplePlugin, py::nodelete>>(m, "UpSamplePlugin")
// Bind the normal constructor as well as the one which deserializes the plugin
//.def(py::init<const nvinfer1::Weights*, int>())
.def(py::init<const void*, size_t>())
;
}
然后你可以用任何已知的编译时间 zoom_factor
调用这个函数
在我们开始之前,我是 C++11 的完全菜鸟,几年前使用过 C。
我正在尝试使用 pybind11 编写 C++11 代码的 python 绑定,但出现 subjected 错误。我基本上是在关注 Nvidia 人员的这个 guide 并且陷入了这个错误。 有好心人能给我指出正确的方向吗?
定义:
template<int zoom_factor>
class UpSamplePlugin: public nvinfer1::IPluginExt
{
public:
UpSamplePlugin() {}
// Create the plugin at runtime from a byte stream.
UpSamplePlugin(const void* buffer, size_t size)
{
assert(size == sizeof(mInputDims)); // assert datatype of input
mInputDims = *reinterpret_cast<const nvinfer1::Dims*>(buffer);
}
...
}
致电:
py::class_<UpSamplePlugin, nvinfer1::IPluginExt, std::unique_ptr<UpSamplePlugin, py::nodelete>>(m, "UpSamplePlugin")
// Bind the normal constructor as well as the one which deserializes the plugin
//.def(py::init<const nvinfer1::Weights*, int>())
.def(py::init<const void*, size_t>())
;
错误:
/media/.../plugin/pyUpSample.cpp: In function ‘void pybind11_init_upsampleplugin(pybind11::module&)’:
/media/.../plugin/pyUpSample.cpp:13:90: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Dp> class std::unique_ptr’
py::class_<UpSamplePlugin, nvinfer1::IPluginExt, std::unique_ptr<UpSamplePlugin, py::nodelete>>(m, "UpSamplePlugin")
^
/media/.../plugin/pyUpSample.cpp:13:90: note: expected a type, got ‘UpSamplePlugin’
没有名为 UpSamplePlugin
的类型,这只是一个模板。
所以你必须做类似 UpSamplePlugin<T>
的事情。在你的情况下应该是 UpSamplePlugin<zoom_factor>
尝试以下代码,如果此声明在模板内:
py::class_<UpSamplePlugin<zoom_factor>, nvinfer1::IPluginExt, std::unique_ptr<UpSamplePlugin, py::nodelete>>(m, "UpSamplePlugin")
// Bind the normal constructor as well as the one which deserializes the plugin
//.def(py::init<const nvinfer1::Weights*, int>())
.def(py::init<const void*, size_t>())
;
编译器将"create"一个对应于UpSamplePlugin<zoom_factor>
的新类型。
如果不在模板内:
创建另一个模板(它可以是模板函数),可以用 zoom_factor 调用为任何常量类型:
template<int zoom_factor>
void doSomething() {
py::class_<UpSamplePlugin<zoom_factor>, nvinfer1::IPluginExt, std::unique_ptr<UpSamplePlugin, py::nodelete>>(m, "UpSamplePlugin")
// Bind the normal constructor as well as the one which deserializes the plugin
//.def(py::init<const nvinfer1::Weights*, int>())
.def(py::init<const void*, size_t>())
;
}
然后你可以用任何已知的编译时间 zoom_factor