-
Notifications
You must be signed in to change notification settings - Fork 45
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
Speed up dot
and dot_outer
by not calling unique
for identical Symmetry
#303
Speed up dot
and dot_outer
by not calling unique
for identical Symmetry
#303
Conversation
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.
This is a great speed-up and good additions to the tests.
In addition to the other requests, could you update the changelog?
So an interesting side effect of adding the equality operator to the EDIT |
In fact I believe this can be generalised further by checking whether either all_sym_sg = []
for s1 in symmetry._groups:
res = []
for s2 in s1.subgroups:
# outer of symmetry with its subgroups
u = s1.outer(s2).unique()
# assert that unique is same size as main symmetry
if u.size != s1.size:
res.append(False)
else:
# check that there is no difference between unique
# and main symmetry
diff = (s1 * ~u).angle.data
if np.allclose(diff, 0):
res.append(True)
else:
res.append(False)
all_sym_sg.append(all(res))
all(all_sym_sg)
True |
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've got no comments on this, the coverage has dropped though - happy to let @hakonanes lead reviewing on this.
Thanks, I will get on it. |
Check whether one symmetry of sym1 and sym2 exists in the suubgroup of the other
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 speed-up and much more robusts tests are great!
I have a couple of questions. Also, could you add to the changelog stating that the S4 symmetry has been corrected?
Just a note on performance: >>> import orix
>>> from orix.quaternion.symmetry import Oh
>>> %timeit Oh == Oh
58.8 µs ± 784 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
>>> %timeit Oh in Oh.subgroups
10 ms ± 124 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
>>> %timeit Oh.outer(Oh).unique()
3.25 ms ± 36.9 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) Checking subgroups is currently detrimental to perfoomance, I will add a boolean parameter to the |
We would then have to make
I assume the timings in the top comment still hold, roughly? |
This I am okay with, it is essentially the premise with which we implemented the hash. I'm not considering user-created symmetries for now.
I suspect that this feature could be implemented with a setter, at least for the whole array.
Yes, for identical symmetries. I think for this PR we can keep this identical symmetry check for the performance benefit. |
I haven't coded with those in mind either, but functionality should allow a
Yes, if the whole This issue gets to the heart of something I struggle to decide on whenever writing a class: whether class properties should be computed upon initialization or created upon request via a |
Co-authored-by: Håkon Wiik Ånes <hwaanes@gmail.com>
I'm very happy with this PR, and I'll leave it up to @pc494 to review and merge when he finds the time. |
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.
LGTM, merging
Description of the change
As discussed in #296. The use of
unique
is slow and causes a significant performance hit when not needed. Currently inOrientation.dot
and.dot_outer
unique values of the two symmetries are computed, however when the twoSymmetry
are identical, eg. bothTh
, then this call to unique is not needed. I suggest we add a check to the function to test whether the twoSymmetry
are unique, and if so avoid theunique
call. This may be further extended to related symmetries, eg.Oh
andTh
.Progress of the PR
Minimal example of the bug fix or new feature
For reviewers
__init__.py
.unreleased section in
CHANGELOG.rst
.