Skip to content

Commit cbfecb7

Browse files
committed
refactor naive function
1 parent 2837609 commit cbfecb7

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

tests/naive.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,3 +2379,11 @@ def mpdist_custom_func(P_ABBA, m, percentage, n_A, n_B):
23792379
MPdist = P_ABBA[k]
23802380

23812381
return MPdist
2382+
2383+
2384+
def rolling_window_dot_product(Q, T):
2385+
window = len(Q)
2386+
result = np.zeros(len(T) - window + 1)
2387+
for i in range(len(result)):
2388+
result[i] = np.dot(T[i : i + window], Q)
2389+
return result

tests/test_core.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ def _gpu_searchsorted_kernel(a, v, bfs, nlevel, is_left, idx):
3535
TEST_THREADS_PER_BLOCK = 10
3636

3737

38-
def naive_rolling_window_dot_product(Q, T):
39-
window = len(Q)
40-
result = np.zeros(len(T) - window + 1)
41-
for i in range(len(result)):
42-
result[i] = np.dot(T[i : i + window], Q)
43-
return result
44-
45-
4638
def naive_compute_mean_std_multidimensional(T, m):
4739
n = T.shape[1]
4840
nrows, ncols = T.shape
@@ -210,7 +202,7 @@ def test_check_window_size_excl_zone():
210202

211203
@pytest.mark.parametrize("Q, T", test_data)
212204
def test_sliding_dot_product(Q, T):
213-
ref_mp = naive_rolling_window_dot_product(Q, T)
205+
ref_mp = naive.rolling_window_dot_product(Q, T)
214206
comp_mp = core.sliding_dot_product(Q, T)
215207
npt.assert_almost_equal(ref_mp, comp_mp)
216208

tests/test_sdp.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1+
import naive
12
import numpy as np
23
import pytest
34
from numpy import testing as npt
45

56
from stumpy import sdp
67

7-
8-
def naive_rolling_window_dot_product(Q, T):
9-
window = len(Q)
10-
result = np.zeros(len(T) - window + 1)
11-
for i in range(len(result)):
12-
result[i] = np.dot(T[i : i + window], Q)
13-
return result
14-
15-
168
test_data = [
179
(np.array([-1, 1, 2], dtype=np.float64), np.array(range(5), dtype=np.float64)),
1810
(
@@ -25,20 +17,20 @@ def naive_rolling_window_dot_product(Q, T):
2517

2618
@pytest.mark.parametrize("Q, T", test_data)
2719
def test_njit_sliding_dot_product(Q, T):
28-
ref_mp = naive_rolling_window_dot_product(Q, T)
20+
ref_mp = naive.rolling_window_dot_product(Q, T)
2921
comp_mp = sdp._njit_sliding_dot_product(Q, T)
3022
npt.assert_almost_equal(ref_mp, comp_mp)
3123

3224

3325
@pytest.mark.parametrize("Q, T", test_data)
3426
def test_convolve_sliding_dot_product(Q, T):
35-
ref_mp = naive_rolling_window_dot_product(Q, T)
27+
ref_mp = naive.rolling_window_dot_product(Q, T)
3628
comp_mp = sdp._convolve_sliding_dot_product(Q, T)
3729
npt.assert_almost_equal(ref_mp, comp_mp)
3830

3931

4032
@pytest.mark.parametrize("Q, T", test_data)
4133
def test_sliding_dot_product(Q, T):
42-
ref_mp = naive_rolling_window_dot_product(Q, T)
34+
ref_mp = naive.rolling_window_dot_product(Q, T)
4335
comp_mp = sdp._sliding_dot_product(Q, T)
4436
npt.assert_almost_equal(ref_mp, comp_mp)

0 commit comments

Comments
 (0)