Skip to content

Commit b581b38

Browse files
committed
add new sdp func and its test
1 parent dd98c83 commit b581b38

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

stumpy/sdp.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ def _convolve_sliding_dot_product(Q, T):
5555
return convolve(np.flipud(Q), T, mode="valid")
5656

5757

58+
def _oaconvolve_sliding_dot_product(Q, T):
59+
"""
60+
Use scipy's oaconvolve to calculate the sliding dot product.
61+
62+
Parameters
63+
----------
64+
Q : numpy.ndarray
65+
Query array or subsequence
66+
67+
T : numpy.ndarray
68+
Time series or sequence
69+
70+
Returns
71+
-------
72+
output : numpy.ndarray
73+
Sliding dot product between `Q` and `T`.
74+
"""
75+
return oaconvolve(np.ascontiguousarray(Q[::-1]), T, mode="valid")
76+
77+
5878
def _sliding_dot_product(Q, T):
5979
"""
6080
Compute the sliding dot product between `Q` and `T`

tests/test_sdp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ def test_convolve_sliding_dot_product(Q, T):
2929
npt.assert_almost_equal(ref_mp, comp_mp)
3030

3131

32+
@pytest.mark.parametrize("Q, T", test_data)
33+
def test_oaconvolve_sliding_dot_product(Q, T):
34+
ref_mp = naive.rolling_window_dot_product(Q, T)
35+
comp_mp = sdp._convolve_sliding_dot_product(Q, T)
36+
npt.assert_almost_equal(ref_mp, comp_mp)
37+
38+
3239
@pytest.mark.parametrize("Q, T", test_data)
3340
def test_sliding_dot_product(Q, T):
3441
ref_mp = naive.rolling_window_dot_product(Q, T)

0 commit comments

Comments
 (0)