Skip to content

Commit

Permalink
perf(dust): multiply operation was more expensive than assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Nov 26, 2024
1 parent 160f877 commit 66be8de
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions cc3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,16 @@ def dust(
mask_sizes = stats["voxel_counts"]
del stats

if invert:
to_retain = [
i for i in range(1, N+1) if mask_sizes[i] < threshold
]
else:
to_retain = [
i for i in range(1, N+1) if mask_sizes[i] >= threshold
]
to_mask = [
i for i in range(1, N+1) if mask_sizes[i] < threshold
]

if len(to_retain) == N:
if len(to_mask) == 0:
return img

mask = np.isin(cc_labels, to_retain, assume_unique=True)
mask = np.isin(cc_labels, to_mask, assume_unique=True, invert=False)
del cc_labels
img *= mask
img[mask] = 0
return img.view(orig_dtype)

def largest_k(
Expand Down

0 comments on commit 66be8de

Please sign in to comment.