Skip to content

Commit 1ddb950

Browse files
Fixed #769 Improved code consistency for T_A and T_B (#889)
* fix name and order of variables in stump * fix stumped accordingly * Revert changing oof variables' name * minor fixes * minor change to increase consistency in docstring * change order of arguments in gpu_stump * minor fixes * partially fixed name of variables * swap the variables' names i and j * fix format * Remove an outdated comment * reorder terms * swap i and j for better readability * Remove outdated comment
1 parent 286cb17 commit 1ddb950

File tree

8 files changed

+154
-156
lines changed

8 files changed

+154
-156
lines changed

stumpy/aamp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ def _aamp(
331331

332332

333333
def aamp(T_A, m, T_B=None, ignore_trivial=True, p=2.0, k=1):
334-
# function needs to be changed to return top-k matrix profile
335334
"""
336335
Compute the non-normalized (i.e., without z-normalization) matrix profile
337336

stumpy/aamped.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ def _dask_aamped(
159159

160160

161161
def aamped(client, T_A, m, T_B=None, ignore_trivial=True, p=2.0, k=1):
162-
# function needs to be revised to return top-k matrix profile
163162
"""
164163
Compute the non-normalized (i.e., without z-normalization) matrix profile
165164

stumpy/gpu_aamp.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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

199200
def _gpu_aamp(
@@ -439,8 +440,6 @@ def _gpu_aamp(
439440

440441

441442
def 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

Comments
 (0)