Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing jitfix_iset #261

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading