Skip to content

Fixed #1243: aampdist_snippets dropping the final window when len(T) % m == 0 - #1249

Open
jseiden12 wants to merge 1 commit into
stumpy-dev:mainfrom
jseiden12:fix-aampdist-snippets-1243
Open

jseiden12 wants to merge 1 commit into
stumpy-dev:mainfrom
jseiden12:fix-aampdist-snippets-1243

Conversation

@jseiden12

Copy link
Copy Markdown

Fixes #1243.

With normalize=False, aampdist_snippets never evaluated the last window whenever the series length divided evenly by the subsequence length. For len(T) = 8, m = 4 it only ever looked at the window starting at index 0, never the one at index 4, and returned [0 0].

The window count came from (n_padded // m) - 1. The - 1 was meant to exclude the extra partial window that padding adds when the length does not divide evenly, but it subtracts one in both cases, so an exact fit loses a real window.

This counts the full windows from the unpadded length instead (n_contiguous_windows = len(T) // m) and derives the candidate start indices from the profile matrix, which is the same approach #894 used for the identical bug in stumpy/snippets.py. The naive reference in tests/naive.py had the same off-by-one and is fixed the same way, and there is a new regression test in tests/test_aampdist_snippets.py.

One thing I noticed while testing: the issue's example expects [4 0], but that is the normalized path's ranking. After this fix the AAMP path returns [0 4]. Both windows are now selected, which is the bug here; the order differs because AAMP ranks by non-normalized distances. The regression test asserts the selected set rather than the order.

Tests: the new regression test fails on main (D.shape[0] is 1, expected 2) and passes with this change. pytest tests/test_aampdist_snippets.py 76 passed, tests/test_snippets.py 147 passed, black and flake8 clean.

@jseiden12
jseiden12 requested a review from seanlaw as a code owner December 4, 2026 18:18
@gitnotebooks

gitnotebooks Bot commented Dec 4, 2026

Copy link
Copy Markdown

Review these changes at https://app.gitnotebooks.com/stumpy-dev/stumpy/pull/1249

@NimaSarajpoor NimaSarajpoor changed the title Fix aampdist_snippets dropping the final window when len(T) % m == 0 Fixed #1243: aampdist_snippets dropping the final window when len(T) % m == 0 Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aampdist_snippets drops the final non-overlapping window when len(T) % m == 0

1 participant