|
127 | 127 | end
|
128 | 128 |
|
129 | 129 | Base.@propagate_inbounds _broadcast_getindex(A, I) = _broadcast_getindex(containertype(A), A, I)
|
| 130 | +Base.@propagate_inbounds _broadcast_getindex(::Type{Tuple}, A::Tuple{Any}, I) = A[1] |
130 | 131 | Base.@propagate_inbounds _broadcast_getindex(::Type{Array}, A::Ref, I) = A[]
|
131 | 132 | Base.@propagate_inbounds _broadcast_getindex(::ScalarType, A, I) = A
|
132 | 133 | Base.@propagate_inbounds _broadcast_getindex(::Any, A, I) = A[I]
|
@@ -333,13 +334,25 @@ end
|
333 | 334 | end
|
334 | 335 | @inline broadcast_c(f, ::Type{Any}, a...) = f(a...)
|
335 | 336 | @inline broadcast_c(f, ::Type{Tuple}, A, Bs...) =
|
336 |
| - tuplebroadcast(f, first_tuple(A, Bs...), A, Bs...) |
| 337 | + tuplebroadcast(f, tuplebroadcast_length(A, Bs...), A, Bs...) |
337 | 338 | @inline tuplebroadcast(f, ::NTuple{N,Any}, As...) where {N} =
|
338 | 339 | ntuple(k -> f(tuplebroadcast_getargs(As, k)...), Val(N))
|
339 | 340 | @inline tuplebroadcast(f, ::NTuple{N,Any}, ::Type{T}, As...) where {N,T} =
|
340 | 341 | ntuple(k -> f(T, tuplebroadcast_getargs(As, k)...), Val(N))
|
341 |
| -first_tuple(A::Tuple, Bs...) = A |
342 |
| -@inline first_tuple(A, Bs...) = first_tuple(Bs...) |
| 342 | +tuplebroadcast_length(A, B) = (nothing,) |
| 343 | +tuplebroadcast_length(A, ::Tuple{}) = () |
| 344 | +tuplebroadcast_length(::Tuple{}, A) = () |
| 345 | +tuplebroadcast_length(::Tuple, ::Tuple{}) = () |
| 346 | +tuplebroadcast_length(::Tuple{}, ::Tuple) = () |
| 347 | +tuplebroadcast_length(::Tuple{Any}, ::Tuple{}) = () |
| 348 | +tuplebroadcast_length(::Tuple{}, ::Tuple{Any}) = () |
| 349 | +tuplebroadcast_length(A::Tuple, ::Tuple{Any}) = A |
| 350 | +tuplebroadcast_length(::Tuple{Any}, A::Tuple) = A |
| 351 | +tuplebroadcast_length(A::NTuple{N,Any}, ::NTuple{N,Any}...) where {N} = A |
| 352 | +tuplebroadcast_length(::Tuple, ::Tuple) = |
| 353 | + throw(DimensionMismatch("tuples could not be broadcast to a common size")) |
| 354 | +@inline tuplebroadcast_length(A, Bs...) = |
| 355 | + tuplebroadcast_length(A, tuplebroadcast_length(Bs...)) |
343 | 356 | tuplebroadcast_getargs(::Tuple{}, k) = ()
|
344 | 357 | @inline tuplebroadcast_getargs(As, k) =
|
345 | 358 | (_broadcast_getindex(first(As), k), tuplebroadcast_getargs(tail(As), k)...)
|
|
0 commit comments