Skip to content

Commit b16e346

Browse files
committed
Fix empty case.
1 parent 7358701 commit b16e346

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/broadcast.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,17 @@ first_statictype() = error("unresolved dest type")
108108

109109
@inline function _broadcast(f, sz::Size{newsize}, s::Tuple{Vararg{Size}}, a...) where newsize
110110
first_staticarray = first_statictype(a...)
111+
if prod(newsize) == 0
112+
# Use inference to get eltype in empty case (see also comments in _map)
113+
eltys = Tuple{map(eltype, a)...}
114+
T = Core.Compiler.return_type(f, eltys)
115+
@inbounds return similar_type(first_staticarray, T, Size(newsize))()
116+
end
111117
elements = __broadcast(f, sz, s, a...)
112118
@inbounds return similar_type(first_staticarray, eltype(elements), Size(newsize))(elements)
113119
end
114120

115121
@generated function __broadcast(f, ::Size{newsize}, s::Tuple{Vararg{Size}}, a...) where newsize
116-
if prod(newsize) == 0
117-
# Use inference to get eltype in empty case (see also comments in _map)
118-
eltys = [:(eltype(a[$i])) for i 1:length(a)]
119-
return quote
120-
@_inline_meta
121-
T = Core.Compiler.return_type(f, Tuple{$(eltys...)})
122-
@inbounds return similar_type($first_staticarray, T, Size(newsize))()
123-
end
124-
end
125-
126122
sizes = [sz.parameters[1] for sz s.parameters]
127123
indices = CartesianIndices(newsize)
128124
exprs = similar(indices, Expr)

0 commit comments

Comments
 (0)