Skip to content

Commit 0e1a308

Browse files
coerce dtype=np.int64 for np.prod calls in subsample (#806)
* coerce dtype=np.int64 for np.prod calls in subsample * fix: tuple is immutable * change arr.shape calls to full_shape as uint64
1 parent bc002d1 commit 0e1a308

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

fastplotlib/utils/functions.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,18 +455,19 @@ def subsample_array(
455455
np.ndarray
456456
subsample of the input array
457457
"""
458-
if np.prod(arr.shape) <= max_size:
458+
full_shape = np.array(arr.shape, dtype=np.uint64)
459+
if np.prod(full_shape) <= max_size:
459460
return arr[:] # no need to subsample if already below the threshold
460461

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

464465
# new shape for subsampled array
465-
ns = np.floor(np.array(arr.shape) / f).clip(min=1)
466+
ns = np.floor(np.array(full_shape) / f).clip(min=1)
466467

467468
# get the step size for the slices
468-
slices = tuple(
469-
slice(None, None, int(s)) for s in np.floor(arr.shape / ns).astype(int)
469+
slices = list(
470+
slice(None, None, int(s)) for s in np.floor(full_shape / ns).astype(int)
470471
)
471472

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

0 commit comments

Comments
 (0)