本文整理匯總了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
示例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])
示例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)