mirror of
https://github.com/YosysHQ/nextpnr.git
synced 2026-02-16 04:43:16 +00:00
3rdparty: upgrade pybind11 to v2.12.1.
This commit is contained in:
28
3rdparty/pybind11/tests/test_numpy_array.cpp
vendored
28
3rdparty/pybind11/tests/test_numpy_array.cpp
vendored
@@ -521,4 +521,32 @@ TEST_SUBMODULE(numpy_array, sm) {
|
||||
sm.def("test_fmt_desc_double", [](const py::array_t<double> &) {});
|
||||
sm.def("test_fmt_desc_const_float", [](const py::array_t<const float> &) {});
|
||||
sm.def("test_fmt_desc_const_double", [](const py::array_t<const double> &) {});
|
||||
|
||||
sm.def("round_trip_float", [](double d) { return d; });
|
||||
|
||||
sm.def("pass_array_pyobject_ptr_return_sum_str_values",
|
||||
[](const py::array_t<PyObject *> &objs) {
|
||||
std::string sum_str_values;
|
||||
for (const auto &obj : objs) {
|
||||
sum_str_values += py::str(obj.attr("value"));
|
||||
}
|
||||
return sum_str_values;
|
||||
});
|
||||
|
||||
sm.def("pass_array_pyobject_ptr_return_as_list",
|
||||
[](const py::array_t<PyObject *> &objs) -> py::list { return objs; });
|
||||
|
||||
sm.def("return_array_pyobject_ptr_cpp_loop", [](const py::list &objs) {
|
||||
py::size_t arr_size = py::len(objs);
|
||||
py::array_t<PyObject *> arr_from_list(static_cast<py::ssize_t>(arr_size));
|
||||
PyObject **data = arr_from_list.mutable_data();
|
||||
for (py::size_t i = 0; i < arr_size; i++) {
|
||||
assert(data[i] == nullptr);
|
||||
data[i] = py::cast<PyObject *>(objs[i].attr("value"));
|
||||
}
|
||||
return arr_from_list;
|
||||
});
|
||||
|
||||
sm.def("return_array_pyobject_ptr_from_list",
|
||||
[](const py::list &objs) -> py::array_t<PyObject *> { return objs; });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user