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

eigen: Disable dtype=object arrays from being referenced #17

Conversation

EricCousineau-TRI
Copy link
Collaborator

@EricCousineau-TRI EricCousineau-TRI commented Apr 24, 2018

In preparation for scalar type conversion with dtype=object, we should ensure that copies should be made when able, but we should error out as early as possible if a user attempts tries to reference existing memory when using dtype=object.

This can help point out areas that can be helped by a custom user-defined dtype, or something that should be reworked in it's generic form.


This change is Reviewable

case return_value_policy::move:
case return_value_policy::copy:
case return_value_policy::automatic_reference:
return eigen_array_cast<props>(*src);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can alphabetize, or use the same ordering as above, or this one?
http://pybind11.readthedocs.io/en/stable/advanced/functions.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK This actually kind of uses the above ordering, but split between success and failure now.
If you look at the subset of cases split between success and failure, you'll see they're in the same order.

if (is_pyobject_<Scalar>()) {
is_pyobject = true;
constexpr bool is_pyobject = is_pyobject_dtype<Scalar>::value;
// TODO(eric.cousineau): Re-enable this once this does not aversely

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand when we will be enabling the assert?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be re-enabled once RobotLocomotion/drake#8452 either merges (in which case no code should run across this) or fails (in which case we want to quickly squash these errors).

As of RobotLocomotion/drake#8665, I've only taken basic steps to support multiple scalar types, some of which compiles this code. I want a run-time error now, so that if anybody uses them right now, they get a quick error, but everything still compiles for the high-level API checks on CI.

Once one of the above happens, then it make sense to elevate to compile-time to more quickly squash its usage.

Clarified the comment too.

@@ -108,7 +108,7 @@ TEST_SUBMODULE(eigen, m) {
m.def("double_threec", [](py::EigenDRef<Eigen::Vector3f> x) { x *= 2; });
m.def("double_adscalarc", [](py::EigenDRef<VectorXADScalar> x) { x *= 2; });
m.def("double_threer", [](py::EigenDRef<Eigen::RowVector3f> x) { x *= 2; });
m.def("double_adscalarr", [](py::EigenDRef<VectorXADScalarR> x) { x *= 2; });
// m.def("double_adscalarr", [](py::EigenDRef<VectorXADScalarR> x) { x *= 2; });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we mean to remove this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Fixed up the tests to have more coverage.

@@ -233,17 +230,22 @@ template <typename props> handle eigen_array_cast(typename props::Type const &sr
src.data(), base);
}
else {
if (base) {
// Should be disabled by `cast_impl`.
throw cast_error("should not have reached here (dtype=object)");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to test this? We are testing just dtype=object in our test which is present in this string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Tried covering this more comprehensively; at this point, I want it to fail mainly; at later points, I would like it to fail at more defined locations. (Added a TODO.)

@EricCousineau-TRI EricCousineau-TRI force-pushed the feature/disable_dtype_object_ref branch from f8d6b82 to 891c253 Compare April 25, 2018 21:34
@m-chaturvedi
Copy link

Reviewed 1 of 4 files at r1, 3 of 3 files at r2.
Review status: all files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

@EricCousineau-TRI EricCousineau-TRI merged commit 14c31ad into RobotLocomotion:drake Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants