Skip to content
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
72 changes: 36 additions & 36 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,6 @@ def naive_rolling_window_dot_product(Q, T):
return result


def test_check_dtype_float32():
assert core.check_dtype(np.random.rand(10).astype(np.float32))


def test_check_dtype_float64():
assert core.check_dtype(np.random.rand(10))


def test_get_max_window_size():
for n in range(3, 10):
ref_max_m = (
int(
n
- math.floor(
(n + (config.STUMPY_EXCL_ZONE_DENOM - 1))
// (config.STUMPY_EXCL_ZONE_DENOM + 1)
)
)
- 1
)
cmp_max_m = core.get_max_window_size(n)
assert ref_max_m == cmp_max_m


def test_check_window_size():
for m in range(-1, 3):
with pytest.raises(ValueError):
core.check_window_size(m)


def test_check_max_window_size():
for m in range(4, 7):
with pytest.raises(ValueError):
core.check_window_size(m, max_size=3)


def naive_compute_mean_std(T, m):
n = T.shape[0]

Expand Down Expand Up @@ -103,6 +67,42 @@ def naive_compute_mean_std_multidimensional(T, m):
]


def test_check_dtype_float32():
assert core.check_dtype(np.random.rand(10).astype(np.float32))


def test_check_dtype_float64():
assert core.check_dtype(np.random.rand(10))


def test_get_max_window_size():
for n in range(3, 10):
ref_max_m = (
int(
n
- math.floor(
(n + (config.STUMPY_EXCL_ZONE_DENOM - 1))
// (config.STUMPY_EXCL_ZONE_DENOM + 1)
)
)
- 1
)
cmp_max_m = core.get_max_window_size(n)
assert ref_max_m == cmp_max_m


def test_check_window_size():
for m in range(-1, 3):
with pytest.raises(ValueError):
core.check_window_size(m)


def test_check_max_window_size():
for m in range(4, 7):
with pytest.raises(ValueError):
core.check_window_size(m, max_size=3)


@pytest.mark.parametrize("Q, T", test_data)
def test_sliding_dot_product(Q, T):
ref_mp = naive_rolling_window_dot_product(Q, T)
Expand Down
25 changes: 13 additions & 12 deletions tests/test_motifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@

import naive

test_data = [
(
np.array([0.0, 1.0, 0.0]),
np.array([0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, 0.0, -0.5]),
),
(
np.array([0.0, 1.0, 2.0]),
np.array([0.1, 1.0, 2.0, 3.0, -1.0, 0.1, 1.0, 2.0, -0.5]),
),
(np.random.uniform(-1000, 1000, [8]), np.random.uniform(-1000, 1000, [64])),
]


def naive_match(Q, T, excl_zone, max_distance):
m = Q.shape[0]
Expand All @@ -41,6 +29,19 @@ def naive_match(Q, T, excl_zone, max_distance):
return np.array(result, dtype=object)


test_data = [
(
np.array([0.0, 1.0, 0.0]),
np.array([0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, 0.0, -0.5]),
),
(
np.array([0.0, 1.0, 2.0]),
np.array([0.1, 1.0, 2.0, 3.0, -1.0, 0.1, 1.0, 2.0, -0.5]),
),
(np.random.uniform(-1000, 1000, [8]), np.random.uniform(-1000, 1000, [64])),
]


def test_motifs_one_motif():
# The top motif for m=3 is a [0 1 0] at indices 0, 5 and 9
T = np.array([0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, 0.0, -0.5, 2.0, 3.0, 2.0])
Expand Down
35 changes: 18 additions & 17 deletions tests/test_scraamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@
import naive


test_data = [
(
np.array([9, 8100, -60, 7], dtype=np.float64),
np.array([584, -11, 23, 79, 1001, 0, -19], dtype=np.float64),
),
(
np.random.uniform(-1000, 1000, [8]).astype(np.float64),
np.random.uniform(-1000, 1000, [64]).astype(np.float64),
),
]

window_size = [8, 16, 32]
substitution_locations = [(slice(0, 0), 0, -1, slice(1, 3), [0, 3])]
substitution_values = [np.nan, np.inf]
percentages = [(0.01, 0.1, 1.0)]


def naive_prescraamp(T_A, m, T_B, s, exclusion_zone=None):
distance_matrix = naive.aamp_distance_matrix(T_A, T_B, m)

Expand Down Expand Up @@ -126,6 +109,24 @@ def naive_scraamp(T_A, m, T_B, percentage, exclusion_zone, pre_scraamp, s):
return out


test_data = [
(
np.array([9, 8100, -60, 7], dtype=np.float64),
np.array([584, -11, 23, 79, 1001, 0, -19], dtype=np.float64),
),
(
np.random.uniform(-1000, 1000, [8]).astype(np.float64),
np.random.uniform(-1000, 1000, [64]).astype(np.float64),
),
]


window_size = [8, 16, 32]
substitution_locations = [(slice(0, 0), 0, -1, slice(1, 3), [0, 3])]
substitution_values = [np.nan, np.inf]
percentages = [(0.01, 0.1, 1.0)]


@pytest.mark.parametrize("T_A, T_B", test_data)
def test_prescraamp_self_join(T_A, T_B):
m = 3
Expand Down
32 changes: 16 additions & 16 deletions tests/test_stimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@
import naive


def naive_bsf_indices(n):
a = np.arange(n)
nodes = [a.tolist()]
out = []

while nodes:
tmp = []
for node in nodes:
for n in split(node, out):
if n:
tmp.append(n)
nodes = tmp

return np.array(out)


T = [
np.array([584, -11, 23, 79, 1001, 0, -19], dtype=np.float64),
np.random.uniform(-1000, 1000, [64]).astype(np.float64),
Expand All @@ -29,22 +45,6 @@ def split(node, out):
return node[:mid], node[mid + 1 :]


def naive_bsf_indices(n):
a = np.arange(n)
nodes = [a.tolist()]
out = []

while nodes:
tmp = []
for node in nodes:
for n in split(node, out):
if n:
tmp.append(n)
nodes = tmp

return np.array(out)


@pytest.mark.parametrize("n", n)
def test_bsf_indices(n):
ref_bsf_indices = naive_bsf_indices(n)
Expand Down