Skip to content

Use FillArrays.simplify_broadcasted for Zeros broadcasts - #506

Draft
jishnub wants to merge 1 commit into
masterfrom
jishnub/fillarrays_bcast_v2
Draft

Use FillArrays.simplify_broadcasted for Zeros broadcasts#506
jishnub wants to merge 1 commit into
masterfrom
jishnub/fillarrays_bcast_v2

Conversation

@jishnub

@jishnub jishnub commented Aug 10, 2026

Copy link
Copy Markdown
Member

Depends on JuliaArrays/FillArrays.jl#444 (FillArrays 1.19). CI will not resolve until that is merged and released — the compat bound here is raised to FillArrays = "1.19".

Why

The Zeros rules in generic/broadcast.jl called FillArrays._broadcasted_zeros, an internal imported at the top of BandedMatrices.jl, and duplicated FillArrays' own list of which operations a Zeros absorbs (*, / one way; *, \ the other). If FillArrays gains or changes a rule, this list silently falls out of step.

What changes

FillArrays.simplify_broadcasted(style, op, args...) returns the simplified array where a rule applies, and otherwise a Broadcasted carrying the style we hand it — so anything it cannot simplify comes straight back for BandedStyle to handle as before.

broadcasted(S::BandedStyle, op, a::AbstractZeros, b::AbstractArray) = FillArrays.simplify_broadcasted(S, op, a, b)
broadcasted(S::BandedStyle, op, a::AbstractArray, b::AbstractZeros) = FillArrays.simplify_broadcasted(S, op, a, b)
broadcasted(S::BandedStyle, op, a::AbstractZeros, b::AbstractZeros) = FillArrays.simplify_broadcasted(S, op, a, b)

No operations are enumerated, and _broadcasted_zeros is dropped from the import list.

The Ones rules are deliberately left as they were: they preserve bandedness via _copy_oftype, which is our semantics rather than FillArrays', and routing them through simplify_broadcasted would lose that.

One incidental fix: the Zeros methods keyed on the concrete Zeros, so AbstractZeros subtypes were missed. They now key on AbstractZeros. The third method disambiguates the first two when both arguments are zeros.

Test suite passes against FillArrays#444.

🤖 Generated with Claude Code

The `Zeros` rules called `FillArrays._broadcasted_zeros`, an internal, and
duplicated FillArrays' own list of which operations a `Zeros` absorbs.

`FillArrays.simplify_broadcasted(style, op, args...)` replaces both. It returns the
simplified array where a rule applies, and otherwise a `Broadcasted` carrying the
style we passed in, so anything it cannot simplify comes back to us unchanged. The
methods no longer enumerate operations, and they now key on `AbstractZeros` rather
than the concrete `Zeros`.

The `Ones` rules are left alone: they preserve bandedness via `_copy_oftype`, which
is our semantics rather than FillArrays'.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jishnub
jishnub marked this pull request as draft August 10, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant