From 7f15c8a3bbb88565befb8c38a474760f7419bb8a Mon Sep 17 00:00:00 2001 From: Eric Cousineau Date: Mon, 12 Feb 2018 23:58:56 -0500 Subject: [PATCH 1/2] math_test: Ensure it's not run in the same directory. --- bindings/pydrake/BUILD.bazel | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bindings/pydrake/BUILD.bazel b/bindings/pydrake/BUILD.bazel index c1c873bde91d..28caf4094098 100644 --- a/bindings/pydrake/BUILD.bazel +++ b/bindings/pydrake/BUILD.bazel @@ -227,7 +227,7 @@ drake_py_test( ) drake_py_test( - name = "math_test", + name = "test/math_test", size = "small", srcs = ["test/math_test.py"], main = "test/math_test.py", @@ -236,6 +236,11 @@ drake_py_test( ], ) +alias( + name = "math_test", + actual = "test/math_test", +) + drake_py_test( name = "symbolic_variables_test", size = "small", From 709abd21b932c6cda808c23b89594d8e0d7357be Mon Sep 17 00:00:00 2001 From: Eric Cousineau Date: Mon, 12 Feb 2018 23:58:01 -0500 Subject: [PATCH 2/2] controllers: Use WrapPtr to ensure Context is not copied by pybind. --- bindings/pydrake/systems/BUILD.bazel | 1 + bindings/pydrake/systems/controllers_py.cc | 25 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bindings/pydrake/systems/BUILD.bazel b/bindings/pydrake/systems/BUILD.bazel index 194ff56cdfa1..c8983987ae23 100644 --- a/bindings/pydrake/systems/BUILD.bazel +++ b/bindings/pydrake/systems/BUILD.bazel @@ -92,6 +92,7 @@ drake_pybind_library( drake_pybind_library( name = "controllers_py", cc_deps = [ + "//bindings/pydrake/util:wrap_function", "//systems/controllers:dynamic_programming", ], cc_so_name = "controllers", diff --git a/bindings/pydrake/systems/controllers_py.cc b/bindings/pydrake/systems/controllers_py.cc index d5c48e2bcca9..fbceecbb5e43 100644 --- a/bindings/pydrake/systems/controllers_py.cc +++ b/bindings/pydrake/systems/controllers_py.cc @@ -4,11 +4,34 @@ #include #include "drake/bindings/pydrake/pydrake_pybind.h" +#include "drake/bindings/pydrake/util/wrap_function.h" #include "drake/systems/controllers/dynamic_programming.h" namespace drake { namespace pydrake { +namespace { + +template +struct wrap_ptr : public wrap_arg_default {}; + +template +struct wrap_ptr&> { + using Type = systems::Context; + static auto wrap(const Type& arg) { return &arg; } + static auto unwrap(const Type* arg_wrapped) { return *arg_wrapped; } +}; + +// Ensures that `const Context&` is wrapped with `const Context*`. +// TODO(eric.cousineau): Replace this with general wrappper, place in +// `pydrake_pybind` or somewhere related. +template +auto WrapPtr(Func&& func) { + return WrapFunction(std::forward(func)); +} + +} // namespace + PYBIND11_MODULE(controllers, m) { // NOLINTNEXTLINE(build/namespaces): Emulate placement in namespace. using namespace drake::systems::controllers; @@ -21,7 +44,7 @@ PYBIND11_MODULE(controllers, m) { .def_readwrite("discount_factor", &DynamicProgrammingOptions::discount_factor); - m.def("FittedValueIteration", &FittedValueIteration); + m.def("FittedValueIteration", WrapPtr(&FittedValueIteration)); } } // namespace pydrake