Repository navigation
fix: drop NaN again in median for float types - #45
Conversation
|
/opencode review |
|
The working tree is already checked out at the PR commit ( Review: fix: drop NaN again in median for float typesVerification performed
Findings
VerdictApprove. The change is a minimal, correct restoration of upstream behavior, the new loop is sound, and it comes with regression tests covering single NaN, multiple NaN, all-NaN, |
|
@wtn I have updated the workflows, so could you please rebase your branch onto main? |
The refactor that moved median into a macro template replaced the loop
that trims trailing NaN from the sorted buffer,
for (; n; n--) {
if (!isnan(buf[n - 1])) break;
}
with a loop over a local index whose result was not used. The element
count kept including the NaN values, so the median was taken from the
wrong position: DFloat[3, NaN, 1, 2].median returned 2.5, and
DFloat[NaN, 1].median returned NaN.
Restore the original loop in both the ignan and prnan iterators.
Co-authored-by: Claude Mythos 5.2 <noreply@anthropic.com>
yoshoku
left a comment
There was a problem hiding this comment.
Thank you for your contribution.
Since 8f16066,
medianonDFloatandSFloatcounts NaN values. The sort moves NaN to the end of the buffer, and the loop that followed it used to shrinknpast them. The macro template loops over a localiand leavesnunchanged, so the median is read from a buffer that still includes the NaN values.nnow excludes the trailing NaN values.median(nan: true)runs a second iterator,iter_*_median_prnan, which has the same loop and gets the same fix.Numo::DFloat[1, 2, Float::NAN].median(nan: true)returns1.5with this change and2.0without it.