From c4a28a69114564c181e94a70a04c1d2da87c2d33 Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Tue, 24 Jun 2014 12:03:15 -0500 Subject: [PATCH 1/3] Fix failing empty array tests. --- distarray/dist/distarray.py | 3 ++- distarray/dist/maps.py | 2 +- distarray/dist/tests/test_distarray.py | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/distarray/dist/distarray.py b/distarray/dist/distarray.py index 3c371b6e..0c99fd83 100644 --- a/distarray/dist/distarray.py +++ b/distarray/dist/distarray.py @@ -179,12 +179,13 @@ def get_slice(arr, index, ddpr, comm): return_type, index = sanitize_indices(index, ndim=self.ndim, shape=self.shape) return_proxy = (return_type == 'view') - targets = self.distribution.owning_targets(index) + targets = self.distribution.owning_targets(index) or [0] args = [self.key, index] if self.distribution.has_precise_index: if return_proxy: # returning a new DistArray view new_distribution = self.distribution.slice(index) + targets = new_distribution.targets ddpr = new_distribution.get_dim_data_per_rank() args.extend([ddpr, new_distribution.comm]) local_fn = get_slice diff --git a/distarray/dist/maps.py b/distarray/dist/maps.py index d4cead4f..f7d0e2b3 100644 --- a/distarray/dist/maps.py +++ b/distarray/dist/maps.py @@ -666,7 +666,7 @@ def has_precise_index(self): def slice(self, index_tuple): """Make a new Distribution from a slice.""" - new_targets = self.owning_targets(index_tuple) + new_targets = self.owning_targets(index_tuple) or [0] global_dim_data = [] # iterate over the dimensions for map_, idx in zip(self.maps, index_tuple): diff --git a/distarray/dist/tests/test_distarray.py b/distarray/dist/tests/test_distarray.py index 1f84a5f7..e1a91a9b 100644 --- a/distarray/dist/tests/test_distarray.py +++ b/distarray/dist/tests/test_distarray.py @@ -178,14 +178,12 @@ def test_incomplete_index_block_dist_2d(self): arr = self.context.fromarray(expected) assert_array_equal(arr[1].toarray(), expected[1]) - @unittest.expectedFailure def test_empty_slice_1d(self): shape = (10,) expected = numpy.random.randint(10, size=shape) arr = self.context.fromarray(expected) assert_array_equal(arr[100:].toarray(), expected[100:]) - @unittest.expectedFailure def test_empty_slice_2d(self): shape = (10, 20) expected = numpy.random.randint(10, size=shape) From 9d7e9376ceba363c2dbc270e6eefc2249f4ea079 Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Tue, 24 Jun 2014 12:07:57 -0500 Subject: [PATCH 2/3] Test some of the attributes of the empty slice. --- distarray/dist/tests/test_distarray.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/distarray/dist/tests/test_distarray.py b/distarray/dist/tests/test_distarray.py index e1a91a9b..6bc52227 100644 --- a/distarray/dist/tests/test_distarray.py +++ b/distarray/dist/tests/test_distarray.py @@ -182,7 +182,11 @@ def test_empty_slice_1d(self): shape = (10,) expected = numpy.random.randint(10, size=shape) arr = self.context.fromarray(expected) - assert_array_equal(arr[100:].toarray(), expected[100:]) + out = arr[100:] + self.assertEqual(out.shape, (0,)) + self.assertEqual(out.grid_shape, (1,)) + self.assertEqual(len(out.targets), 1) + assert_array_equal(out.toarray(), expected[100:]) def test_empty_slice_2d(self): shape = (10, 20) From 72bb494f53fd5bc2109dc896b746343c2791a06a Mon Sep 17 00:00:00 2001 From: Robert David Grant Date: Tue, 24 Jun 2014 12:09:42 -0500 Subject: [PATCH 3/3] Check attributes on empty 2d slice. --- distarray/dist/tests/test_distarray.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/distarray/dist/tests/test_distarray.py b/distarray/dist/tests/test_distarray.py index 6bc52227..3ddf79cb 100644 --- a/distarray/dist/tests/test_distarray.py +++ b/distarray/dist/tests/test_distarray.py @@ -192,7 +192,11 @@ def test_empty_slice_2d(self): shape = (10, 20) expected = numpy.random.randint(10, size=shape) arr = self.context.fromarray(expected) - assert_array_equal(arr[100:, 100:].toarray(), expected[100:, 100:]) + out = arr[100:, 100:] + self.assertEqual(out.shape, (0, 0)) + self.assertEqual(out.grid_shape, (1, 1)) + self.assertEqual(len(out.targets), 1) + assert_array_equal(out.toarray(), expected[100:, 100:]) def test_trailing_ellipsis(self): shape = (2, 3, 7, 6)