-
Notifications
You must be signed in to change notification settings - Fork 50
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
Implement rounding consistently to 12 decimal places in orix, eg. in unique()
functions
#285
Conversation
|
From my testing the reason between the two versions ('stable' and 'paddy') in #281 (comment) is that at this line in Line 675 in ff6e541
the min and max differences between the two data arrays are -1.7763568394002505e-15 and 1.7763568394002505e-15 , which then flows through the rest of the function.
|
In orix/orix/quaternion/rotation.py Lines 149 to 159 in ff6e541
|
The behaviour is the same with the next test orix/orix/tests/test_miller.py Line 218 in ff6e541
The output size is |
The indices test also needed correcting orix/orix/tests/test_miller.py Line 220 in ff6e541
However the actual vectors returned before the fix and after are the same, ie. |
From @hakonanes #281:
I agree, if we decide to round in |
The tests for |
This issue reminds me of mtex-toolbox/mtex#1261, where rounding to 12 decimals of vectors fixed an issue in TSL IPF color keys for some Laue classes. We shouldn't round too much, but not too little so that we have to fix this bug again. I suggest 12 decimals for arrays of 64 bit floats, in all rounding cases as you say. If users don't set array data types themselves, they should always be 64 bit floats.
We could, but I don't see a use case for it? |
I agree. There was a nasty rounding case in the tests. In orix/orix/sampling/S2_sampling.py Lines 88 to 92 in ff6e541
With 5 degree resolution, depending on the rounding the returned value from It comes down to whether everyone is okay with Perhaps this will also have changed the notebooks? I will check. |
They look good to me! Only changes I saw was which of the diamond lattice vectors on the equator were considered in the upper hemisphere.
Good catch. The S2 sampling is written by @din14970 in diffsims, which I took into orix (with his permission) to sample orientations for the IPF color keys. I don't consider it a nasty bug, though, as long as the resolution scales more or less as expected with increasing parameter. Haven't actually checked this thoroughly, which we perhaps should do and make into a brief user guide. |
Sorry, should made this #281 (comment) here instead. |
Am I correct in thinking this can now be done as of #288?
It's not necessarily on my cards at the moment, so happy to hold off. I think this can be done explicitly using a combination of |
Yes, with that PR and the rounding in >>> from orix.crystal_map import Phase
>>> from orix.vector import Miller
>>> diamond = Phase(space_group=227)
>>> h = Miller.from_highest_indices(phase=diamond, uvw=[10, 10, 10])
>>> h2 = h.in_fundamental_sector()
>>> h3 = h2.unique(use_symmetry=False)
>>> h4 = h.unique(use_symmetry=True)
>>> print(h.size, h2.size, h3.size, h4.size)
9260 9260 285 285
>>> fig = h3.scatter(return_figure=True, s=5)
>>> h4.scatter(figure=fig, c="g", s=5)
>>> fig.axes[0].plot(diamond.point_group.fundamental_sector.edges, color="r", zorder=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.
Good catch, important fix! Two minor suggestions.
unique
functions
unique
functionsunique
functions
Co-authored-by: Håkon Wiik Ånes <hwaanes@gmail.com>
unique
functionsunique()
functions
unique()
functionsunique()
functions
I'm happy with this, for normal rounding 12/14 decimals place seems fine, ceil bits can be annoying. In general, given how annoying machine specific bugs are I would tend to round too much (and get an error because we rounded - explicit) than too little (and get an error because of machine precision - implicit). Approve, will leave @hakonanes to merge. |
Turns out this was needed for the next thing I had to look at so I'm merging myself. |
Description of the change
A discussed in #281 there appears to be a bug in
Miller.unique
which subsequently causes a failing test in that PR. As As @hakonanes has confirmed in that PR, this appears to be a floating point bug, and rounding, even to a large precision (14 dp), corrects the bug.So whilst implementing #281 has shown the bug and corrects it, I am not sure whether we should rely completely on this or whether we should manually implement some rounding in
unique
to be sure we always get the expected behaviour.Some thoughts on this would be great.
This PR also corrects the test and removes an unneeded line as discussed in #281.
Update:
Rounding, for example in
unique
functions, has been consistently fixed to 12 dp for the repository.Progress of the PR
Example code
From @hakonanes in #281
#281 (comment)
For reviewers
__init__.py
.unreleased section in
CHANGELOG.rst
.