Skip to content

Commit

Permalink
Fixing jitfix_iset
Browse files Browse the repository at this point in the history
  • Loading branch information
gviejo committed Apr 4, 2024
1 parent f29e0cf commit 59268c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pynapple/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
14 changes: 13 additions & 1 deletion tests/test_interval_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 59268c5

Please sign in to comment.