From d3447ce88a5165183817ec0eb8816558fad495a4 Mon Sep 17 00:00:00 2001 From: DMZ22 Date: Fri, 24 Jul 2026 12:52:23 +0530 Subject: [PATCH] Drop redundant k clamp in _mpdist_vect and _aampdist_vect P_ABBA is allocated as np.empty(2 * j), so P_ABBA.shape[0] - 1 is 2 * j - 1. The k = min(int(k), P_ABBA.shape[0] - 1) that follows therefore already applies the same upper bound that the min(..., 2 * j - 1) inside the k is None branch does, making the inner clamp redundant. Remove it in both mpdist and aampdist, as suggested in the issue. Closes #1082. --- stumpy/aampdist.py | 2 +- stumpy/mpdist.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stumpy/aampdist.py b/stumpy/aampdist.py index 9a99d4f3f..e5c3f9e78 100644 --- a/stumpy/aampdist.py +++ b/stumpy/aampdist.py @@ -72,7 +72,7 @@ def _aampdist_vect( if k is None: percentage = np.clip(percentage, 0.0, 1.0) - k = min(math.ceil(percentage * (2 * Q.shape[0])), 2 * j - 1) + k = math.ceil(percentage * (2 * Q.shape[0])) k = min(int(k), P_ABBA.shape[0] - 1) diff --git a/stumpy/mpdist.py b/stumpy/mpdist.py index 489caa9f3..6b0d0e3d9 100644 --- a/stumpy/mpdist.py +++ b/stumpy/mpdist.py @@ -101,7 +101,7 @@ def _mpdist_vect( if k is None: percentage = np.clip(percentage, 0.0, 1.0) - k = min(math.ceil(percentage * (2 * Q.shape[0])), 2 * j - 1) + k = math.ceil(percentage * (2 * Q.shape[0])) k = min(int(k), P_ABBA.shape[0] - 1)