Repository navigation
fix: propagate NaN in axis/arg reductions and Maximum/Minimum like numpy - #7
Merged
Merged
Conversation
Max/Min were already NaN-propagating, but the rest of the family was not: - MaxAxis/MinAxis used `v > dst`, so a NaN after the first element was skipped and a leading NaN stuck: max over [9, NaN, 3] gave 9 (numpy: NaN). - ArgMax/ArgMin and their axis forms ignored NaN the same way: argmax of [inf, NaN] gave 0 (numpy: 1, the index of the first NaN). - Maximum/Minimum used math.Max/math.Min, which special-case +-Inf ahead of NaN: maximum(NaN, +Inf) gave +Inf (numpy: NaN). Found by a differential sweep against numpy 2.5.3 (2640 random cases with NaN/Inf/signed zeros, strided and transposed views). The expectations in nan_test.go are numpy values. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Max/Minalready propagate NaN (numpy.max semantics); the rest of the family did not.MaxAxis(0)over column[9, NaN, 3]-style inputArgMax([+Inf, NaN])ArgMinAxiswith a NaN after the first elementMaximum(NaN, +Inf)/Minimum(NaN, -Inf)Causes:
v > dstcomparisons inMaxAxis/MinAxis/Arg*skip a NaN that is not first and keep one that is;math.Max/math.Minreturn the infinity before checking for NaN. The kernels now use the builtinmax/min(NaN-propagating, asMaxalready does) and the arg kernels return the index of the first NaN.Found with a differential sweep against numpy 2.5.3 (2640 random cases including NaN/Inf/signed zeros and strided/transposed views; the harness is not committed).
nan_test.goholds numpy's values for one fixture; each of the four kernel changes was reverted in turn and the test failed each time.🤖 Generated with Claude Code