Skip to content

Add __getitem__ slicing#384

Merged
kwmsmith merged 56 commits into
masterfrom
feature/add-slicing
Jun 12, 2014
Merged

Add __getitem__ slicing#384
kwmsmith merged 56 commits into
masterfrom
feature/add-slicing

Conversation

@bgrant
Copy link
Copy Markdown
Contributor

@bgrant bgrant commented May 26, 2014

Add support for slicing (including incomplete indexing) through a DistArray's __getitem__. Currently only BlockMaps and NoDistMaps are supported, and only slices with step-sizes of 1 are supported.

Slices return DistArray views as one would expect.

This required a small bit of refactoring

  1. I added a couple small attributes to NoDistMaps from BlockMaps for convenience
  2. I consolidated two separated implementations of sanitize_indices and expanded its functionality and usage.

Slicing currently throws errors when a resulting slice would have a dimension of size 0, but maybe Kurt's upcoming changes will resolve this.

bgrant added 30 commits May 7, 2014 13:44
Slicing is kind of working!
…add-slicing

Conflicts:
	distarray/dist/distarray.py
Slices shouldn't be bounds checked.
in DistArray.from_localarrays.
and reuse it on the client side.  Also factor out a _process_return_value function.
This method allows making a new client-side Distribution object from a Distribution and slice.
@kwmsmith kwmsmith modified the milestones: 0.3, 0.4 May 27, 2014
@kwmsmith
Copy link
Copy Markdown
Contributor

This is great -- will review soon. I recommend we merge the reduction stuff first, and get the 0-dimensional and n-dimensional with shape entry of 0 working before merging this.

I think slicing the other distribution types is possible with certain constraints in place -- we should discuss. Those should come in future PRs, of course.

Other features for future PRs:

  • step size >1 and < 0,
  • Slicing cyclic with block_size==1 and slice step==1
  • Evaluate slicing block cyclic with slice step==1,
  • Slicing unstructured -- I think we can do it with an extra roundtrip.

@bgrant
Copy link
Copy Markdown
Contributor Author

bgrant commented May 27, 2014

Also for a future PR:

  • __setitem__ slicing. I think this will be easier than __getitem__ was, since you don't have to return a new DistArray.

@bgrant bgrant mentioned this pull request May 27, 2014
Comment thread distarray/dist/maps.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To allow us to implement this on other map subclasses in the future, can we put a slice() method on the map subclasses, and have Distribution.slice() call its map slices in a polymorphic way?

bgrant added 2 commits May 29, 2014 15:12
Conflicts:
	distarray/dist/maps.py
	distarray/dist/tests/test_maps.py
	distarray/local/localarray.py
	distarray/metadata_utils.py
@cowlicks
Copy link
Copy Markdown
Contributor

cowlicks commented Jun 2, 2014

The merges from master make this hard to review. Could you rebase in the future?

@bgrant
Copy link
Copy Markdown
Contributor Author

bgrant commented Jun 2, 2014

@cowlicks: I'm not really sold on history rewriting, but I could be convinced. What about the merge commits make this hard to review?

@cowlicks
Copy link
Copy Markdown
Contributor

cowlicks commented Jun 3, 2014

What is wrong with rewriting history locally? No one has a copy of your local branch, so you could rebase before you push. So you wouldn't need to add a merge at the end of the PR. I agree that we should not rewrite the history of any branch on DistArray's public repo. I think personal dev forks are usually okay to rewrite, unless another dev has expressed interest in working off one of your forks.

Generally I review a PR by looking at the list of commit messages. Then trying to understand how they are accomplishing the goal of the PR. From there, I read each commit consecutively. And make sure it does what the commit message says. And that it does nothing weird or buggy.

However this does not work if you carefully craft all your commit then throw a merge in at the end. Since the merge changes a bunch of stuff potentially related to your PR. A bunch of my comments are probably obsolete, and everything after the commit it should probably be re-reviewed.

I realize there is the other reviewing strategy of click on "files changed" and read everything. This is generally what I have to do when I realize a bunch of commits overlap. However this basically leaves you reviewing a giant diff with no commit messages. Which is frustrating because you have no idea what the changes are intended to do except for what is in the PR message.

Conflicts:
	distarray/dist/maps.py
	distarray/dist/tests/test_distarray.py
	distarray/dist/tests/test_maps.py
	distarray/local/localarray.py
	distarray/local/maps.py
@kwmsmith
Copy link
Copy Markdown
Contributor

kwmsmith commented Jun 9, 2014

@bgrant -- what about creating a slice_owners() method on the client-side maps that handles the slice case, and perhaps rename owners() to index_owners() (which handles the other case)? the if isinstance(..., Integral) and elif isinstance(..., slice) looks like a code smell to me that suggests breaking out a separate method.

Also, same question for the local side -- what about adding a local_from_global_slice() method to the local map subclasses?

Comment thread distarray/local/localarray.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems like this error case should be dealt with immediately after the santitize_indices() call -- reason for handling it here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That seems correct.

@bgrant
Copy link
Copy Markdown
Contributor Author

bgrant commented Jun 12, 2014

Okay @kwmsmith : comments addressed.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.38%) when pulling 911925b on feature/add-slicing into de18b91 on master.

kwmsmith added a commit that referenced this pull request Jun 12, 2014
@kwmsmith kwmsmith merged commit 7a7bf40 into master Jun 12, 2014
@kwmsmith kwmsmith deleted the feature/add-slicing branch June 12, 2014 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants