本文整理汇总了Python中distarray.local.localarray.LocalArray.set_localarray方法的典型用法代码示例。如果您正苦于以下问题:Python LocalArray.set_localarray方法的具体用法?Python LocalArray.set_localarray怎么用?Python LocalArray.set_localarray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类distarray.local.localarray.LocalArray
的用法示例。
在下文中一共展示了LocalArray.set_localarray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestInit
# 需要导入模块: from distarray.local.localarray import LocalArray [as 别名]
# 或者: from distarray.local.localarray.LocalArray import set_localarray [as 别名]
class TestInit(MpiTestCase):
"""Is the __init__ method working properly?"""
def setUp(self):
self.dist_1d = Distribution.from_shape(comm=self.comm,
shape=(7,), grid_shape=(4,))
self.larr_1d = LocalArray(self.dist_1d, buf=None)
self.dist_2d = Distribution.from_shape(comm=self.comm,
shape=(16, 16), grid_shape=(4, 1))
self.larr_2d = LocalArray(self.dist_2d, buf=None)
def test_basic_1d(self):
"""Test basic LocalArray creation."""
self.assertEqual(self.larr_1d.global_shape, (7,))
self.assertEqual(self.larr_1d.dist, ('b',))
self.assertEqual(self.larr_1d.grid_shape, (4,))
self.assertEqual(self.larr_1d.comm_size, 4)
self.assertTrue(self.larr_1d.comm_rank in range(4))
self.assertEqual(len(self.larr_1d.distribution), 1)
self.assertEqual(self.larr_1d.global_shape, (7,))
if self.larr_1d.comm_rank == 3:
self.assertEqual(self.larr_1d.local_shape, (1,))
else:
self.assertEqual(self.larr_1d.local_shape, (2,))
self.assertEqual(self.larr_1d.ndarray.shape, self.larr_1d.local_shape)
self.assertEqual(self.larr_1d.ndarray.size, self.larr_1d.local_size)
self.assertEqual(self.larr_1d.local_size, self.larr_1d.local_shape[0])
self.assertEqual(self.larr_1d.ndarray.dtype, self.larr_1d.dtype)
def test_basic_2d(self):
"""Test basic LocalArray creation."""
self.assertEqual(self.larr_2d.global_shape, (16, 16))
self.assertEqual(self.larr_2d.dist, ('b', 'b'))
self.assertEqual(self.larr_2d.grid_shape, (4, 1))
self.assertEqual(self.larr_2d.comm_size, 4)
self.assertTrue(self.larr_2d.comm_rank in range(4))
self.assertEqual(len(self.larr_2d.distribution), 2)
self.assertEqual(self.larr_2d.grid_shape, (4, 1))
self.assertEqual(self.larr_2d.global_shape, (16, 16))
self.assertEqual(self.larr_2d.local_shape, (4, 16))
self.assertEqual(self.larr_2d.local_size,
np.array(self.larr_2d.local_shape).prod())
self.assertEqual(self.larr_2d.ndarray.shape, self.larr_2d.local_shape)
self.assertEqual(self.larr_2d.ndarray.size, self.larr_2d.local_size)
self.assertEqual(self.larr_2d.ndarray.dtype, self.larr_2d.dtype)
def test_localarray(self):
"""Can the ndarray be set and get?"""
self.larr_2d.get_localarray()
la = np.random.random(self.larr_2d.local_shape)
la = np.asarray(la, dtype=self.larr_2d.dtype)
self.larr_2d.set_localarray(la)
self.larr_2d.get_localarray()
def test_bad_localarray(self):
""" Test that setting a bad local array fails as expected. """
self.larr_1d.get_localarray()
local_shape = self.larr_1d.local_shape
# Double dimension sizes to make an invalid shape.
bad_shape = tuple(2 * size for size in local_shape)
la = np.random.random(bad_shape)
la = np.asarray(la, dtype=self.larr_1d.dtype)
with self.assertRaises(ValueError):
self.larr_1d.set_localarray(la)
def test_cart_coords(self):
"""Test getting the cart_coords attribute"""
actual_1d = self.larr_1d.cart_coords
expected_1d = tuple(self.larr_1d.distribution.cart_coords)
self.assertEqual(actual_1d, expected_1d)
actual_2d = self.larr_2d.cart_coords
expected_2d = tuple(self.larr_2d.distribution.cart_coords)
self.assertEqual(actual_2d, expected_2d)