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


Python Distribution.from_dim_data_per_rank方法代码示例

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


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

示例1: from_localarrays

# 需要导入模块: from distarray.dist.maps import Distribution [as 别名]
# 或者: from distarray.dist.maps.Distribution import from_dim_data_per_rank [as 别名]
    def from_localarrays(cls, key, context=None, targets=None, distribution=None,
                         dtype=None):
        """The caller has already created the LocalArray objects.  `key` is
        their name on the engines.  This classmethod creates a DistArray that
        refers to these LocalArrays.

        Either a `context` or a `distribution` must also be provided.  If
        `context` is provided, a ``dim_data_per_rank`` will be pulled from
        the existing ``LocalArray``\s and a ``Distribution`` will be created
        from it.   If `distribution` is provided, it should accurately
        reflect the  distribution of the existing ``LocalArray``\s.

        If `dtype` is not provided, it will be fetched from the engines.
        """

        def get_dim_datas_and_dtype(arr):
            return (arr.dim_data, arr.dtype)

        da = cls.__new__(cls)
        da.key = key

        if (context is None) == (distribution is None):
            errmsg = "Must provide `context` or `distribution` but not both."
            raise RuntimeError(errmsg)

        # has context, get dist and dtype
        elif (distribution is None) and (dtype is None):
            res = context.apply(get_dim_datas_and_dtype, args=(key,))
            dim_datas = [i[0] for i in res]
            dtypes = [i[1] for i in res]
            da._dtype = dtypes[0]
            da.distribution = Distribution.from_dim_data_per_rank(context,
                                                                  dim_datas,
                                                                  targets)

        # has context and dtype, get dist
        elif (distribution is None) and (dtype is not None):
            da._dtype = dtype
            dim_datas = context.apply(getattr, args=(key, 'dim_data'))
            da.distribution = Distribution.from_dim_data_per_rank(context,
                                                                  dim_datas,
                                                                  targets)

        # has distribution, get dtype
        elif (distribution is not None) and (dtype is None):
            da.distribution = distribution
            da._dtype = distribution.context.apply(getattr,
                                                   args=(key, 'dtype'),
                                                   targets=[0])[0]
        # has distribution and dtype
        elif (distribution is not None) and (dtype is not None):
            da.distribution = distribution
            da._dtype = dtype

        # sanity check that I didn't miss any cases above, because this is a
        # confusing function
        else:
            assert False
        return da
开发者ID:cowlicks,项目名称:distarray,代码行数:61,代码来源:distarray.py

示例2: test_load_nu

# 需要导入模块: from distarray.dist.maps import Distribution [as 别名]
# 或者: from distarray.dist.maps.Distribution import from_dim_data_per_rank [as 别名]
 def test_load_nu(self):
     distribution = Distribution.from_dim_data_per_rank(self.dac,
                                                        nu_test_data)
     da = self.dac.load_npy(self.output_path, distribution)
     for i in range(da.shape[0]):
         for j in range(da.shape[1]):
             self.assertEqual(da[i, j], self.expected[i, j])
开发者ID:MJones810,项目名称:distarray,代码行数:9,代码来源:test_distributed_io.py

示例3: test_load_nu

# 需要导入模块: from distarray.dist.maps import Distribution [as 别名]
# 或者: from distarray.dist.maps.Distribution import from_dim_data_per_rank [as 别名]
 def test_load_nu(self):
     distribution = Distribution.from_dim_data_per_rank(self.context,
                                                        nu_test_data)
     da = self.context.load_hdf5(self.output_path, distribution, key="test")
     assert_array_equal(self.expected, da)
开发者ID:cowlicks,项目名称:distarray,代码行数:7,代码来源:test_distributed_io.py


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