From 862bd05b1f5b775e1545e984a98b0942d3583f54 Mon Sep 17 00:00:00 2001 From: tosemml <97384583+tosemml@users.noreply.github.com> Date: Tue, 8 Aug 2023 18:24:59 -0700 Subject: [PATCH 1/2] Use np.add --- CLIP-ViP/src/utils/basic_utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CLIP-ViP/src/utils/basic_utils.py b/CLIP-ViP/src/utils/basic_utils.py index 3cd77fd..0c08638 100644 --- a/CLIP-ViP/src/utils/basic_utils.py +++ b/CLIP-ViP/src/utils/basic_utils.py @@ -155,9 +155,7 @@ def dissect_by_lengths(np_array, lengths, dim=0, assert_equal=True): np_array.shape[0] == sum(lengths), Output is a list of nd arrays, singlton dimention is kept""" if assert_equal: assert len(np_array) == sum(lengths) - length_indices = [0, ] - for i in range(len(lengths)): - length_indices.append(length_indices[i] + lengths[i]) + length_indices = [0, ] + np.add(length_indices,lengths).tolist() if dim == 0: array_list = [np_array[length_indices[i]:length_indices[i+1]] for i in range(len(lengths))] elif dim == 1: From 4a70a5c55535e22590a4d2e23a878d09df8f7541 Mon Sep 17 00:00:00 2001 From: tosemml <97384583+tosemml@users.noreply.github.com> Date: Tue, 8 Aug 2023 18:29:07 -0700 Subject: [PATCH 2/2] use np.add --- hd-vila/src/utils/basic_utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hd-vila/src/utils/basic_utils.py b/hd-vila/src/utils/basic_utils.py index 7fab2fc..7679ae0 100644 --- a/hd-vila/src/utils/basic_utils.py +++ b/hd-vila/src/utils/basic_utils.py @@ -155,9 +155,7 @@ def dissect_by_lengths(np_array, lengths, dim=0, assert_equal=True): np_array.shape[0] == sum(lengths), Output is a list of nd arrays, singlton dimention is kept""" if assert_equal: assert len(np_array) == sum(lengths) - length_indices = [0, ] - for i in range(len(lengths)): - length_indices.append(length_indices[i] + lengths[i]) + length_indices = [0, ] + np.add(length_indices,lengths).tolist() if dim == 0: array_list = [np_array[length_indices[i]:length_indices[i+1]] for i in range(len(lengths))] elif dim == 1: