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 transforms #744

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Eigen transforms #744

wants to merge 14 commits into from

Conversation

ZackAttack614
Copy link
Collaborator

No description provided.

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 39.71%. Comparing base (c1fbb97) to head (69730dc).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #744      +/-   ##
==========================================
+ Coverage   39.70%   39.71%   +0.01%     
==========================================
  Files         135      135              
  Lines       22392    22393       +1     
==========================================
+ Hits         8890     8893       +3     
+ Misses      13502    13500       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ZackAttack614 ZackAttack614 requested a review from psavery January 10, 2025 19:12
Copy link

@kpwelsh kpwelsh left a comment

Choose a reason for hiding this comment

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

A couple of minor things should be changed.
A couple of minor things could be changed.

Not 100% sure if there is a better way to do the xsimd or not.

@@ -15,6 +15,7 @@ def test_gvec_to_xy_from_file(test_data_dir):
allow_pickle=True
)
for obj in arr:
print(1)
Copy link

Choose a reason for hiding this comment

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

This is a mistake to leave in.

Copy link

Choose a reason for hiding this comment

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

Suggested change
print(1)

m.def("make_binary_rot_mat", &makeBinaryRotMat, "Function that computes a rotation matrix from a binary vector");
m.def("make_rot_mat_of_exp_map", &makeRotMatOfExpMap, "Function that computes a rotation matrix from an exponential map");
m.def("makeOscillRotMat", &makeOscillRotMat, "Function that generates a collection of rotation matrices from two angles (chi, ome)");
m.def("anglesToGvecToDetectorXYFromAngles", &anglesToGvecToDetectorXYFromAngles, "I hate this.");
Copy link

Choose a reason for hiding this comment

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

Inappropriate documentation

Copy link
Collaborator

Choose a reason for hiding this comment

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

This function could just be called anglesToDetectorXY instead.

Copy link

Choose a reason for hiding this comment

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

Suggested change
m.def("anglesToGvecToDetectorXYFromAngles", &anglesToGvecToDetectorXYFromAngles, "I hate this.");
m.def("anglesToDetectorXY", &anglesToDetectorXY, "Converts angles to detector xy coordinates.");

Seems fine to me.

Comment on lines +117 to +120
src_files = [
str(cpp_transform_pkgdir / 'src/transforms.cpp'),
str(cpp_transform_pkgdir / 'src/inverse_distortion.cpp'),
]
Copy link

Choose a reason for hiding this comment

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

Suggested change
src_files = [
str(cpp_transform_pkgdir / 'src/transforms.cpp'),
str(cpp_transform_pkgdir / 'src/inverse_distortion.cpp'),
]

inverse_distortion_ext = Extension(
name='hexrd.extensions.inverse_distortion',
sources=src_files,
extra_compile_args=compiler_flags+['-std=c++14'],
sources=[src_files[1]],
Copy link

Choose a reason for hiding this comment

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

Suggested change
sources=[src_files[1]],
sources=[cpp_transform_pkgdir / 'src/inverse_distortion.cpp'],

@@ -123,15 +137,23 @@ def get_cpp_extensions():
numpy.get_include(),
]

transforms_ext = Extension(
name='hexrd.extensions.transforms',
sources=[src_files[0]],
Copy link

Choose a reason for hiding this comment

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

Suggested change
sources=[src_files[0]],
sources=[cpp_transform_pkgdir / 'src/transforms.cpp'],

setup.py Show resolved Hide resolved
auto mat22 = rMat_c(2, 2);

// SIMD loop for full batches
for (size_t i = 0; i < num_full_batches * batch_size; i += batch_size) {
Copy link

Choose a reason for hiding this comment

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

Can we use xsimd::transform here to avoid writing this loop body twice?

Copy link

Choose a reason for hiding this comment

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

Lets not bother with this. Apparently xsimd::transform was removed recently and is currently in limbo.
xtensor-stack/xsimd#1045

Copy link

Choose a reason for hiding this comment

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

Theres some odd indentation all around this file.
Since we don't have a lot of cpp in this repo, I think its a good idea to start using clang-format here.


# Two binary rmats should be the identity
assert np.allclose(rmat @ rmat, np.eye(3))

Copy link

Choose a reason for hiding this comment

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

Suggested change
assert np.allclose(rmat.T @ rmat, np.eye(3)), "It is orthogonal"
assert np.all((np.abs(rmat) - 1 < 1e-10) | (np.abs(rmat) < 1e-10)), "It is binary"

These seem like reasonable tests to have as well,

'-Wall',
'-shared',
'-std=c++14',
'-funroll-loops',
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think Windows is just going to straight up ignore these. Maybe we should write alternative flags to use for Windows, so it will be optimized as well? Like we did above on line 47. We do have Windows users.

@psavery
Copy link
Collaborator

psavery commented Jan 14, 2025

I ran a quick performance check on running hexrd fit-grains ./mruby_config_composite.yml, and after these changes, it took 139 seconds instead of 141.5 seconds before. It's about the same speed - which is good!

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.

4 participants