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'm having strange issues with trying to call this function from python. Argument a's size often seems to have weird values (often 16 or 2^64-1).
size_t myfunc(const std::optional<std::reference_wrapper<const std::vector<uint8_t>>>& a = std::nullopt,
const std::optional<std::vector<float>>& b = std::nullopt)
It seems to be the introduction of the 2nd argument that triggers the observation of the issue, but my intuition is it is a memory issue so it may only be exposed by the second argument.
Here is a small reproduceable snippet, also with examples of similar calls that work OK:
#include<cstdint>
#include<functional>
#include<optional>
#include<vector>
#include<memory>
#include<pybind11/pybind11.h>
#include<pybind11/stl.h>
#include<pybind11/numpy.h>classPybindTest
{
public:/* Problem case */size_toptrefwrap_uint8(const std::optional<std::reference_wrapper<const std::vector<uint8_t>>>& a = std::nullopt,
const std::optional<std::vector<float>>& b = std::nullopt)
{
if (a.has_value()) { return a->get().size(); }
else { return999; }
}
/* Similar, but OK cases */size_toptrefwrap_novec_uint8(const std::optional<std::reference_wrapper<uint8_t>>& a = std::nullopt,
const std::optional<std::vector<float>>& b = std::nullopt)
{
if (a.has_value()) { return a->get(); }
else { return999; }
}
size_topt_uint8(const std::optional<const std::vector<uint8_t>>& a = std::nullopt,
const std::optional<std::vector<float>>& b = std::nullopt)
{
if (a.has_value()) { return a->size(); }
else { return999; }
}
size_trefwrap_2ndopt_uint8(const std::reference_wrapper<const std::vector<uint8_t>>& a, const std::optional<std::vector<float>>& b = std::nullopt)
{
return a.get().size();
}
size_toptrefwrap_no2ndopt_uint8(const std::optional<std::reference_wrapper<const std::vector<uint8_t>>>& a = std::nullopt,
const std::vector<float>& b = {})
{
if (a.has_value()) { return a->get().size(); }
else { return999; }
}
size_toptrefwrap_int32(const std::optional<std::reference_wrapper<const std::vector<int32_t>>>& a = std::nullopt,
const std::optional<std::vector<float>>& b = std::nullopt)
{
if (a.has_value()) { return a->get().size(); }
else { return999; }
}
};
namespacepy= pybind11;
PYBIND11_MODULE(PybindTest, m)
{
py::class_<PybindTest, std::shared_ptr<PybindTest>>(m, "PybindTest")
.def(py::init<>())
.def("optrefwrap_uint8", &PybindTest::optrefwrap_uint8, py::arg("a") = py::none(), py::arg("b") = py::none())
.def("optrefwrap_no2ndopt_uint8", &PybindTest::optrefwrap_no2ndopt_uint8, py::arg("a") = py::none(), py::arg("b") = std::vector<float>())
.def("opt_uint8", &PybindTest::opt_uint8, py::arg("a") = py::none(), py::arg("b") = py::none())
.def("refwrap_2ndopt_uint8", &PybindTest::refwrap_2ndopt_uint8, py::arg("a"), py::arg("b"))
.def("optrefwrap_int32", &PybindTest::optrefwrap_int32, py::arg("a") = py::none(), py::arg("b") = py::none())
.def("optrefwrap_novec_uint8", &PybindTest::optrefwrap_novec_uint8, py::arg("a") = py::none(), py::arg("b") = py::none());
}
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
-
I'm having strange issues with trying to call this function from python. Argument a's size often seems to have weird values (often 16 or 2^64-1).
It seems to be the introduction of the 2nd argument that triggers the observation of the issue, but my intuition is it is a memory issue so it may only be exposed by the second argument.
Here is a small reproduceable snippet, also with examples of similar calls that work OK:
Python calls:
Code was built using the pybind cmake_example, ran on Ubuntu 22.04, Python 3.10.
I always hesitate to conclude that there is a bug in a well-used project like this, before I file a bug, am I doing anything obviously wrong here?
Beta Was this translation helpful? Give feedback.
All reactions