From 59268c5fc71e147dc3bb53cf5d3238d2484e1bcc Mon Sep 17 00:00:00 2001 From: Guillaume Viejo Date: Thu, 4 Apr 2024 17:20:47 -0400 Subject: [PATCH] Fixing jitfix_iset --- pynapple/core/utils.py | 8 ++++---- tests/test_interval_set.py | 14 +++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pynapple/core/utils.py b/pynapple/core/utils.py index f7f75122..f2d8c376 100644 --- a/pynapple/core/utils.py +++ b/pynapple/core/utils.py @@ -2,7 +2,7 @@ # @Author: Guillaume Viejo # @Date: 2024-02-09 11:45:45 # @Last Modified by: Guillaume Viejo -# @Last Modified time: 2024-04-01 16:56:47 +# @Last Modified time: 2024-04-04 17:04:38 """ Utility functions @@ -265,11 +265,8 @@ def _jitfix_iset(start, end): Description """ to_warn = np.zeros(4, dtype=np.bool_) - m = start.shape[0] - data = np.zeros((m, 2), dtype=np.float64) - i = 0 ct = 0 @@ -295,6 +292,9 @@ def _jitfix_iset(start, end): newend = end[i] break + if i >= m: + break + while i < m - 1: if start[i + 1] < end[i]: to_warn[2] = True diff --git a/tests/test_interval_set.py b/tests/test_interval_set.py index c8667f64..9ca0aaaf 100644 --- a/tests/test_interval_set.py +++ b/tests/test_interval_set.py @@ -3,7 +3,7 @@ # @Author: gviejo # @Date: 2022-03-30 11:15:02 # @Last Modified by: Guillaume Viejo -# @Last Modified time: 2024-03-29 11:04:32 +# @Last Modified time: 2024-04-04 17:18:10 """Tests for IntervalSet of `pynapple` package.""" @@ -412,6 +412,18 @@ def test_jitfix_iset_error3(): nap.IntervalSet(start=start, end=end) assert str(w[0].message) == "Some epochs have no duration" +def test_jitfix_iset_random(): + for i in range(10): + np.random.seed(42) + start = np.sort(np.random.uniform(0, 1000, 100)) + end = np.sort(np.random.uniform(0, 1000, 100)) + + ep, to_warn = nap.core.utils._jitfix_iset(start, end) + + if len(ep): + assert np.all(ep[:,1] - ep[:,0] > 0) + assert np.all(np.diff(ep.flatten())>0) + def test_raise_warning(): start = np.around(np.array([0, 15, 16], dtype=np.float64), 9) end = np.around(np.array([5, 15, 20], dtype=np.float64), 9)