Skip to content

Commit 3919b53

Browse files
committed
revise sliding dot product functions
1 parent 33ca9dd commit 3919b53

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

stumpy/core.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def check_window_size(m, max_size=None, n=None):
652652
@njit(fastmath=config.STUMPY_FASTMATH_TRUE)
653653
def _sliding_dot_product(Q, T):
654654
"""
655-
A Numba JIT-compiled implementation of the sliding window dot product.
655+
A Numba JIT-compiled implementation of the sliding dot product.
656656
657657
Parameters
658658
----------
@@ -667,18 +667,21 @@ def _sliding_dot_product(Q, T):
667667
out : numpy.ndarray
668668
Sliding dot product between `Q` and `T`.
669669
"""
670-
m = Q.shape[0]
670+
m = len(Q)
671671
l = T.shape[0] - m + 1
672672
out = np.empty(l)
673673
for i in range(l):
674-
out[i] = np.dot(Q, T[i : i + m])
674+
result = 0.0
675+
for j in range(m):
676+
result += Q[j] * T[i + j]
677+
out[i] = result
675678

676679
return out
677680

678681

679682
def sliding_dot_product(Q, T):
680683
"""
681-
Use FFT convolution to calculate the sliding window dot product.
684+
Use FFT or direct convolution to calculate the sliding dot product.
682685
683686
Parameters
684687
----------
@@ -701,18 +704,11 @@ def sliding_dot_product(Q, T):
701704
<https://www.cs.ucr.edu/~eamonn/PID4481997_extend_Matrix%20Profile_I.pdf>`__
702705
703706
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
709707
"""
710-
n = T.shape[0]
711-
m = Q.shape[0]
712-
Qr = np.flipud(Q) # Reverse/flip Q
713-
QT = convolve(Qr, T)
708+
# mode='valid' returns output of convolution where the two
709+
# sequences fully overlap.
714710

715-
return QT.real[m - 1 : n]
711+
return convolve(np.flipud(Q), T, mode="valid")
716712

717713

718714
@njit(

0 commit comments

Comments
 (0)