Skip to content

Commit e88ceda

Browse files
vtjnashnalimilan
authored andcommitted
broadcast: use recursion rather than ntuple to map over a tuple (#51154)
Inference seems to have trouble with the anonymous function version, so go back to the recursive version. Fixes #51129 Probably also fixes #50859 (cherry picked from commit d949bb4)
1 parent 653fd93 commit e88ceda

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

base/broadcast.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,8 @@ _broadcast_getindex_eltype(A) = eltype(A) # Tuple, Array, etc.
750750
eltypes(::Tuple{}) = Tuple{}
751751
eltypes(t::Tuple{Any}) = Iterators.TupleOrBottom(_broadcast_getindex_eltype(t[1]))
752752
eltypes(t::Tuple{Any,Any}) = Iterators.TupleOrBottom(_broadcast_getindex_eltype(t[1]), _broadcast_getindex_eltype(t[2]))
753-
# eltypes(t::Tuple) = (TT = eltypes(tail(t)); TT === Union{} ? Union{} : Iterators.TupleOrBottom(_broadcast_getindex_eltype(t[1]), TT.parameters...))
754-
eltypes(t::Tuple) = Iterators.TupleOrBottom(ntuple(i -> _broadcast_getindex_eltype(t[i]), Val(length(t)))...)
753+
eltypes(t::Tuple) = (TT = eltypes(tail(t)); TT === Union{} ? Union{} : Iterators.TupleOrBottom(_broadcast_getindex_eltype(t[1]), TT.parameters...))
754+
# eltypes(t::Tuple) = Iterators.TupleOrBottom(ntuple(i -> _broadcast_getindex_eltype(t[i]), Val(length(t)))...)
755755

756756
# Inferred eltype of result of broadcast(f, args...)
757757
function combine_eltypes(f, args::Tuple)

test/broadcast.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,3 +1133,6 @@ end
11331133
import Base.Broadcast: BroadcastStyle, DefaultArrayStyle
11341134
@test Base.infer_effects(BroadcastStyle, (DefaultArrayStyle{1},DefaultArrayStyle{2},)) |>
11351135
Core.Compiler.is_foldable
1136+
1137+
f51129(v, x) = (1 .- (v ./ x) .^ 2)
1138+
@test @inferred(f51129([13.0], 6.5)) == [-3.0]

0 commit comments

Comments
 (0)