Repository navigation
Let map and broadcast return values of a type without zero - #1055
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1055 +/- ##
=======================================
Coverage 94.77% 94.77%
=======================================
Files 16 16
Lines 9913 9917 +4
=======================================
+ Hits 9395 9399 +4
Misses 518 518 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ViralBShah
enabled auto-merge (squash)
October 13, 2026 05:17
Deciding whether `f` preserves zeros called `_iszero(f(0...))`, which throws a `MethodError` when the value is a `String`, a `Tuple`, a `Pair` or `nothing`. `_iszeroresult` treats such a value as a nonzero, so it fills the result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ViralBShah
force-pushed
the
vs/map-result-without-zero
branch
from
October 13, 2026 05:20
9f40c9a to
aee01a1
Compare
ViralBShah
commented
Oct 13, 2026
ViralBShah
left a comment
Member
Author
There was a problem hiding this comment.
Reviewed by Codex at aee01a1.
No actionable findings within the dispatcher changes. Results without a defined zero now reach the fill path while the existing numeric, array and missing-value checks retain their behavior. The fully stored multi-argument limitation is explicitly identified in the PR.
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.
mapandbroadcastover a sparse array throw aMethodErrorwhen the function returns a value of a type that has nozero, such as aString, aTuple, aPairornothing.Before
After
To choose between the zero-preserving kernel and the one that fills the result, the dispatchers evaluate
fat the zeros and call_iszeroon the value, which callszerofor anything but aNumber. The new_iszeroresultis_iszerofor aNumber, anAbstractArrayorMissing, and for any other value returnsfalsewhen_iszerothrows aMethodError: a value without a zero is not one, and fills the result like any other nonzero. It replaces_iszerowhereverfat the zeros is tested: themap!andbroadcast!dispatchers,_noshapecheck_map, the zero-argumentbroadcast!,_diffshape_broadcastand_preserveszeros, where only the call offstays inside thetry. Thetryis reached only for a non-Numberresult, so the result types ofmap(sin, A)andA .+ Bare inferred as before.Left out: a broadcast of two or more arguments where one of them stores every entry, such as
string.(A, sparse(ones(2, 2))), still throwsMethodError: no method matching zero(::String). That path tests each computed entry for zero, and a tolerant check there would cost every eltype that is not aNumber.Split from #1022.
Written by Claude Code.
🤖 Generated with Claude Code