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

DM-12230: Mapping.applyForward and applyInverse fail on empty arrays #29

Merged
merged 1 commit into from Oct 17, 2017

Conversation

r-owen
Copy link
Contributor

@r-owen r-owen commented Oct 13, 2017

No description provided.

Copy link
Member

@kfindeisen kfindeisen left a comment

Choose a reason for hiding this comment

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

Looks good, a few suggestions below.

@@ -114,8 +114,11 @@ void Mapping::_tran(ConstArray2D const &from, bool doForward, Array2D const &to)
detail::assertEqual(to.getSize<0>(), "to.size[0]", static_cast<std::size_t>(nToAxes), "to coords");
detail::assertEqual(from.getSize<1>(), "from.size[1]", to.getSize<1>(), "to.size[1]");
int const nPts = from.getSize<1>();
astTranN(getRawPtr(), nPts, nFromAxes, nPts, from.getData(), static_cast<int>(doForward), nToAxes, nPts,
to.getData());
// astTranN treats 0 points as an error and the call isn't needed anyway
Copy link
Member

Choose a reason for hiding this comment

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

You might want to explicitly say that the caller is responsible for making to be an empty array of the correct dimensions; it took me a while to convince myself that this method really didn't need to do anything.

Copy link
Contributor Author

@r-owen r-owen Oct 17, 2017

Choose a reason for hiding this comment

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

The caller is always responsible for allocating "to", as per the main description: "Implement applyForward and applyInverse, putting the results into a pre-allocated 2-D array." However, I changed the description of the "to" argument to "@param[out] to transformed coordinates, must be pre-allocated with dimensions (nPts, nOut)".

out_points1 = mapping.applyForward([])
self.assertEqual(len(out_points1), 0)
out_points2 = mapping.applyInverse([])
self.assertEqual(len(out_points2), 0)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe test with a mapping that changes dimensions (e.g., 2 -> 1 or 1 -> 2), and make sure the output is an empty array of the correct width?

Copy link
Contributor Author

@r-owen r-owen Oct 17, 2017

Choose a reason for hiding this comment

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

I will change to using nin!=nout, but the output will be an simply empty in either case. The problem is that I know of no way to call the pybind11 code using a 2-d numpy array that is empty (pybind11 fails claiming the argument type is incorrect); it seems to be a pybind11 limitation. I hate to drag in boost just for one unit test. I have tested manually that it works for ndarrays.

@r-owen r-owen merged commit c3f0dd1 into master Oct 17, 2017
@ktlim ktlim deleted the tickets/DM-12230 branch August 25, 2018 04:30
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.

None yet

2 participants