Skip to content

Commit

Permalink
Merge pull request #8500 from EricCousineau-TRI/issue/8491
Browse files Browse the repository at this point in the history
 pydrake symbolic: Disable Formula.__nonzero__
  • Loading branch information
soonho-tri authored Apr 11, 2018
2 parents d7a41e0 + a4845dd commit 0af536b
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 65 deletions.
3 changes: 3 additions & 0 deletions bindings/pydrake/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ drake_pybind_library(
py_deps = [
":common_py",
":math_py",
"//bindings/pydrake/util:deprecation_py",
],
py_srcs = [
"autodiffutils.py",
Expand Down Expand Up @@ -132,6 +133,7 @@ drake_pybind_library(
py_deps = [
":common_py",
":math_py",
"//bindings/pydrake/util:deprecation_py",
],
py_srcs = ["symbolic.py"],
)
Expand Down Expand Up @@ -280,6 +282,7 @@ drake_py_unittest(
deps = [
":algebra_test_util_py",
":symbolic_py",
"//bindings/pydrake/util:containers_py",
],
)

Expand Down
6 changes: 6 additions & 0 deletions bindings/pydrake/autodiffutils_py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ namespace pydrake {
PYBIND11_MODULE(_autodiffutils_py, m) {
m.doc() = "Bindings for Eigen AutoDiff Scalars";

// Install NumPy warning filtres.
// N.B. This may interfere with other code, but until that is a confirmed
// issue, we should agressively try to avoid these warnings.
py::module::import("pydrake.util.deprecation")
.attr("install_numpy_warning_filters")();

py::class_<AutoDiffXd> autodiff(m, "AutoDiffXd");
autodiff
.def(py::init<const double&, const Eigen::VectorXd&>())
Expand Down
15 changes: 14 additions & 1 deletion bindings/pydrake/symbolic_py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ PYBIND11_MODULE(_symbolic_py, m) {
// NOLINTNEXTLINE(build/namespaces): Emulate placement in namespace.
using namespace drake::symbolic;

// Install NumPy warning filtres.
// N.B. This may interfere with other code, but until that is a confirmed
// issue, we should agressively try to avoid these warnings.
py::module::import("pydrake.util.deprecation")
.attr("install_numpy_warning_filters")();

m.doc() =
"Symbolic variable, variables, monomial, expression, polynomial, and "
"formula";
Expand Down Expand Up @@ -343,7 +349,14 @@ PYBIND11_MODULE(_symbolic_py, m) {
.def("__hash__",
[](const Formula& self) { return std::hash<Formula>{}(self); })
.def_static("True", &Formula::True)
.def_static("False", &Formula::False);
.def_static("False", &Formula::False)
.def("__nonzero__", [](const Formula&) {
throw std::runtime_error(
"You should not call `__nonzero__` on `Formula`. If you are trying "
"to make a map with `Variable`, `Expression`, or `Polynomial` as "
"keys and access the keys, please use "
"`pydrake.util.containers.EqualToDict`.");
});

// Cannot overload logical operators: http://stackoverflow.com/a/471561
// Defining custom function for clarity.
Expand Down
Loading

0 comments on commit 0af536b

Please sign in to comment.