Skip to content

Commit

Permalink
Fix empty case.
Browse files Browse the repository at this point in the history
  • Loading branch information
N5N3 committed Feb 22, 2022
1 parent 7358701 commit b16e346
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,17 @@ first_statictype() = error("unresolved dest type")

@inline function _broadcast(f, sz::Size{newsize}, s::Tuple{Vararg{Size}}, a...) where newsize
first_staticarray = first_statictype(a...)
if prod(newsize) == 0
# Use inference to get eltype in empty case (see also comments in _map)
eltys = Tuple{map(eltype, a)...}
T = Core.Compiler.return_type(f, eltys)
@inbounds return similar_type(first_staticarray, T, Size(newsize))()
end
elements = __broadcast(f, sz, s, a...)
@inbounds return similar_type(first_staticarray, eltype(elements), Size(newsize))(elements)
end

@generated function __broadcast(f, ::Size{newsize}, s::Tuple{Vararg{Size}}, a...) where newsize
if prod(newsize) == 0
# Use inference to get eltype in empty case (see also comments in _map)
eltys = [:(eltype(a[$i])) for i 1:length(a)]
return quote
@_inline_meta
T = Core.Compiler.return_type(f, Tuple{$(eltys...)})
@inbounds return similar_type($first_staticarray, T, Size(newsize))()
end
end

sizes = [sz.parameters[1] for sz s.parameters]
indices = CartesianIndices(newsize)
exprs = similar(indices, Expr)
Expand Down

0 comments on commit b16e346

Please sign in to comment.