Skip to content
Snippets Groups Projects
Commit 93f1835c authored by Dr. Felix Tobias Schindler's avatar Dr. Felix Tobias Schindler
Browse files

[vector] add first draft of pickling for vectors

parent b4ac2df5
No related branches found
No related tags found
No related merge requests found
......@@ -157,6 +157,19 @@ typename std::enable_if<is_vector<C>::value, pybind11::class_<C>>::type bind_Vec
c.def("sup_norm", &C::sup_norm);
c.def("standard_deviation", [](const C& self) { return self.standard_deviation(); });
c.def("__getstate__", [](const C& self) { return py::make_tuple(std::vector<S>(self)); });
c.def("__setstate__", [](C& self, py::tuple t) {
if (t.size() != 1)
throw std::runtime_error("Invalid state!");
auto data = t[0].cast<std::vector<S>>();
/* Invoke the in-place constructor. Note that this is needed even
when the object just has a trivial default constructor */
new (&self) C(data.size());
/* Assign any additional state */
for (size_t ii = 0; ii < self.size(); ++ii)
self[ii] = data[ii];
});
addbind_ContainerInterface(c);
return c;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment