Skip to content

Suggesting a minor enhancement in mpdist.py:: _mpdist_vect #1082

Description

@NimaSarajpoor

I think we can replace

https://github.com/TDAmeritrade/stumpy/blob/423c679fdfcdd547744d2b9a2aed7565124fd6e1/stumpy/mpdist.py#L100-L106

with

P_ABBA = np.empty(2 * j, dtype=np.float64) 
  
 if k is None: 
     percentage = np.clip(percentage, 0.0, 1.0) 
     k = math.ceil(percentage * (2 * Q.shape[0]))    # BECAUSE `P_ABBA.shape[0] == 2 * j`, see the first line 
  
 k = min(int(k), P_ABBA.shape[0] - 1) 

Activity

  1. seanlaw commented on Apr 20, 2025

    @seanlaw
    Contributor

    Gotcha. I think that is reasonable. We'll need to adjust aampdist as well.

  2. deleted a comment from 03musab on Apr 11, 2026
  3. DMZ22 commented on Jul 24, 2026

    @DMZ22
    Contributor

    Opened #1158 with this, including the aampdist counterpart you mentioned. Since P_ABBA = np.empty(2 * j), the following k = min(int(k), P_ABBA.shape[0] - 1) already applies the same 2 * j - 1 bound, so the inner min is redundant. Verified it's behaviour-preserving over 20,000 randomised (n, m, percentage) combinations (including out-of-range percentages so the clip path is hit) — identical k every time — and test_mpdist.py/test_aampdist.py pass (82 tests).

  4. added a commit that references this issue on Jul 24, 2026
    c9bc2b0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions