1212from numba import cuda , njit , prange
1313from scipy import linalg
1414from scipy .ndimage import maximum_filter1d , minimum_filter1d
15- from scipy .signal import convolve
1615from scipy .spatial .distance import cdist
1716
18- from . import config
17+ from . import config , sdp
1918
2019try :
2120 from numba .cuda .cudadrv .driver import _raise_driver_not_found
@@ -649,36 +648,9 @@ def check_window_size(m, max_size=None, n=None):
649648 warnings .warn (msg )
650649
651650
652- @njit (fastmath = config .STUMPY_FASTMATH_TRUE )
653- def _sliding_dot_product (Q , T ):
654- """
655- A Numba JIT-compiled implementation of the sliding window dot product.
656-
657- Parameters
658- ----------
659- Q : numpy.ndarray
660- Query array or subsequence
661-
662- T : numpy.ndarray
663- Time series or sequence
664-
665- Returns
666- -------
667- out : numpy.ndarray
668- Sliding dot product between `Q` and `T`.
669- """
670- m = Q .shape [0 ]
671- l = T .shape [0 ] - m + 1
672- out = np .empty (l )
673- for i in range (l ):
674- out [i ] = np .dot (Q , T [i : i + m ])
675-
676- return out
677-
678-
679651def sliding_dot_product (Q , T ):
680652 """
681- Use FFT convolution to calculate the sliding window dot product.
653+ Calculate the sliding window dot product.
682654
683655 Parameters
684656 ----------
@@ -692,27 +664,8 @@ def sliding_dot_product(Q, T):
692664 -------
693665 output : numpy.ndarray
694666 Sliding dot product between `Q` and `T`.
695-
696- Notes
697- -----
698- Calculate the sliding dot product
699-
700- `DOI: 10.1109/ICDM.2016.0179 \
701- <https://www.cs.ucr.edu/~eamonn/PID4481997_extend_Matrix%20Profile_I.pdf>`__
702-
703- See Table I, Figure 4
704-
705- Following the inverse FFT, Fig. 4 states that only cells [m-1:n]
706- contain valid dot products
707-
708- Padding is done automatically in fftconvolve step
709667 """
710- n = T .shape [0 ]
711- m = Q .shape [0 ]
712- Qr = np .flipud (Q ) # Reverse/flip Q
713- QT = convolve (Qr , T )
714-
715- return QT .real [m - 1 : n ]
668+ return sdp ._sliding_dot_product (Q , T )
716669
717670
718671@njit (
@@ -1327,7 +1280,7 @@ def _p_norm_distance_profile(Q, T, p=2.0):
13271280 T_squared [i ] = (
13281281 T_squared [i - 1 ] - T [i - 1 ] * T [i - 1 ] + T [i + m - 1 ] * T [i + m - 1 ]
13291282 )
1330- QT = _sliding_dot_product (Q , T )
1283+ QT = sdp . _njit_sliding_dot_product (Q , T )
13311284 for i in range (l ):
13321285 p_norm_profile [i ] = Q_squared + T_squared [i ] - 2.0 * QT [i ]
13331286 else :
@@ -1900,7 +1853,7 @@ def _mass_distance_matrix(
19001853 if np .any (~ np .isfinite (Q [i : i + m ])): # pragma: no cover
19011854 distance_matrix [i , :] = np .inf
19021855 else :
1903- QT = _sliding_dot_product (Q [i : i + m ], T )
1856+ QT = sdp . _njit_sliding_dot_product (Q [i : i + m ], T )
19041857 distance_matrix [i , :] = _mass (
19051858 Q [i : i + m ],
19061859 T ,
0 commit comments