@@ -48,7 +48,7 @@ def _compute_and_update_PI_kernel(
4848 Parameters
4949 ----------
5050 idx : int
51- The index for sliding window `i`
51+ The index for sliding window `j` (in `T_B`)
5252
5353 T_A : numpy.ndarray
5454 The time series or sequence for which to compute the dot product
@@ -148,52 +148,53 @@ def _compute_and_update_PI_kernel(
148148 start = cuda .grid (1 )
149149 stride = cuda .gridsize (1 )
150150
151- i = idx
151+ j = idx
152+ # The name `i` is reserved to be used as an index for `T_A`
152153
153- if i % 2 == 0 :
154+ if j % 2 == 0 :
154155 p_norm_out = p_norm_even
155156 p_norm_in = p_norm_odd
156157 else :
157158 p_norm_out = p_norm_odd
158159 p_norm_in = p_norm_even
159160
160- for j in range (start , p_norm_out .shape [0 ], stride ):
161- zone_start = max (0 , j - excl_zone )
162- zone_stop = min (w , j + excl_zone )
161+ for i in range (start , p_norm_out .shape [0 ], stride ):
162+ zone_start = max (0 , i - excl_zone )
163+ zone_stop = min (w , i + excl_zone )
163164
164165 if compute_p_norm :
165- p_norm_out [j ] = (
166- p_norm_in [j - 1 ]
167- - abs (T_B [i - 1 ] - T_A [j - 1 ]) ** p
168- + abs (T_B [i + m - 1 ] - T_A [j + m - 1 ]) ** p
166+ p_norm_out [i ] = (
167+ p_norm_in [i - 1 ]
168+ - abs (T_A [i - 1 ] - T_B [j - 1 ]) ** p
169+ + abs (T_A [i + m - 1 ] - T_B [j + m - 1 ]) ** p
169170 )
170- p_norm_out [0 ] = p_norm_first [i ]
171- if not T_B_subseq_isfinite [i ] or not T_A_subseq_isfinite [j ]:
171+ p_norm_out [0 ] = p_norm_first [j ]
172+ if not T_B_subseq_isfinite [j ] or not T_A_subseq_isfinite [i ]:
172173 p_norm = np .inf
173174 else :
174- p_norm = p_norm_out [j ]
175+ p_norm = p_norm_out [i ]
175176
176177 if p_norm < config .STUMPY_P_NORM_THRESHOLD :
177178 p_norm = 0
178179
179180 if ignore_trivial :
180- if i <= zone_stop and i >= zone_start :
181+ if j <= zone_stop and j >= zone_start :
181182 p_norm = np .inf
182- if p_norm < profile_L [j ] and i < j :
183- profile_L [j ] = p_norm
184- indices_L [j ] = i
185- if p_norm < profile_R [j ] and i > j :
186- profile_R [j ] = p_norm
187- indices_R [j ] = i
188-
189- if p_norm < profile [j , - 1 ]:
190- idx = core ._gpu_searchsorted_right (profile [j ], p_norm , bfs , nlevel )
183+ if p_norm < profile_L [i ] and j < i :
184+ profile_L [i ] = p_norm
185+ indices_L [i ] = j
186+ if p_norm < profile_R [i ] and j > i :
187+ profile_R [i ] = p_norm
188+ indices_R [i ] = j
189+
190+ if p_norm < profile [i , - 1 ]:
191+ idx = core ._gpu_searchsorted_right (profile [i ], p_norm , bfs , nlevel )
191192 for g in range (k - 1 , idx , - 1 ):
192- profile [j , g ] = profile [j , g - 1 ]
193- indices [j , g ] = indices [j , g - 1 ]
193+ profile [i , g ] = profile [i , g - 1 ]
194+ indices [i , g ] = indices [i , g - 1 ]
194195
195- profile [j , idx ] = p_norm
196- indices [j , idx ] = i
196+ profile [i , idx ] = p_norm
197+ indices [i , idx ] = j
197198
198199
199200def _gpu_aamp (
@@ -439,8 +440,6 @@ def _gpu_aamp(
439440
440441
441442def gpu_aamp (T_A , m , T_B = None , ignore_trivial = True , device_id = 0 , p = 2.0 , k = 1 ):
442- # function needs to be revised to return (top-k) matrix profile and
443- # matrix profile indices
444443 """
445444 Compute the non-normalized (i.e., without z-normalization) matrix profile with
446445 one or more GPU devices
0 commit comments