From b1f1d1eb4b40f2836f97c2c88b50ef82ea34124b 2012-04-16 19:13:33 From: MinRK Date: 2012-04-16 19:13:33 Subject: [PATCH] allow map / parallel function for single-engine views --- diff --git a/IPython/parallel/client/remotefunction.py b/IPython/parallel/client/remotefunction.py index ea47005..6031e78 100644 --- a/IPython/parallel/client/remotefunction.py +++ b/IPython/parallel/client/remotefunction.py @@ -182,6 +182,9 @@ class ParallelFunction(RemoteFunction): # 'all' is lazily evaluated at execution time, which is now: if targets == 'all': targets = client._build_targets(targets)[1] + elif isinstance(targets, int): + # single-engine view, targets must be iterable + targets = [targets] nparts = len(targets) msg_ids = [] diff --git a/IPython/parallel/tests/test_view.py b/IPython/parallel/tests/test_view.py index 7c94b85..9ddf41d 100644 --- a/IPython/parallel/tests/test_view.py +++ b/IPython/parallel/tests/test_view.py @@ -534,4 +534,10 @@ class TestView(ClusterTestCase): echo = lambda x:x self.assertRaisesRemote(NameError, v.apply_sync, echo, r) + def test_single_engine_map(self): + e0 = self.client[self.client.ids[0]] + r = range(5) + check = [ -1*i for i in r ] + result = e0.map_sync(lambda x: -1*x, r) + self.assertEquals(result, check)