ошибка: несоответствие типа / значения в аргументе 1 в списке параметров шаблона для шаблонакласс std :: unique_ptr ' - PullRequest
0 голосов
/ 06 октября 2018

Прежде чем мы начнем, я полный нуб в C ++ 11, несколько лет назад использовал C.

Я пытаюсь написать связывание Python кода C ++ 11 с использованием pybind11 иполучение подвергшейся ошибки.Я в основном следую этому руководству от людей Nvidia и застрял в этой ошибке.Может ли какая-нибудь милая душа направить меня в правильном направлении?

Определение :

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’

1 Ответ

0 голосов
/ 06 октября 2018

Нет типа с именем 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>())
;

Компилятор «создаст» новый тип, соответствующий 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>())
;    
}

Затем вы можете вызвать эту функцию с любым COMPILE TIME KNOWN zoom_factor

...