def test_from_global_dim_data_bc(self): """ Test creation of a block-cyclic array. """ rows, cols = 5, 9 global_dim_data = ( # dim 0 { 'dist_type': 'c', 'proc_grid_size': 2, 'size': rows, 'block_size': 2, }, # dim 1 { 'dist_type': 'c', 'proc_grid_size': 2, 'size': cols, 'block_size': 2, }, ) distribution = Distribution.from_global_dim_data( self.context, global_dim_data) distarr = DistArray(distribution, dtype=int) distarr.toarray() las = distarr.get_localarrays() local_shapes = [la.local_shape for la in las] self.assertSequenceEqual(local_shapes, [(3, 5), (3, 4), (2, 5), (2, 4)])
def test___init__(self): shape = (5, 5) distribution = Distribution(self.context, shape, ('b', 'c')) da = DistArray(distribution, dtype=int) da.fill(42) nda = numpy.empty(shape, dtype=int) nda.fill(42) assert_array_equal(da.tondarray(), nda)
def test_from_global_dim_data_irregular_block(self): bounds = (0, 2, 3, 4, 10) glb_dim_data = ({'dist_type': 'b', 'bounds': bounds}, ) distribution = Distribution.from_global_dim_data( self.context, glb_dim_data) distarr = DistArray(distribution, dtype=int) distarr.toarray()
def test_irregular_block_assignment(self): global_dim_data = ({ 'dist_type': 'b', 'bounds': (0, 5), }, { 'dist_type': 'b', 'bounds': (0, 2, 6, 7, 9), }) distribution = Distribution.from_global_dim_data( self.context, global_dim_data) distarr = DistArray(distribution, dtype=int) distarr.toarray()
def test_from_global_dim_data_1d(self): total_size = 40 list_of_indices = [ [29, 38, 18, 19, 11, 33, 10, 1, 22, 25], [5, 15, 34, 12, 16, 24, 23, 39, 6, 36], [0, 7, 27, 4, 32, 37, 21, 26, 9, 17], [35, 14, 20, 13, 3, 30, 2, 8, 28, 31], ] glb_dim_data = ({ 'dist_type': 'u', 'indices': list_of_indices, }, ) distribution = Distribution.from_global_dim_data( self.context, glb_dim_data) distarr = DistArray(distribution, dtype=int) for i in range(total_size): distarr[i] = i localarrays = distarr.get_localarrays() for i, arr in enumerate(localarrays): assert_allclose(arr, list_of_indices[i])
def test_from_global_dim_data_uu(self): rows = 6 cols = 20 row_ixs = numpy.random.permutation(range(rows)) col_ixs = numpy.random.permutation(range(cols)) row_indices = [row_ixs[:rows // 2], row_ixs[rows // 2:]] col_indices = [col_ixs[:cols // 4], col_ixs[cols // 4:]] glb_dim_data = ( { 'dist_type': 'u', 'indices': row_indices }, { 'dist_type': 'u', 'indices': col_indices }, ) distribution = Distribution.from_global_dim_data( self.context, glb_dim_data) distarr = DistArray(distribution, dtype=int) distarr.toarray()
def test_from_global_dim_data_bu(self): rows = 9 row_break_point = rows // 2 cols = 10 col_indices = numpy.random.permutation(range(cols)) col_break_point = len(col_indices) // 3 indices = [ col_indices[:col_break_point], col_indices[col_break_point:] ] glb_dim_data = ( { 'dist_type': 'b', 'bounds': (0, row_break_point, rows) }, { 'dist_type': 'u', 'indices': indices }, ) distribution = Distribution.from_global_dim_data( self.context, glb_dim_data) distarr = DistArray(distribution, dtype=int) distarr.toarray()