Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/structuredbroadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,13 @@ fzero(S::StructuredMatrix) = Some(zero(eltype(S)))
fzero(::StructuredMatrix{<:AbstractMatrix{T}}) where {T<:Number} = Some(haszero(T) ? zero(T)*I : nothing)
fzero(x) = nothing
function fzero(bc::Broadcast.Broadcasted)
args = map(fzero, bc.args)
# Type-assert to prevent inference from widening the result type to AbstractArray.
# Broadcasted.args is always <: Tuple by construction, but when the Broadcasted type
# parameter is not fully known (e.g., Broadcasted{StructuredMatrixStyle{T} where T}),
# inference may widen args, causing any(isnothing, args) to create a cached
# MethodInstance any(::typeof(isnothing), ::AbstractArray) that is invalidated by
# any package defining any(f, ::AbstractArraySubtype).
args = map(fzero, bc.args)::Tuple
return any(isnothing, args) ? nothing : Some(bc.f(map(something, args)...))
end

Expand Down