diff options
author | Andreas Sandberg <andreas.sandberg@arm.com> | 2017-05-09 19:22:53 +0100 |
---|---|---|
committer | Andreas Sandberg <andreas.sandberg@arm.com> | 2017-05-22 17:15:09 +0000 |
commit | 6914a229a038206341ae1fea46393965a555ca9a (patch) | |
tree | 4a11cfaed46dabc827c5ee17cd976f42b5f53d49 /ext/pybind11/tests/test_stl_binders.cpp | |
parent | ca1d18d599dcc620bf526fb22042af95b1b60b68 (diff) | |
download | gem5-6914a229a038206341ae1fea46393965a555ca9a.tar.xz |
ext: Upgrade PyBind11 to version 2.1.1
Change-Id: I16870dec402d661295f9d013dc23e362b2b2c169
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Curtis Dunham <curtis.dunham@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/3225
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'ext/pybind11/tests/test_stl_binders.cpp')
-rw-r--r-- | ext/pybind11/tests/test_stl_binders.cpp | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/ext/pybind11/tests/test_stl_binders.cpp b/ext/pybind11/tests/test_stl_binders.cpp index b9b56c15d..f636c0b55 100644 --- a/ext/pybind11/tests/test_stl_binders.cpp +++ b/ext/pybind11/tests/test_stl_binders.cpp @@ -10,10 +10,16 @@ #include "pybind11_tests.h" #include <pybind11/stl_bind.h> +#include <pybind11/numpy.h> #include <map> #include <deque> #include <unordered_map> +#ifdef _MSC_VER +// We get some really long type names here which causes MSVC to emit warnings +# pragma warning(disable: 4503) // warning C4503: decorated name length exceeded, name was truncated +#endif + class El { public: El() = delete; @@ -53,17 +59,45 @@ template <class Map> Map *times_ten(int n) { return m; } +struct VStruct { + bool w; + uint32_t x; + double y; + bool z; +}; + +struct VUndeclStruct { //dtype not declared for this version + bool w; + uint32_t x; + double y; + bool z; +}; + test_initializer stl_binder_vector([](py::module &m) { py::class_<El>(m, "El") .def(py::init<int>()); - py::bind_vector<std::vector<unsigned int>>(m, "VectorInt"); + py::bind_vector<std::vector<unsigned char>>(m, "VectorUChar", py::buffer_protocol()); + py::bind_vector<std::vector<unsigned int>>(m, "VectorInt", py::buffer_protocol()); py::bind_vector<std::vector<bool>>(m, "VectorBool"); py::bind_vector<std::vector<El>>(m, "VectorEl"); py::bind_vector<std::vector<std::vector<El>>>(m, "VectorVectorEl"); + m.def("create_undeclstruct", [m] () mutable { + py::bind_vector<std::vector<VUndeclStruct>>(m, "VectorUndeclStruct", py::buffer_protocol()); + }); + + try { + py::module::import("numpy"); + } catch (...) { + return; + } + PYBIND11_NUMPY_DTYPE(VStruct, w, x, y, z); + py::class_<VStruct>(m, "VStruct").def_readwrite("x", &VStruct::x); + py::bind_vector<std::vector<VStruct>>(m, "VectorStruct", py::buffer_protocol()); + m.def("get_vectorstruct", [] {return std::vector<VStruct> {{0, 5, 3.0, 1}, {1, 30, -1e4, 0}};}); }); test_initializer stl_binder_map([](py::module &m) { @@ -92,4 +126,3 @@ test_initializer stl_binder_noncopyable([](py::module &m) { py::bind_map<std::unordered_map<int, E_nc>>(m, "UmapENC"); m.def("get_umnc", ×_ten<std::unordered_map<int, E_nc>>, py::return_value_policy::reference); }); - |