當前位置: 首頁>>代碼示例>>Python>>正文


Python Distribution.from_shape方法代碼示例

本文整理匯總了Python中distarray.dist.maps.Distribution.from_shape方法的典型用法代碼示例。如果您正苦於以下問題:Python Distribution.from_shape方法的具體用法?Python Distribution.from_shape怎麽用?Python Distribution.from_shape使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在distarray.dist.maps.Distribution的用法示例。


在下文中一共展示了Distribution.from_shape方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_2D

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
 def test_2D(self):
     da = Distribution.from_shape(self.context, (3, 3))
     a = self.context.empty(da)
     db = Distribution.from_shape(self.context, (3, 3), dist=('n', 'b'))
     b = self.context.empty(db)
     self.assertEqual(a.grid_shape, (3, 1))
     self.assertEqual(b.grid_shape, (1, 3))
開發者ID:cowlicks,項目名稱:distarray,代碼行數:9,代碼來源:test_context.py

示例2: test_different_contexts

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
 def test_different_contexts(self):
     ctx1 = Context(targets=range(4))
     ctx2 = Context(targets=range(3))
     distribution1 = Distribution.from_shape(ctx1, (10,))
     distribution2 = Distribution.from_shape(ctx2, (10,))
     da1 = ctx1.ones(distribution1)
     da2 = ctx2.ones(distribution2)
     db1 = self.local_sin(da1)
     db2 = self.local_sin(da2)
     ndarr1 = db1.toarray()
     ndarr2 = db2.toarray()
     assert_array_equal(ndarr1, ndarr2)
開發者ID:MJones810,項目名稱:distarray,代碼行數:14,代碼來源:test_decorators.py

示例3: fromfunction

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
    def fromfunction(self, function, shape, **kwargs):
        """Create a DistArray from a function over global indices.

        Unlike numpy's `fromfunction`, the result of distarray's
        `fromfunction` is restricted to the same Distribution as the
        index array generated from `shape`.

        See numpy.fromfunction for more details.
        """
        dtype = kwargs.get('dtype', None)
        dist = kwargs.get('dist', None)
        grid_shape = kwargs.get('grid_shape', None)
        distribution = Distribution.from_shape(context=self,
                                               shape=shape, dist=dist,
                                               grid_shape=grid_shape)
        ddpr = distribution.get_dim_data_per_rank()
        function_name, ddpr_name, kwargs_name = \
            self._key_and_push(function, ddpr, kwargs)
        da_name = self._generate_key()
        comm_name = self._comm_key
        cmd = ('{da_name} = distarray.local.fromfunction({function_name}, '
               'distarray.local.maps.Distribution('
               '{ddpr_name}[{comm_name}.Get_rank()], comm={comm_name}),'
               '**{kwargs_name})')
        self._execute(cmd.format(**locals()))
        return DistArray.from_localarrays(da_name, distribution=distribution)
開發者ID:MJones810,項目名稱:distarray,代碼行數:28,代碼來源:context.py

示例4: test_randint

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
 def test_randint(self):
     low = 1
     shape = (3, 4)  # aka shape
     distribution = Distribution.from_shape(context=self.context,
                                            shape=shape)
     a = self.random.randint(distribution, low=low)
     self.assertEqual(a.shape, shape)
開發者ID:MJones810,項目名稱:distarray,代碼行數:9,代碼來源:test_random.py

示例5: test_get_index_error

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
 def test_get_index_error(self):
     distribution = Distribution.from_shape(self.dac, (10,), dist={0: 'c'})
     dap = self.dac.empty(distribution)
     with self.assertRaises(IndexError):
         dap[11]
     with self.assertRaises(IndexError):
         dap[-11]
開發者ID:MJones810,項目名稱:distarray,代碼行數:9,代碼來源:test_distarray.py

示例6: test_grid_rank

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
 def test_grid_rank(self):
     # regression test for issue #235
     d = Distribution.from_shape(self.context, (4, 4, 4),
                                 dist=('b', 'n', 'b'),
                                 grid_shape=(1, 1, 4))
     a = self.context.empty(d)
     self.assertEqual(a.grid_shape, (1, 1, 4))
開發者ID:cowlicks,項目名稱:distarray,代碼行數:9,代碼來源:test_distarray.py

示例7: test_tondarray

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
 def test_tondarray(self):
     distribution = Distribution.from_shape(self.context, (3, 3))
     dap = self.context.empty(distribution)
     ndarr = numpy.arange(9).reshape(3, 3)
     for (i, j), val in numpy.ndenumerate(ndarr):
         dap[i, j] = ndarr[i, j]
     numpy.testing.assert_array_equal(dap.tondarray(), ndarr)
開發者ID:cowlicks,項目名稱:distarray,代碼行數:9,代碼來源:test_distarray.py

示例8: test_set_index_error

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
 def test_set_index_error(self):
     distribution = Distribution.from_shape(self.context, (10,), dist={0: 'c'})
     dap = self.context.empty(distribution)
     with self.assertRaises(IndexError):
         dap[11] = 55
     with self.assertRaises(IndexError):
         dap[-11] = 55
開發者ID:cowlicks,項目名稱:distarray,代碼行數:9,代碼來源:test_distarray.py

示例9: test_key_and_push_args

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
    def test_key_and_push_args(self):
        context = Context()

        distribution = Distribution.from_shape(context, (2, 2))
        da = context.ones(distribution)
        db = da*2

        def dummy_func(*args, **kwargs):
            fn = lambda x: x
            db = DecoratorBase(fn)
            return db.key_and_push_args(args, kwargs)

        # Push some distarrays
        arg_keys1, kw_keys1 = dummy_func(da, db, foo=da, bar=db)
        # with some other data too
        arg_keys2, kw_keys2 = dummy_func(da, 'question', answer=42, foo=db)

        self.assertEqual(arg_keys1, "(%s, %s,)" % (da.key, db.key))
        # assert we pushed the right key, keystr pair
        self.assertTrue("'foo': %s" % (da.key) in kw_keys1)
        self.assertTrue("'bar': %s" % (db.key) in kw_keys1)

        # lots of string manipulation to parse out the relevant pieces
        # of the python commands.
        self.assertEqual(arg_keys2[1: -2].split(', ')[0], da.key)

        _key = arg_keys2[1: -2].split(', ')[1]
        self.assertEqual(context._pull0(_key), 'question')
        self.assertTrue("'answer'" in kw_keys2)

        self.assertTrue("'foo'" in kw_keys2)
        self.assertTrue(db.key in kw_keys2)
開發者ID:MJones810,項目名稱:distarray,代碼行數:34,代碼來源:test_decorators.py

示例10: test_global_tolocal_bug

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
 def test_global_tolocal_bug(self):
     # gh-issue #154
     distribution = Distribution.from_shape(self.context, (3, 3),
                                            dist=('n', 'b'))
     dap = self.context.zeros(distribution)
     ndarr = numpy.zeros((3, 3))
     numpy.testing.assert_array_equal(dap.tondarray(), ndarr)
開發者ID:cowlicks,項目名稱:distarray,代碼行數:9,代碼來源:test_distarray.py

示例11: test___init__

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
 def test___init__(self):
     shape = (5, 5)
     distribution = Distribution.from_shape(self.context, shape, ('b', 'c'))
     da = DistArray(distribution, dtype=int)
     da.fill(42)
     nda = numpy.empty(shape, dtype=int)
     nda.fill(42)
     assert_array_equal(da.tondarray(), nda)
開發者ID:cowlicks,項目名稱:distarray,代碼行數:10,代碼來源:test_distarray.py

示例12: test_iteration

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
 def test_iteration(self):
     size = 10
     distribution = Distribution.from_shape(self.context, (size,),
                                            dist={0: 'c'})
     dap = self.context.empty(distribution)
     dap.fill(10)
     for val in dap:
         self.assertEqual(val, 10)
開發者ID:cowlicks,項目名稱:distarray,代碼行數:10,代碼來源:test_distarray.py

示例13: test_local_add_supermix

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
 def test_local_add_supermix(self):
     distribution = Distribution.from_shape(self.context, (5, 5))
     dm = self.context.empty(distribution)
     dm.fill(22)
     dn = self.context.empty(distribution)
     dn.fill(44)
     do = self.local_add_supermix(self.da, 11, dm, 33, dc=dn, num3=55)
     expected = 2 * numpy.pi + 11 + 22 + 33 + 44 + 55 + 66
     self.assert_allclose(do, expected)
開發者ID:MJones810,項目名稱:distarray,代碼行數:11,代碼來源:test_decorators.py

示例14: test_empty_localarray

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
 def test_empty_localarray(self):
     if len(self.context.targets) < 2:
         raise self.skipTest("not enough targets to run test.")
     dist = Distribution.from_shape(self.context,
                                    shape=(1,),
                                    dist=('b',),
                                    targets=self.context.targets[:2])
     darr = self.context.ones(dist)
     self.assertRaises(NotImplementedError, darr.min, ())
     self.assertRaises(NotImplementedError, darr.sum, (), {'axis':0})
開發者ID:cowlicks,項目名稱:distarray,代碼行數:12,代碼來源:test_distarray.py

示例15: test_create_target_subset

# 需要導入模塊: from distarray.dist.maps import Distribution [as 別名]
# 或者: from distarray.dist.maps.Distribution import from_shape [as 別名]
    def test_create_target_subset(self):
        shape = (100, 100)
        subtargets = self.context.targets[::2]
        distribution = Distribution.from_shape(self.context, shape=shape, targets=subtargets)
        darr = self.context.ones(distribution)
        lss = darr.get_localshapes()
        self.assertEqual(len(lss), len(subtargets))

        ddpr = distribution.get_dim_data_per_rank()
        self.assertEqual(len(ddpr), len(subtargets))
開發者ID:cowlicks,項目名稱:distarray,代碼行數:12,代碼來源:test_distarray.py


注:本文中的distarray.dist.maps.Distribution.from_shape方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。