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
.unique() method of Rotation does not return correct indexing for inversion #272
Conversation
The failing code style seems to be as a result of a new black release https://github.com/psf/black/releases which formats to remove the spaces around the power operator |
This looks like a good catch of a nasty bug. I'm wondering why code using this method relies on the unique elements being sorted. I've certainly utilized this "feature", but not intentionally... It might be better to comply with NumPy without the fix, and then add a Do you know if your fix increases memory use of Thanks for looking up the reason for the code style failing, I've made an issue which I intend to fix shortly. We can continue on this PR without considering that check for now. |
I started to update this here, but have reverted the changes so you can continue with it in #273, which will make keeping track of the changes easier.
I'm not sure why they need to be sorted, but the tests seem to rely on it, so I think it's easiest not to change this for now. In the fix there is an extra intermediate Original code:
Fix:
|
I spent some time on the unique code a while back and I recall deciding the sorting did serve a purpose, what I don't recall, but I think it's worth leaving it like that if we can. |
Thanks @pc494, sounds like a good idea to leave it as is and just correct the inverse map. |
Please feel free to make the separate PR with the Black updates, since you've already done it in this branch :)
I agree, sounds good.
Looks acceptable. I'm curious, with which software did you profile your code? |
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'm happy since the tests pass and all the results in the user guide notebooks look like expected. Thanks for fixing this, @harripj.
I'm planning to review this too, but it might take a day or two |
Will do!
I used |
I've merged #274, so bringing master into this branch should make the code style check pass.
Thanks, will start to use this myself! |
I will just add a line to the changelog now. |
Good, I should have requested that during review, my bad. |
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.
Happy with this, merging
Rotation.unique
appears to have a bug where the returnedinverse
map does not actually reconstruct the original data, which it should as defined the docs and NumPy docs. This is due to some internal sorting such that the returned unique rotations are no longer indexed correctly by the inverse map.A quick solution is to remove the sorting and to add a test to ensure that the reconstructed data is the same as the original data. If there is some reason for the sorting, perhaps another solution can be found.
EDIT
The index sorting turns out is important, at least for the tests, so best to keep this functionality (not sure how I missed this before making the PR). In any case the PR has been updated to keep the original index sorting functionality, but correct the incorrect inverse map.
Progress of the PR
Minimal example of the bug fix or new feature
For reviewers
__init__.py
.unreleased section in
CHANGELOG.rst
.