Skip to content

Commit

Permalink
Turned _chunk_faces into a generator to avoid keeping lists of chunk …
Browse files Browse the repository at this point in the history
…faces in memory
  • Loading branch information
m-albert committed Oct 19, 2023
1 parent 43efb6a commit 19dac60
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions dask_image/ndmeasure/_utils/_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,18 @@ def _chunk_faces(chunks, shape, structure, wrap_axes=None):
- (0, 1) wrap over the 0th and 1st axis.
- (0, 1, 3) wrap over 0th, 1st and 3rd axis.
Returns
Yields
-------
faces : list of tuple of slices
Each element in this list indexes a face between two chunks.
tuple of slices
Each element indexes a face between two chunks.
Examples
--------
>>> import dask.array as da
>>> import scipy.ndimage as ndi
>>> a = da.arange(110, chunks=110).reshape((10, 11)).rechunk(5)
>>> structure = ndi.generate_binary_structure(2, 1)
>>> chunk_faces(a.chunks, a.shape, structure)
>>> list(chunk_faces(a.chunks, a.shape, structure))
[(slice(4, 6, None), slice(0, 5, None)),
(slice(4, 6, None), slice(5, 10, None)),
(slice(4, 6, None), slice(10, 11, None)),
Expand All @@ -224,8 +224,6 @@ def _chunk_faces(chunks, shape, structure, wrap_axes=None):
block_summary = np.arange(len(slices)).reshape(
[len(c) for c in chunks])

faces = []

# Iterate over all blocks and use the structuring element
# to determine which blocks should be connected.
# For wrappped axes, we need to consider the block
Expand Down Expand Up @@ -271,9 +269,7 @@ def _chunk_faces(chunks, shape, structure, wrap_axes=None):
slices[ind_curr_block][dim].stop - 1,
slices[ind_curr_block][dim].stop + 1))

faces.append(tuple(curr_slice))

return faces
yield tuple(curr_slice)


def block_ndi_label_delayed(block, structure):
Expand Down

0 comments on commit 19dac60

Please sign in to comment.