Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for pybary #34

Merged
merged 2 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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