Skip to content

fix: handle oversized median filter windows - #1797

Open
KuroGeo wants to merge 1 commit into
huggingface:mainfrom
KuroGeo:fix/median-filter-short-input
Open

KuroGeo wants to merge 1 commit into
huggingface:mainfrom
KuroGeo:fix/median-filter-short-input

Conversation

@KuroGeo

@KuroGeo KuroGeo commented Oct 11, 2026

Copy link
Copy Markdown

medianFilter() reflects an out-of-range index only once. When the window is wider than a short input, the reflected index can still be outside the array: singleton floating-point inputs produce NaN, wider windows produce incorrect medians, and BigInt typed arrays throw. Whisper timestamp alignment also uses this helper.

Use periodic reflection to keep every sample index in range, and return a distinct copy for empty or singleton inputs. This preserves the input typed-array constructor, existing window validation, and the in-range fast path.

Added regression coverage for singleton and two-element inputs, oversized windows across floating-point, integer, and BigInt typed arrays, empty inputs, and unit windows.

Validation:

  • Full @huggingface/transformers test suite (pnpm test --runInBand): all 27 suites passed, 2,227 tests passed, 47 skipped. Assertions and timeouts were unchanged; run with Node 24 and NODE_USE_ENV_PROXY=1 to use the configured network proxy.
  • Structured-output package: 20 tests passed.
  • Focused maths suite: 50 tests passed; seven new regression cases fail against the original implementation.
  • Independent reflection reference: 396 input/window/type combinations passed.
  • Root pnpm build passed for both packages, including declaration generation.
  • Changed-file Prettier and git diff --check passed. The root format check reports only the unchanged tensor.test.js and tensor_ops.test.js files.

No JSDoc or generated documentation changes. This patch was prepared with AI assistance; the diff and validation results were reviewed before submission.

This branch has not been deployed

No deployments
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.

1 participant