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

Improving the performance of the samplings utils (see #175) #177

Merged
merged 15 commits into from
May 7, 2021

Conversation

pc494
Copy link
Member

@pc494 pc494 commented Apr 25, 2021

Description of the change

Improving the performance of the gridding utils by allowing a uniform sampling of a subspace (see #175 for details). I've also renamed a file to be more consistent with what I imagine this part of the code will look like in the future.

Progress of the PR

For reviewers

  • The PR title is short, concise, and will make sense 1 year later.
  • New functions are imported in corresponding __init__.py.
  • New features, API changes, and deprecations are mentioned in the
    unreleased section in CHANGELOG.rst.

@pc494
Copy link
Member Author

pc494 commented Apr 26, 2021

While I'm here I'm going to tidy up the class method "random":

def random(cls, shape=(1,)):
which is quiet sloppy at the moment.

I'll also look into the

def random_vonmises(cls, shape=(1,), alpha=1.0, reference=(1, 0, 0, 0)):
functionality.

@pc494 pc494 mentioned this pull request Apr 29, 2021
9 tasks
@pc494 pc494 changed the title Improving the performance of the gridding utils (see #175) Improving the performance of the samplings utils (see #175) Apr 30, 2021
@pc494 pc494 requested a review from hakonanes April 30, 2021 12:09
@pc494
Copy link
Member Author

pc494 commented Apr 30, 2021

While I'm here I'm going to tidy up the class method "random":

def random(cls, shape=(1,)):

which is quiet sloppy at the moment.

I'll also look into the

def random_vonmises(cls, shape=(1,), alpha=1.0, reference=(1, 0, 0, 0)):

functionality.

Going to transfer this into an issue to be dealt with when the large refactor comes in at some point in the future.

Copy link
Member

@hakonanes hakonanes left a comment

Choose a reason for hiding this comment

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

Thanks for looking into the rotation sampling, @pc494.

I haven't fully understood the maths involved here, but the sample returned with angles of about 1-7 degrees accompanied by a resolution in the order of 0.5 degrees returns an empty sampling. Could you explain this to me?

Apart from this, I like that you've renamed the utilities to SO3, so that we can easily fit SO2 in the future into this orix.sampling module.

orix/sampling/SO3_sampling.py Outdated Show resolved Hide resolved
orix/sampling/SO3_sampling.py Show resolved Hide resolved
orix/sampling/SO3_sampling.py Show resolved Hide resolved
orix/sampling/SO3_sampling.py Outdated Show resolved Hide resolved
orix/sampling/sample_generators.py Outdated Show resolved Hide resolved
e_1_min = np.cos(np.deg2rad(max_angle/2))
u_1_max = 1 - np.square(e_1_min)
u_2_min = np.arcsin(e_1_min) / 2 / np.pi
u_1 = np.linspace(0,u_1_max,num=int(num_steps*(u_1_max)),endpoint=True)
Copy link
Member

Choose a reason for hiding this comment

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

int(num_steps * u_1_max) becomes zero when u_1_max is small (see comment to get_sample_local()). Is there some way to handle the case where max angle is small (1-7 degrees) and a resolution of below 1 degree?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, putting a crude fix in for this

@hakonanes hakonanes added the enhancement New feature or request label May 2, 2021
@hakonanes hakonanes added this to the v0.6.0 milestone May 2, 2021
@pc494
Copy link
Member Author

pc494 commented May 2, 2021

Thanks @hakonanes for this review, it's very good. It'll take me a little while to loop back to this but when I do I think most of the style changes will be simple to implement. The version in 0.6 is going to be a bit lacking (although we can fix the bug that gives back empty regions) and I've got a sense of what a more complete implementation will look like (probably for 0.7.0)

@hakonanes
Copy link
Member

That sounds like a good plan. As mentioned in #175, there is no rush.

@pc494 pc494 self-assigned this May 6, 2021
Copy link
Member Author

@pc494 pc494 left a comment

Choose a reason for hiding this comment

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

Working on these locally, will be up shortly.

orix/sampling/SO3_sampling.py Show resolved Hide resolved
orix/sampling/SO3_sampling.py Show resolved Hide resolved
orix/sampling/SO3_sampling.py Outdated Show resolved Hide resolved
orix/sampling/SO3_sampling.py Outdated Show resolved Hide resolved
e_1_min = np.cos(np.deg2rad(max_angle/2))
u_1_max = 1 - np.square(e_1_min)
u_2_min = np.arcsin(e_1_min) / 2 / np.pi
u_1 = np.linspace(0,u_1_max,num=int(num_steps*(u_1_max)),endpoint=True)
Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, putting a crude fix in for this

orix/sampling/sample_generators.py Outdated Show resolved Hide resolved
@hakonanes
Copy link
Member

Good stuff! I'll let you merge yourself, @pc494.

@pc494 pc494 merged commit 13ff938 into pyxem:master May 7, 2021
@pc494 pc494 deleted the fix-for-175 branch May 7, 2021 14:08
@pc494 pc494 mentioned this pull request May 16, 2021
7 tasks
@pc494 pc494 restored the fix-for-175 branch May 16, 2021 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants