Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
grain.experimental.WindowShuffleMapDatasetsilently corrupts data whenlen(parent)is not a multiple ofwindow_size: the short final window of each epoch is permuted over a full-size window, so an index can land past the epoch end and wrap into an earlier window. Elements are lost and duplicated.The sibling
WindowShuffleIterDatasetpermutes with the actual window length and is unaffected, so the documented Map/Iter equivalence forreverse=Falsewas also violated.Root cause
_shuffled_index()used global window boundaries andmax_index=self._window_size - 1even for a shorter final window.Fix
Align windows within each epoch, clamp the permutation domain to the actual window length, and offset the result by the epoch. The seed is unchanged for all epoch-aligned windows, so behavior is bit-identical when
len(parent)is divisible bywindow_size.Verification
shuffle_test.py: 49/49 pass.slice_repeat_shuffle_test.py: 9/9 pass._getitemsconsistency, negative and NumPy indices.py_compileand whitespace checks clean.Not verified: Bazel/CI, other platforms, and free-threaded Python. Pre-existing negative-index equivalence behavior was not changed.
AI-assisted development. Human review requested before merge.