def _resize_nosync(self, *args): # normalize new shape argument old_shape = self._shape new_shape = normalize_resize_args(old_shape, *args) old_cdata_shape = self._cdata_shape # update metadata self._shape = new_shape self._flush_metadata_nosync() # determine the new number and arrangement of chunks chunks = self._chunks new_cdata_shape = tuple( int(np.ceil(s / c)) for s, c in zip(new_shape, chunks)) # remove any chunks not within range for cidx in itertools.product(*[range(n) for n in old_cdata_shape]): if all(i < c for i, c in zip(cidx, new_cdata_shape)): pass # keep the chunk else: key = self._chunk_key(cidx) try: del self._chunk_store[key] except KeyError: # chunk not initialized pass
def _resize_nosync(self, *args): # normalize new shape argument old_shape = self._shape new_shape = normalize_resize_args(old_shape, *args) old_cdata_shape = self._cdata_shape # update metadata self._shape = new_shape self._flush_metadata_nosync() # determine the new number and arrangement of chunks chunks = self._chunks new_cdata_shape = tuple(int(np.ceil(s / c)) for s, c in zip(new_shape, chunks)) # remove any chunks not within range for cidx in itertools.product(*[range(n) for n in old_cdata_shape]): if all(i < c for i, c in zip(cidx, new_cdata_shape)): pass # keep the chunk else: key = self._chunk_key(cidx) try: del self._chunk_store[key] except KeyError: # chunk not initialized pass
def test_normalize_resize_args(): # 1D eq((200, ), normalize_resize_args((100, ), 200)) eq((200, ), normalize_resize_args((100, ), (200, ))) # 2D eq((200, 100), normalize_resize_args((100, 100), (200, 100))) eq((200, 100), normalize_resize_args((100, 100), (200, None))) eq((200, 100), normalize_resize_args((100, 100), 200, 100)) eq((200, 100), normalize_resize_args((100, 100), 200, None)) with assert_raises(ValueError): normalize_resize_args((100, ), (200, 100))
def test_normalize_resize_args(): # 1D assert (200, ) == normalize_resize_args((100, ), 200) assert (200, ) == normalize_resize_args((100, ), (200, )) # 2D assert (200, 100) == normalize_resize_args((100, 100), (200, 100)) assert (200, 100) == normalize_resize_args((100, 100), (200, None)) assert (200, 100) == normalize_resize_args((100, 100), 200, 100) assert (200, 100) == normalize_resize_args((100, 100), 200, None) with pytest.raises(ValueError): normalize_resize_args((100, ), (200, 100))
def test_normalize_resize_args(): # 1D eq((200,), normalize_resize_args((100,), 200)) eq((200,), normalize_resize_args((100,), (200,))) # 2D eq((200, 100), normalize_resize_args((100, 100), (200, 100))) eq((200, 100), normalize_resize_args((100, 100), (200, None))) eq((200, 100), normalize_resize_args((100, 100), 200, 100)) eq((200, 100), normalize_resize_args((100, 100), 200, None)) with assert_raises(ValueError): normalize_resize_args((100,), (200, 100))