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-32008: Wrap test_spoke
in C++/pybind11
#152
Conversation
test_spoke
in C++/pybind1test_spoke
in C++/pybind11
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.
Please pull testSpoke
out into a separate src/X.cc
file and switch to using ndarray instead of py::array
(which I don't believe we use anywhere). I'll look at it again after that. The array access should be simpler after this.
|
||
namespace { | ||
|
||
int testSpoke(double cos_theta_src, double sin_theta_src, py::array_t<double> ref_ctr, int ref_ctr_id, |
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 think this function should be implemented in a file in src/
, with a header in include/
(which then gets the docstrings that this definitely needs!); the only thing in this pybind file should be the PYBIND11_MODULE
below.
int testSpoke(double cos_theta_src, double sin_theta_src, py::array_t<double> ref_ctr, int ref_ctr_id, | ||
py::array_t<double> proj_ref_ctr_delta, double proj_ref_ctr_dist_sq, | ||
py::array_t<unsigned int> ref_dist_idx_array, py::array_t<unsigned int> ref_id_array, | ||
py::array_t<double> reference_array, double src_sin_tol) { |
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.
These py::array_t
should be ndarray::Array<type, 1>
when you move this to src/
. Then I think you won't need the unchecked
iterators below, you can just do ref_ctr[0]
, etc.
c91751b
to
7f637bc
Compare
Finished things up mostly except for one compiler warning. |
Please squash your commits. |
* no match is found. | ||
*/ | ||
int check_spoke(double cos_theta_src, double sin_theta_src, ndarray::Array<double, 1, 1> const& ref_ctr, | ||
uint16_t ref_ctr_id, ndarray::Array<double, 1, 1> const& proj_ref_ctr_delta, |
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.
Is ref_ctr_id
really a uint16? That means the refcat can only have 65k entries. I'd expect this, ref_id_array
, and ref_dist_idx_array to all be std::size_t
, since they are array indexes.
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.
It is. I'll change the other two types and see if it compiles.
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.
Did these not work as size_t? The uint16 makes me uncomfortable.
|
||
PYBIND11_MODULE(pessimisticPatternMatcherUtils, mod) { | ||
mod.def("check_spoke", &check_spoke, | ||
"Test the opening angle between the spokes of our source pattern against the reference."); |
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.
Huh, I wasn't aware that you could add a python docstring like this. We don't mention it in the dev guide, but we probably should!
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.
A number of array cleanups: Eigen and ndarray can do a bunch of things to clean this up.
Just to check: you ran clang-format on this?
for (auto idx = ref_dist_idx_array.begin(); idx != ref_dist_idx_array.end(); idx++) { | ||
/// Compute the delta vector from the pattern center. | ||
unsigned int ref_id = ref_id_array[*idx]; | ||
double ref_delta[3]; |
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.
Make this an ndarray, so you can directly assign it:
Array<double, 1, 2> ref_delta = copy(reference_array[ref_id] - ref_ctr);
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.
Will do. However I will point out that the last number of is the number of contiguous dimensions. So you can't have 1, 2. This would be 1, 1.
(proj_ref_delta[0] * proj_ref_ctr_delta[1] - proj_ref_delta[1] * proj_ref_ctr_delta[0]) / | ||
geom_dist_ref; | ||
double sin_theta_ref = | ||
cross_ref[0] * ref_ctr[0] + cross_ref[1] * ref_ctr[1] + cross_ref[2] * ref_ctr[2]; |
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.
And again, with Eign, something like:
double sin_theta_ref = cross_ref.asEigenMatrix().dot(ref_ctr.asEigenMatrix());
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'll give these a shot on one or two of them and see if I can get it to compile/run. If I can't though, I'm not too uncomfortable with just leaving it for now.
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.
Done.
Clang format is running every time I save the file, yes. |
6234f6c
to
a2e0de3
Compare
c2f5f27
to
1dc498a
Compare
namespace astrom { | ||
|
||
int check_spoke(double cos_theta_src, double sin_theta_src, ndarray::Array<double, 1, 1> const& ref_ctr, | ||
uint16_t ref_ctr_id, ndarray::Array<double, 1, 1> const& proj_ref_ctr_delta, |
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.
Hang on, I don't see ref_ctr_id used in the C++ code below at all?
* the source spoke we are trying to test and the candidate reference | ||
* spokes. | ||
* @param[in] ref_id_array Array of id lookups into the master reference array | ||
* that our center id object is paired with. |
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.
Please add a note here about why this is uint16 (as you said, the higher level code trims the arrays due to memory limits): it's generally expected that indexes are size_t.
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.
Remove ref_ctr_id, add a note about why ref_id_array is uint16, and you're good to go.
Done! Take a look at the comment for yourself if you want. |
8392297
to
04221e1
Compare
Add pybind layer. Add pessimistic utils to SConscript and import. Add testSpokeCC to pessimitic matcher. Remove call to old _test_spoke method. Create header and source file. Move code to source file. Change to using ndarray. Add doxygen. Change function name. Change input arrays to const& Switch to eigen operations for cross and dot products. Update comment around for loop. Change to double slash. Change cross product to eigen. Remove unused ref_ctr_id variable. Add comment. Clang fortmating.
04221e1
to
8898f17
Compare
No description provided.