def _arbitrary_reshape(self, arr: BlockArray, shape, block_shape) -> BlockArray: # This is the worst-case scenario. # Generate index mappings per block, and group source indices to minimize # RPCs and generation of new objects. system = arr.system dst_arr = BlockArray.empty(shape=shape, block_shape=block_shape, dtype=arr.dtype, system=system) for dst_grid_entry in dst_arr.grid.get_entry_iterator(): dst_block: Block = dst_arr.blocks[dst_grid_entry] dst_slice_selection = dst_arr.grid.get_slice(dst_grid_entry) dst_index_list = array_utils.slice_sel_to_index_list(dst_slice_selection) src_index_list = array_utils.translate_index_list(dst_index_list, shape, arr.shape) src_blocks = self._group_index_lists_by_block( dst_arr.grid.get_slice_tuples(dst_grid_entry), arr.grid, dst_index_list, src_index_list ) for src_grid_entry in src_blocks: src_block: Block = arr.blocks[src_grid_entry] index_pairs = src_blocks[src_grid_entry] syskwargs = {"grid_entry": dst_grid_entry, "grid_shape": dst_arr.grid.grid_shape} dst_block.oid = system.update_block_by_index(dst_block.oid, src_block.oid, index_pairs, syskwargs=syskwargs) return dst_arr
def _reshape_by_entry(app_inst, arr: BlockArray, shape, block_shape) -> BlockArray: dst_arr = app_inst.empty(shape=shape, block_shape=block_shape, dtype=arr.dtype) for dst_grid_entry in dst_arr.grid.get_entry_iterator(): dst_slice_selection = dst_arr.grid.get_slice(dst_grid_entry) dst_index_list = array_utils.slice_sel_to_index_list(dst_slice_selection) src_index_list = array_utils.translate_index_list(dst_index_list, shape, arr.shape) for i in range(len(dst_index_list)): dst_index = dst_index_list[i] src_index = src_index_list[i] dst_arr[dst_index] = arr[src_index] return dst_arr