Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove final explicit uses of Inference.return_type #330

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,10 @@ end
end
end

eltype_exprs = [t <: AbstractArray ? :($(eltype(t))) : :($t) for t ∈ a]
newtype_expr = :(Core.Inference.return_type(f, Tuple{$(eltype_exprs...)}))

return quote
@_inline_meta
@inbounds return similar_type($first_staticarray, $newtype_expr, Size($newsize))(tuple($(exprs...)))
elements = tuple($(exprs...))
@inbounds return similar_type($first_staticarray, promote_tuple_eltype(elements), Size($newsize))(elements)
end
end

Expand Down
10 changes: 4 additions & 6 deletions src/mapreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ end
tmp = [:(a[$j][$i]) for j ∈ 1:length(a)]
exprs[i] = :(f($(tmp...)))
end
eltypes = [eltype(a[j]) for j ∈ 1:length(a)] # presumably, `eltype` is "hyperpure"?
newT = :(Core.Inference.return_type(f, Tuple{$(eltypes...)}))
return quote
@_inline_meta
@inbounds return similar_type(typeof(_first(a...)), $newT, Size(S))(tuple($(exprs...)))
elements = tuple($(exprs...))
@inbounds return similar_type(typeof(_first(a...)), promote_tuple_eltype(elements), Size(S))(elements)
end
end

Expand Down Expand Up @@ -110,8 +109,6 @@ end
@generated function _mapreducedim(f, op, ::Size{S}, a::StaticArray, ::Type{Val{D}}) where {S,D}
N = length(S)
Snew = ([n==D ? 1 : S[n] for n = 1:N]...)
T0 = eltype(a)
T = :((T1 = Core.Inference.return_type(f, Tuple{$T0}); Core.Inference.return_type(op, Tuple{T1,T1})))

exprs = Array{Expr}(Snew)
itr = [1:n for n ∈ Snew]
Expand All @@ -128,7 +125,8 @@ end

return quote
@_inline_meta
@inbounds return similar_type(a, $T, Size($Snew))(tuple($(exprs...)))
elements = tuple($(exprs...))
@inbounds return similar_type(a, promote_tuple_eltype(elements), Size($Snew))(elements)
end
end

Expand Down
8 changes: 4 additions & 4 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ end
@test_broken eltype(a / 2) == Real
end
let a = SVector{3, Real}(2, 2.0, 4//2)
@test_broken eltype(a + 2.0) == Float64
@test_broken eltype(a - 2.0) == Float64
@test_broken eltype(a * 2.0) == Float64
@test_broken eltype(a / 2.0) == Float64
@test eltype(a + 2.0) == Float64
@test eltype(a - 2.0) == Float64
@test eltype(a * 2.0) == Float64
@test eltype(a / 2.0) == Float64
end
let a = broadcast(Float32, SVector(3, 4, 5))
@test eltype(a) == Float32
Expand Down