From e749317aade661cb747b2595bd7ed17b91646698 Mon Sep 17 00:00:00 2001 From: Anna Grim <108307071+anna-grim@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:01:29 -0800 Subject: [PATCH] Update util.py --- src/deep_neurographs/utils/util.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/deep_neurographs/utils/util.py b/src/deep_neurographs/utils/util.py index 6530c6b..28fb3e7 100644 --- a/src/deep_neurographs/utils/util.py +++ b/src/deep_neurographs/utils/util.py @@ -682,16 +682,15 @@ def get_memory_available(): return psutil.virtual_memory().available / 1e9 -def spaced_idxs(container, k): +def spaced_idxs(arr_length, k): """ Generates an array of indices based on a specified step size and ensures the last index is included. Parameters: ---------- - container : iterable - An iterable (e.g., list, array) from which the length is determined. - The length of this container dictates the range of generated indices. + arr_length : int + Length of array to be sampled from. k : int Step size for generating indices. @@ -703,7 +702,7 @@ def spaced_idxs(container, k): "container" is guaranteed to be included in the output. """ - idxs = np.arange(0, len(container) + k, k)[:-1] - if len(container) % 2 == 0: - idxs = np.append(idxs, len(container) - 1) + idxs = np.arange(0, arr_length + k, k)[:-1] + if arr_length % 1 == 0: + idxs = np.append(idxs, arr_length - 1) return idxs