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

Fix indexing/slicing into sliced CrystalMap #391

Merged
merged 3 commits into from
Sep 30, 2022

Conversation

hakonanes
Copy link
Member

@hakonanes hakonanes commented Sep 28, 2022

Description of the change

I discovered a bug where indexing/slicing into an already sliced CrystalMap assumed the initial shape (_original_shape) and not the current shape.

Progress of the PR

Minimal example of the bug fix or new feature

>>> from orix.crystal_map import CrystalMap
>>> xmap = CrystalMap.empty((4, 5))
>>> xmap.id.reshape(xmap.shape)
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19]])
>>> xmap2 = xmap[1:4, :3]
>>> xmap2._original_shape
(4, 5)
>>> xmap2.id.reshape(xmap2.shape)
array([[ 5,  6,  7],
       [10, 11, 12],
       [15, 16, 17]])

Getting some IDs of xmap2 before this fix

>>> xmap2[1, 1].id
array([11])
>>> xmap2[:2, :2].id
array([5, 6])

and after this fix

>>> xmap2[1, 1].id
array([13])
>>> xmap2[:2, :2].id
array([ 5,  6, 10, 11])

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.
  • Contributor(s) are listed correctly in __credits__ in orix/__init__.py and in
    .zenodo.json.

Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
@hakonanes hakonanes added the bug Something isn't working label Sep 28, 2022
@hakonanes hakonanes added this to the v0.10.1 milestone Sep 28, 2022
@hakonanes hakonanes marked this pull request as draft September 28, 2022 17:24
@hakonanes hakonanes marked this pull request as ready for review September 28, 2022 19:26
@hakonanes hakonanes mentioned this pull request Sep 29, 2022
5 tasks
Copy link
Member

@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.

also good, merging.

@pc494 pc494 merged commit 0af45ad into pyxem:main Sep 30, 2022
@hakonanes hakonanes deleted the fix-indexing-sliced-xmap branch September 30, 2022 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants