当前位置: 首页>>代码示例>>Python>>正文


Python LocalArray.local_from_global方法代码示例

本文整理汇总了Python中distarray.local.localarray.LocalArray.local_from_global方法的典型用法代码示例。如果您正苦于以下问题:Python LocalArray.local_from_global方法的具体用法?Python LocalArray.local_from_global怎么用?Python LocalArray.local_from_global使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在distarray.local.localarray.LocalArray的用法示例。


在下文中一共展示了LocalArray.local_from_global方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cyclic_simple

# 需要导入模块: from distarray.local.localarray import LocalArray [as 别名]
# 或者: from distarray.local.localarray.LocalArray import local_from_global [as 别名]
    def test_cyclic_simple(self):
        """Can we compute local indices for a cyclic distribution?"""
        distribution = Distribution.from_shape(comm=self.comm,
                                        shape=(10,), dist={0: 'c'})
        la = LocalArray(distribution)
        self.assertEqual(la.global_shape, (10,))
        self.assertEqual(la.grid_shape, (4,))

        if la.comm_rank == 0:
            gis = (0, 4, 8)
            self.assertEqual(la.local_shape, (3,))
            calc_result = [la.local_from_global(gi) for gi in gis]
            result = [(0,), (1,), (2,)]
        elif la.comm_rank == 1:
            gis = (1, 5, 9)
            self.assertEqual(la.local_shape, (3,))
            calc_result = [la.local_from_global(gi) for gi in gis]
            result = [(0,), (1,), (2,)]
        elif la.comm_rank == 2:
            gis = (2, 6)
            self.assertEqual(la.local_shape, (2,))
            calc_result = [la.local_from_global(gi) for gi in gis]
            result = [(0,), (1,)]
        elif la.comm_rank == 3:
            gis = (3, 7)
            self.assertEqual(la.local_shape, (2,))
            calc_result = [la.local_from_global(gi) for gi in gis]
            result = [(0,), (1,)]

        self.assertEqual(result, calc_result)
开发者ID:cowlicks,项目名称:distarray,代码行数:32,代码来源:paralleltest_localarray.py

示例2: test_block_simple

# 需要导入模块: from distarray.local.localarray import LocalArray [as 别名]
# 或者: from distarray.local.localarray.LocalArray import local_from_global [as 别名]
    def test_block_simple(self):
        """Can we compute local indices for a block distribution?"""
        distribution = Distribution.from_shape(comm=self.comm, shape=(4, 4))
        la = LocalArray(distribution)
        self.assertEqual(la.global_shape, (4, 4))
        self.assertEqual(la.grid_shape, (4, 1))
        self.assertEqual(la.local_shape, (1, 4))
        row_result = [(0, 0), (0, 1), (0, 2), (0, 3)]

        row = la.comm_rank
        calc_row_result = [la.local_from_global(row, col) for col in
                           range(la.global_shape[1])]
        self.assertEqual(row_result, calc_row_result)
开发者ID:cowlicks,项目名称:distarray,代码行数:15,代码来源:paralleltest_localarray.py

示例3: test_block_complex

# 需要导入模块: from distarray.local.localarray import LocalArray [as 别名]
# 或者: from distarray.local.localarray.LocalArray import local_from_global [as 别名]
    def test_block_complex(self):
        """Can we compute local indices for a block distribution?"""
        distribution = Distribution.from_shape(comm=self.comm, shape=(8, 2))
        la = LocalArray(distribution)
        self.assertEqual(la.global_shape, (8, 2))
        self.assertEqual(la.grid_shape, (4, 1))
        self.assertEqual(la.local_shape, (2, 2))
        expected_lis = [(0, 0), (0, 1), (1, 0), (1, 1)]

        if la.comm_rank == 0:
            gis = [(0, 0), (0, 1), (1, 0), (1, 1)]
        elif la.comm_rank == 1:
            gis = [(2, 0), (2, 1), (3, 0), (3, 1)]
        elif la.comm_rank == 2:
            gis = [(4, 0), (4, 1), (5, 0), (5, 1)]
        elif la.comm_rank == 3:
            gis = [(6, 0), (6, 1), (7, 0), (7, 1)]

        result = [la.local_from_global(*gi) for gi in gis]
        self.assertEqual(result, expected_lis)
开发者ID:cowlicks,项目名称:distarray,代码行数:22,代码来源:paralleltest_localarray.py


注:本文中的distarray.local.localarray.LocalArray.local_from_global方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。