Skip to content

Commit

Permalink
Merge pull request #34 from EricCousineau-TRI/pybary
Browse files Browse the repository at this point in the history
Fixes for pybary
  • Loading branch information
RussTedrake authored Feb 13, 2018
2 parents f075f88 + 709abd2 commit a85cd84
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bindings/pydrake/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -236,6 +236,11 @@ drake_py_test(
],
)

alias(
name = "math_test",
actual = "test/math_test",
)

drake_py_test(
name = "symbolic_variables_test",
size = "small",
Expand Down
1 change: 1 addition & 0 deletions bindings/pydrake/systems/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 24 additions & 1 deletion bindings/pydrake/systems/controllers_py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,34 @@
#include <pybind11/stl.h>

#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 <typename T, typename = void>
struct wrap_ptr : public wrap_arg_default<T> {};

template <typename T>
struct wrap_ptr<const systems::Context<T>&> {
using Type = systems::Context<T>;
static auto wrap(const Type& arg) { return &arg; }
static auto unwrap(const Type* arg_wrapped) { return *arg_wrapped; }
};

// Ensures that `const Context<T>&` is wrapped with `const Context<T>*`.
// TODO(eric.cousineau): Replace this with general wrappper, place in
// `pydrake_pybind` or somewhere related.
template <typename Func>
auto WrapPtr(Func&& func) {
return WrapFunction<wrap_ptr>(std::forward<Func>(func));
}

} // namespace

PYBIND11_MODULE(controllers, m) {
// NOLINTNEXTLINE(build/namespaces): Emulate placement in namespace.
using namespace drake::systems::controllers;
Expand All @@ -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
Expand Down

0 comments on commit a85cd84

Please sign in to comment.