當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。