Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion distarray/dist/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,17 @@ def __new__(cls, context, shape, dist=None, grid_shape=None, targets=None):

# list of `ClientMap` objects, one per dimension.
maps = [map_from_sizes(*args) for args in zip(shape, dist, grid_shape)]
return cls.from_maps(context=context, maps=maps, targets=targets)

self = cls.from_maps(context=context, maps=maps, targets=targets)

# TODO: FIXME: this is a workaround. The reason we slice here is to
# return a distribution with no empty local shapes. The `from_maps()`
# classmethod should be fixed to ensure no empty local arrays are
# created in the first place. That will remove the need to slice the
# distribution to remove empty localshapes.
if all(d in ('n', 'b') for d in self.dist):
self = self.slice((slice(None),)*self.ndim)
Copy link
Contributor

Choose a reason for hiding this comment

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

(slice(None),)*self.ndim is the same as Ellipsis, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Heh, it doesn't work though, so nevermind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I tried Ellipsis, but it barfed. So this is the workaround for the workaround.

Copy link
Contributor

Choose a reason for hiding this comment

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

Merged. I think it barfed because I don't call sanitize_indices inside
Distribution.slice-- I call it before calling Distribution.slice.

On Mon, Jul 7, 2014 at 4:02 PM, Kurt Smith [email protected] wrote:

In distarray/dist/maps.py:

@@ -612,7 +612,17 @@ def new(cls, context, shape, dist=None, grid_shape=None, targets=None):

     # list of `ClientMap` objects, one per dimension.
     maps = [map_from_sizes(*args) for args in zip(shape, dist, grid_shape)]
  •    return cls.from_maps(context=context, maps=maps, targets=targets)
    
  •    self = cls.from_maps(context=context, maps=maps, targets=targets)
    
  •    # TODO: FIXME: this is a workaround.  The reason we slice here is to
    
  •    # return a distribution with no empty local shapes.  The `from_maps()`
    
  •    # classmethod should be fixed to ensure no empty local arrays are
    
  •    # created in the first place.  That will remove the need to slice the
    
  •    # distribution to remove empty localshapes.
    
  •    if all(d in ('n', 'b') for d in self.dist):
    
  •        self = self.slice((slice(None),)*self.ndim)
    

Yeah, I tried Ellipsis, but it barfed. So this is the workaround for the
workaround.


Reply to this email directly or view it on GitHub
https://github.com/enthought/distarray/pull/502/files#r14622248.

return self

@classmethod
def from_global_dim_data(cls, context, global_dim_data, targets=None):
Expand Down
18 changes: 18 additions & 0 deletions distarray/dist/tests/test_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,23 @@ def test_all_n_dist(self):
self.context.ones(distribution)


class TestNoEmptyLocals(ContextTestCase):

def test_no_empty_local_arrays_4_targets(self):
for n in range(1, 20):
dist = Distribution(self.context, shape=(n,),
dist=('b',),
targets=self.context.targets[:4])
for ls in dist.localshapes():
self.assertNotIn(0, ls)

def test_no_empty_local_arrays_3_targets(self):
for n in range(1, 20):
dist = Distribution(self.context, shape=(n,),
dist=('b',),
targets=self.context.targets[:3])
for ls in dist.localshapes():
self.assertNotIn(0, ls)

if __name__ == '__main__':
unittest.main(verbosity=2)