You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following code snippet that implements a function dtype with the same input arguments (none) but both as a templated and non-templated variant:
template<typenamereal_t>
classOptions
{
/// @brief Returns the `dtype` property
caffe2::TypeMeta dtype() constnoexcept
{
return options_.dtype();
}
/// @brief Returns a new Options object with the `dtype` property as giventemplate<typenameother_t>
Options<other_t> dtype() constnoexcept
{
return Options<other_t>(options_.dtype(caffe2::TypeMeta::Make<T>().toScalarType()));
}
};
In C++ I can distinguish both variants as Options.dtype() and Options.dtype<float>(), respectively.
When trying to wrap the class in PyBind11 as follows
error: address of overloaded function 'dtype' does not match required type 'caffe2::TypeMeta'
((caffe2::TypeMeta)&Options<double>::dtype, py::const_),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../include/options.hpp:94:22: note: candidate function
caffe2::TypeMeta dtype() const noexcept
^
xxx/include/options.hpp:137:22: note: candidate function template
Options<other_t> dtype() const noexcept
When leaving out (caffe2::TypeMeta) (i.e. no hint to the return type) the error is
error: no matching function for call to object of type 'const detail::overload_cast_impl<>'
py::overload_cast<>
^~~~~~~~~~~~~~~~~~~
/opt/homebrew/include/pybind11/detail/common.h:1081:20: note: candidate template ignored: couldn't infer template argument 'Return'
constexpr auto operator()(Return (Class::*pmf)(Args...), std::false_type = {}) const noexcept
^
/opt/homebrew/include/pybind11/detail/common.h:1087:20: note: candidate template ignored: couldn't infer template argument 'Return'
constexpr auto operator()(Return (Class::*pmf)(Args...) const, std::true_type) const noexcept
^
/opt/homebrew/include/pybind11/detail/common.h:1076:20: note: candidate function template not viable: requires single argument 'pf', but 2 arguments were provided
constexpr auto operator()(Return (*pf)(Args...)) const noexcept -> decltype(pf) {
^
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Dear all,
I have the following code snippet that implements a function
dtype
with the same input arguments (none) but both as a templated and non-templated variant:In C++ I can distinguish both variants as
Options.dtype()
andOptions.dtype<float>()
, respectively.When trying to wrap the class in PyBind11 as follows
I get the following compiler error:
When leaving out
(caffe2::TypeMeta)
(i.e. no hint to the return type) the error isAny help is appreciated,
Matthias
Beta Was this translation helpful? Give feedback.
All reactions