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
Conversation
8927971
to
6ba8b64
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)".
tests/test_mapping.py
Outdated
out_points1 = mapping.applyForward([]) | ||
self.assertEqual(len(out_points1), 0) | ||
out_points2 = mapping.applyInverse([]) | ||
self.assertEqual(len(out_points2), 0) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
and applyInverse
6ba8b64
to
c3f0dd1
Compare
No description provided.