Skip to content

Commit 3c70d47

Browse files
committed
Moved functions to sdp module
1 parent 74aed07 commit 3c70d47

File tree

2 files changed

+73
-27
lines changed

2 files changed

+73
-27
lines changed

stumpy/core.py

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
from numba import cuda, njit, prange
1313
from scipy import linalg
1414
from scipy.ndimage import maximum_filter1d, minimum_filter1d
15-
from scipy.signal import convolve
1615
from scipy.spatial.distance import cdist
1716

18-
from . import config
17+
from . import config, sdp
1918

2019
try:
2120
from numba.cuda.cudadrv.driver import _raise_driver_not_found
@@ -652,7 +651,8 @@ def check_window_size(m, max_size=None, n=None):
652651
@njit(fastmath=config.STUMPY_FASTMATH_TRUE)
653652
def _sliding_dot_product(Q, T):
654653
"""
655-
A Numba JIT-compiled implementation of the sliding dot product.
654+
A wrapper for numba JIT-compiled implementation of
655+
the sliding dot product.
656656
657657
Parameters
658658
----------
@@ -667,21 +667,12 @@ def _sliding_dot_product(Q, T):
667667
out : numpy.ndarray
668668
Sliding dot product between `Q` and `T`.
669669
"""
670-
m = len(Q)
671-
l = T.shape[0] - m + 1
672-
out = np.empty(l)
673-
for i in range(l):
674-
result = 0.0
675-
for j in range(m):
676-
result += Q[j] * T[i + j]
677-
out[i] = result
678-
679-
return out
670+
return sdp._njit_sliding_dot_product(Q, T)
680671

681672

682673
def sliding_dot_product(Q, T):
683674
"""
684-
Use FFT or direct convolution to calculate the sliding dot product.
675+
A wrapper for convolution implementation of the sliding dot product.
685676
686677
Parameters
687678
----------
@@ -695,20 +686,8 @@ def sliding_dot_product(Q, T):
695686
-------
696687
output : numpy.ndarray
697688
Sliding dot product between `Q` and `T`.
698-
699-
Notes
700-
-----
701-
Calculate the sliding dot product
702-
703-
`DOI: 10.1109/ICDM.2016.0179 \
704-
<https://www.cs.ucr.edu/~eamonn/PID4481997_extend_Matrix%20Profile_I.pdf>`__
705-
706-
See Table I, Figure 4
707689
"""
708-
# mode='valid' returns output of convolution where the two
709-
# sequences fully overlap.
710-
711-
return convolve(np.flipud(Q), T, mode="valid")
690+
return sdp._convolve_sliding_dot_product(Q, T)
712691

713692

714693
@njit(

stumpy/sdp.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import numpy as np
2+
from numba import njit
3+
from scipy.signal import convolve
4+
5+
from . import config
6+
7+
8+
@njit(fastmath=config.STUMPY_FASTMATH_TRUE)
9+
def _njit_sliding_dot_product(Q, T):
10+
"""
11+
A Numba JIT-compiled implementation of the sliding dot product.
12+
13+
Parameters
14+
----------
15+
Q : numpy.ndarray
16+
Query array or subsequence
17+
18+
T : numpy.ndarray
19+
Time series or sequence
20+
21+
Returns
22+
-------
23+
out : numpy.ndarray
24+
Sliding dot product between `Q` and `T`.
25+
"""
26+
m = len(Q)
27+
l = T.shape[0] - m + 1
28+
out = np.empty(l)
29+
for i in range(l):
30+
result = 0.0
31+
for j in range(m):
32+
result += Q[j] * T[i + j]
33+
out[i] = result
34+
35+
return out
36+
37+
38+
def _convolve_sliding_dot_product(Q, T):
39+
"""
40+
Use FFT or direct convolution to calculate the sliding dot product.
41+
42+
Parameters
43+
----------
44+
Q : numpy.ndarray
45+
Query array or subsequence
46+
47+
T : numpy.ndarray
48+
Time series or sequence
49+
50+
Returns
51+
-------
52+
output : numpy.ndarray
53+
Sliding dot product between `Q` and `T`.
54+
55+
Notes
56+
-----
57+
Calculate the sliding dot product
58+
59+
`DOI: 10.1109/ICDM.2016.0179 \
60+
<https://www.cs.ucr.edu/~eamonn/PID4481997_extend_Matrix%20Profile_I.pdf>`__
61+
62+
See Table I, Figure 4
63+
"""
64+
# mode='valid' returns output of convolution where the two
65+
# sequences fully overlap.
66+
67+
return convolve(np.flipud(Q), T, mode="valid")

0 commit comments

Comments
 (0)