Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions fastplotlib/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,18 +455,19 @@ def subsample_array(
np.ndarray
subsample of the input array
"""
if np.prod(arr.shape) <= max_size:
full_shape = np.array(arr.shape, dtype=np.uint64)
if np.prod(full_shape) <= max_size:
return arr[:] # no need to subsample if already below the threshold

# get factor by which to divide all dims
f = np.power((np.prod(arr.shape) / max_size), 1.0 / arr.ndim)
f = np.power((np.prod(full_shape) / max_size), 1.0 / arr.ndim)

# new shape for subsampled array
ns = np.floor(np.array(arr.shape) / f).clip(min=1)
ns = np.floor(np.array(full_shape) / f).clip(min=1)

# get the step size for the slices
slices = tuple(
slice(None, None, int(s)) for s in np.floor(arr.shape / ns).astype(int)
slices = list(
slice(None, None, int(s)) for s in np.floor(full_shape / ns).astype(int)
)

# ignore dims e.g. RGB, which we don't want to downsample
Expand Down
Loading