|
241 | 241 |
|
242 | 242 | # broadcast methods that dispatch on the type found by inference |
243 | 243 | function _broadcast_t(f, ::Type{Any}, shape, iter, As...) |
| 244 | + if isempty(iter) |
| 245 | + return similar(Array{Any}, shape) |
| 246 | + end |
244 | 247 | nargs = length(As) |
245 | 248 | keeps, Idefaults = map_newindexer(shape, As) |
246 | 249 | st = start(iter) |
@@ -272,14 +275,16 @@ ziptype(A, B) = Zip2{Tuple{eltype(A)},Tuple{eltype(B)}} |
272 | 275 |
|
273 | 276 | # broadcast methods that dispatch on the type of the final container |
274 | 277 | @inline function broadcast_c(f, ::Type{Array}, As...) |
275 | | - S = _default_eltype(Generator{ziptype(As...),ftype(f, As...)}) |
| 278 | + T = _default_eltype(Generator{ziptype(As...),ftype(f, As...)}) |
276 | 279 | shape = broadcast_indices(As...) |
277 | 280 | iter = CartesianRange(shape) |
| 281 | + if isleaftype(T) |
| 282 | + return _broadcast_t(f, T, shape, iter, As...) |
| 283 | + end |
278 | 284 | if isempty(iter) |
279 | | - return similar(Array{S}, shape) |
| 285 | + return similar(Array{T}, shape) |
280 | 286 | end |
281 | | - T = isleaftype(S) ? S : Any |
282 | | - return _broadcast_t(f, T, shape, iter, As...) |
| 287 | + return _broadcast_t(f, Any, shape, iter, As...) |
283 | 288 | end |
284 | 289 | function broadcast_c(f, ::Type{Tuple}, As...) |
285 | 290 | shape = broadcast_indices(As...) |
|
0 commit comments