From 39e01d3b0b2ed1195eab66cda03c7d39bda706cb Mon Sep 17 00:00:00 2001 From: Flynn OConnell Date: Fri, 25 Apr 2025 16:33:02 -0400 Subject: [PATCH 1/3] coerce dtype=np.int64 for np.prod calls in subsample --- fastplotlib/utils/functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastplotlib/utils/functions.py b/fastplotlib/utils/functions.py index d6d996a4..c9fc33f1 100644 --- a/fastplotlib/utils/functions.py +++ b/fastplotlib/utils/functions.py @@ -455,11 +455,11 @@ def subsample_array( np.ndarray subsample of the input array """ - if np.prod(arr.shape) <= max_size: + if np.prod(arr.shape, dtype=np.int64) <= 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(arr.shape, dtype=np.int64) / max_size), 1.0 / arr.ndim) # new shape for subsampled array ns = np.floor(np.array(arr.shape) / f).clip(min=1) From d1bb278784d2bfb280715e3fbc9a74d8c7a4948a Mon Sep 17 00:00:00 2001 From: Flynn OConnell Date: Sun, 27 Apr 2025 18:03:12 -0400 Subject: [PATCH 2/3] fix: tuple is immutable --- fastplotlib/utils/functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastplotlib/utils/functions.py b/fastplotlib/utils/functions.py index c9fc33f1..e141bc43 100644 --- a/fastplotlib/utils/functions.py +++ b/fastplotlib/utils/functions.py @@ -465,7 +465,7 @@ def subsample_array( ns = np.floor(np.array(arr.shape) / f).clip(min=1) # get the step size for the slices - slices = tuple( + slices = list( slice(None, None, int(s)) for s in np.floor(arr.shape / ns).astype(int) ) From 3a2012da288d030385ffbc642a7d00ce2f92da3f Mon Sep 17 00:00:00 2001 From: Flynn OConnell Date: Mon, 19 May 2025 21:11:57 -0400 Subject: [PATCH 3/3] change arr.shape calls to full_shape as uint64 --- fastplotlib/utils/functions.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fastplotlib/utils/functions.py b/fastplotlib/utils/functions.py index e141bc43..45678aa5 100644 --- a/fastplotlib/utils/functions.py +++ b/fastplotlib/utils/functions.py @@ -455,18 +455,19 @@ def subsample_array( np.ndarray subsample of the input array """ - if np.prod(arr.shape, dtype=np.int64) <= 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, dtype=np.int64) / 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 = list( - slice(None, None, int(s)) for s in np.floor(arr.shape / ns).astype(int) + 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