Exemplo n.º 1
0
 def test_create_Context_with_targets_ranks(self):
     """Check that the target <=> rank mapping is consistent."""
     check_targets(required=4, available=len(self.client))
     targets = [3, 2]
     dac = Context(self.client, targets=targets)
     self.assertEqual(set(dac.targets), set(targets))
     dac.close()
Exemplo n.º 2
0
 def test_create_Context_with_targets_ranks(self):
     """Check that the target <=> rank mapping is consistent."""
     check_targets(required=4, available=len(self.client))
     targets = [3, 2]
     dac = Context(self.client, targets=targets)
     self.assertEqual(set(dac.targets), set(targets))
     dac.close()
Exemplo n.º 3
0
 def test_create_delete_key(self):
     """ Check that a key can be created and then destroyed. """
     dac = Context()
     # Create and push a key/value.
     key, value = dac._generate_key(), 'test'
     dac._push({key: value}, targets=dac.targets)
     # Delete the key.
     dac.delete_key(key)
     dac.close()
Exemplo n.º 4
0
 def test_create_Context_with_targets_ranks(self):
     """Check that the target <=> rank mapping is consistent."""
     from distarray.globalapi.context import MPIContext
     check_targets(required=4, available=MPIContext.INTERCOMM.remote_size)
     targets = [3, 2]
     dac = Context(targets=targets)
     self.assertEqual(set(dac.targets), set(targets))
Exemplo n.º 5
0
 def test_create_delete_key(self):
     """ Check that a key can be created and then destroyed. """
     dac = Context()
     # Create and push a key/value.
     key, value = dac._generate_key(), 'test'
     dac._push({key: value}, targets=dac.targets)
     # Delete the key.
     dac.delete_key(key)
     dac.close()
Exemplo n.º 6
0
 def test_context_target_reordering(self):
     """Are contexts' targets reordered in a consistent way?"""
     orig_targets = self.client.ids
     targets1 = orig_targets[:]
     targets2 = orig_targets[:]
     shuffle(targets1)
     shuffle(targets2)
     ctx1 = Context(self.client, targets=targets1)
     ctx2 = Context(self.client, targets=targets2)
     self.assertEqual(ctx1.targets, ctx2.targets)
     ctx1.close()
     ctx2.close()
Exemplo n.º 7
0
    def test_local(self):
        context = Context()

        shape = (4, 4)
        da = context.empty(shape)
        a = numpy.empty(shape)

        def fill_a(a):
            for (i, j), _ in numpy.ndenumerate(a):
                a[i, j] = i + j
            return a

        def fill_da(da):
            for i in da.distribution[0].global_iter:
                for j in da.distribution[1].global_iter:
                    da.global_index[i, j] = i + j
            return da

        self.context.register(fill_da)

        da = self.context.fill_da(da)
        a = fill_a(a)

        assert_array_equal(da.tondarray(), a)
Exemplo n.º 8
0
    def test_local(self):
        context = Context()

        shape = (4, 4)
        da = context.empty(shape)
        a = numpy.empty(shape)

        def fill_a(a):
            for (i, j), _ in numpy.ndenumerate(a):
                a[i, j] = i + j
            return a

        def fill_da(da):
            for i in da.distribution[0].global_iter:
                for j in da.distribution[1].global_iter:
                    da.global_index[i, j] = i + j
            return da

        self.context.register(fill_da)

        da = self.context.fill_da(da)
        a = fill_a(a)

        assert_array_equal(da.tondarray(), a)
Exemplo n.º 9
0
 def test_context_target_reordering(self):
     """Are contexts' targets reordered in a consistent way?"""
     orig_targets = self.client.ids
     targets1 = orig_targets[:]
     targets2 = orig_targets[:]
     shuffle(targets1)
     shuffle(targets2)
     ctx1 = Context(self.client, targets=targets1)
     ctx2 = Context(self.client, targets=targets2)
     self.assertEqual(ctx1.targets, ctx2.targets)
     ctx1.close()
     ctx2.close()
Exemplo n.º 10
0
 def make_context(cls, targets=None):
     try:
         return Context(targets=targets)
     except EnvironmentError:
         msg = "You must have an ipcluster running to run this test case."
         raise unittest.SkipTest(msg)
Exemplo n.º 11
0
 def make_context(cls, targets=None):
     return Context(kind='MPI', targets=targets)
Exemplo n.º 12
0
 def test_create_Context_with_targets(self):
     """Can we create a context with a subset of engines?"""
     check_targets(required=2, available=len(self.client))
     dac = Context(self.client, targets=[0, 1])
     self.assertIs(dac.client, self.client)
     dac.close()
Exemplo n.º 13
0
 def test_create_Context_with_targets(self):
     """Can we create a context with a subset of engines?"""
     from distarray.globalapi.context import MPIContext
     check_targets(required=2, available=MPIContext.INTERCOMM.remote_size)
     Context(targets=[0, 1])
Exemplo n.º 14
0
 def test_create_context(self):
     Context()
Exemplo n.º 15
0
 def test_create_Context_with_targets(self):
     """Can we create a context with a subset of engines?"""
     check_targets(required=2, available=len(self.client))
     dac = Context(self.client, targets=[0, 1])
     self.assertIs(dac.client, self.client)
     dac.close()
Exemplo n.º 16
0
 def test_create_Context(self):
     """Can we create a plain vanilla context?"""
     dac = Context(kind='IPython', client=self.client)
     self.assertIs(dac.client, self.client)