当前位置: 首页>>代码示例>>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;未经允许,请勿转载。