Add simplify_broadcasted as the supported downstream entry point - #444
Open
jishnub wants to merge 1 commit into
Open
Add simplify_broadcasted as the supported downstream entry point#444jishnub wants to merge 1 commit into
simplify_broadcasted as the supported downstream entry point#444jishnub wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## jishnub/broadcaststyle #444 +/- ##
==========================================================
+ Coverage 93.60% 93.63% +0.03%
==========================================================
Files 9 9
Lines 1298 1305 +7
==========================================================
+ Hits 1215 1222 +7
Misses 83 83 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jishnub
force-pushed
the
jishnub/broadcaststyle-v2
branch
3 times, most recently
from
August 10, 2026 15:51
9235e05 to
25f3e9f
Compare
This was referenced Aug 10, 2026
jishnub
force-pushed
the
jishnub/broadcaststyle-v2
branch
from
August 10, 2026 18:20
25f3e9f to
8a50f77
Compare
Packages with a `BroadcastStyle` of their own currently reach the fill rules by
forwarding through `broadcast(DefaultArrayStyle{N}(), op, args...)`. That protocol
is undocumented and leaks implementation details: it names a style unrelated to
fills, it makes the caller enumerate the argument shapes that happen to have rules,
and it requires knowing that `x .^ k` lowers to a three-argument `literal_pow` with
`Ref`s.
`simplify_broadcasted(style, op, args...)` replaces it. It returns the simplified
array where a rule applies, and otherwise a `Broadcasted` carrying the caller's own
style, so anything unsimplified stays lazy. The dimension comes from the arguments
rather than the style, so an `AbstractArrayStyle{Any}` caller works too.
The resolution order is unchanged, and for the same reason as before: the
`Zeros`-absorbing rules are styleless and would otherwise be preempted by the more
specific `FillStyle` range rules. The `DefaultArrayStyle` shims now delegate here,
leaving one implementation rather than two, and a 3592-probe sweep of that path is
byte-identical to before.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
jishnub
force-pushed
the
jishnub/broadcaststyle-v2
branch
from
August 12, 2026 15:38
8a50f77 to
5e01e70
Compare
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.
Stacked on #385 — review that first; this PR's diff is the single commit on top.
The problem
A package with a
BroadcastStyleof its own currently reaches the fill rules by forwarding throughbroadcast(DefaultArrayStyle{N}(), op, args...). That protocol is undocumented and leaks implementation details three ways:x .^ klowers to a three-argumentBase.literal_powwithRefarguments, and that our rule takes them unwrapped. Both LazyArrays and InfiniteArrays carry near-duplicate methods for this alone.Packages also call internals directly:
_broadcasted_zeros(BlockArrays, BandedMatrices),mult_zeros(ArrayLayouts, LazyArrays, QuasiArrays),elconvert,_range_convert,steprangelen.The change
Returns the simplified array where a rule applies, and otherwise a
Broadcastedcarrying the caller's own style — so anything we cannot simplify comes back for the caller to keep lazy, infinite, or on-device.Ref-wrappedliteral_powarguments are unwrapped, so callers never mention it.This is the existing
_dispatch_on_fillswith two changes: the fallback style is parameterized instead of hard-coded toDefaultArrayStyle{N}, and theRef-unwrapping folds in. The dimension now comes from the arguments rather than the style, so anAbstractArrayStyle{Any}caller works too.Resolution order is unchanged, and for the same reason as before: the
Zeros-absorbing rules are styleless and would otherwise be preempted by the more specificFillStylerange rules.has_fill_rule→ styleless rulebroadcasted(FillStyle{N}(), …)→ fill-style ruleisfill→ evaluate on the fill valuesBroadcasted{typeof(style)}The
DefaultArrayStyleshims now delegate here, leaving one implementation rather than two. They are kept for packages that predate this.Verification
broadcasted(DefaultArrayStyle{N}(), op, args...)is byte-identical before and after, so unmigrated packages are unaffected.Downstream, against this branch: LazyArrays 35 broadcast methods → 14, InfiniteArrays' 4 redundant
literal_powmethods → 0, BlockArrays and BandedMatrices 4 → 3 each with_broadcasted_zerosdropped. All four suites pass, and a 16-probe old-vs-new diff against their real checkouts shows no behavioural change.Versioning
This is a minor release (1.19.0):
simplify_broadcastedis new, theDefaultArrayStyleshims are untouched in behaviour, and the 3592-probe sweep over them is byte-identical. Every
published downstream keeps resolving — LazyArrays and InfiniteArrays pin
FillArrays = "1.0",BlockArrays
"1.11", BandedMatrices"1.3", and all of those admit 1.19. Packages opt into thenew entry point by raising their lower bound to
"1.19"when they are ready; nothing is forced.Deleting the
DefaultArrayStyleshims (src/fillbroadcast.jl:245-254) is the eventual endpoint ofthis migration and is genuinely breaking. That is deliberately left for a future major release,
once downstream packages have moved over.
🤖 Generated with Claude Code