Repository navigation
fix: spread RingBuffer.Resample repeats evenly and document nearest-neighbour [patch] - #113
Merged
Merged
Conversation
…eighbour [patch] Resample mapped the ends onto each other and rounded with Math.Round's default banker's rounding, so ties all went to the even index and some samples appeared three times while their neighbours appeared once (5 to 9 gave [0,0,1,2,2,2,3,4,4]). Each slot now takes the element under its centre, floor((i + 0.5) * oldCount / length), computed in exact long arithmetic so there are no floating-point ties and no overflow for large buffers. The XML doc now describes the nearest-neighbour selection instead of promising linear interpolation, and the test that claimed 10, 15, 20, 25, 30 asserts the full output. Fixes #88 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dzcato9evJfMk7iLBAHZpo
|
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.



Fixes #88
What changed
RingBuffer<T>.Resampleused to map the first and last slots onto the first and last elements and round withMath.Round, which defaults to banker's rounding. Every.5tie went to the even index, so some samples were repeated three times while their neighbours appeared once. For example, 5 → 9 gave[0,0,1,2,2,2,3,4,4].floor((i + 0.5) * oldCount / length), as the triage comment recommended. It is computed as((2L * i) + 1) * oldCount / (2L * length). The arithmetic is exact, so there are no floating-point ties, and the product stays below 2^63 for anyintinputs, so the overflow fix from RingBuffer.Resample throws IndexOutOfRangeException and loses the buffer's contents for ~46k+ elements (int overflow) #73/Stop RingBuffer.Resample's index mapping overflowing for large buffers #76 still holds. The result is always< oldCount, so the old clamp is gone.1, 4, 7).Tcan't support.Tests
ResampleWithSpecificValues_CorrectlyInterpolateshad a comment claiming10, 15, 20, 25, 30, which was wrong. It now asserts the full output,[10, 10, 20, 30, 30].Resample_PicksTheNearestSampleToEachSlotsCentreasserts the full output for 5→9, 2→3, 3→12 and 9→3.Resample_Upsampling_RepeatsEverySampleEvenlycovers every ratio from 1..12 → up to 40. For each one it checks how many times each sample repeats and that the endpoints are kept.All five new cases fail on
mainand pass with the fix. The full suite passes locally (475/475), including the large-bufferResampletests.🤖 Generated with Claude Code
https://claude.ai/code/session_01Dzcato9evJfMk7iLBAHZpo
Generated by Claude Code