From f9f910a33bb33fd94fd645743518a4711a7e0017 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Mon, 25 Sep 2017 16:41:18 -0700 Subject: [PATCH] Complete op --- paddle/pybind/protobuf.cc | 150 +++++++++++++++++- .../v2/framework/tests/test_protobuf_descs.py | 36 ++++- 2 files changed, 181 insertions(+), 5 deletions(-) diff --git a/paddle/pybind/protobuf.cc b/paddle/pybind/protobuf.cc index 7af93cca99a..673e0ab80b7 100644 --- a/paddle/pybind/protobuf.cc +++ b/paddle/pybind/protobuf.cc @@ -14,8 +14,72 @@ limitations under the License. */ #include "paddle/pybind/protobuf.h" #include +#include #include "paddle/framework/attribute.h" +// Cast boost::variant for PyBind. +// Copy from +// https://github.com/pybind/pybind11/issues/576#issuecomment-269563199 +namespace pybind11 { +namespace detail { + +// Can be replaced by a generic lambda in C++14 +struct variant_caster_visitor : public boost::static_visitor { + return_value_policy policy; + handle parent; + + variant_caster_visitor(return_value_policy policy, handle parent) + : policy(policy), parent(parent) {} + + template + handle operator()(T const &src) const { + return make_caster::cast(src, policy, parent); + } +}; + +template +struct variant_caster; + +template