Iβm a bit surprised that in this simple example, f
is type-stable but g
is not. Is this a JET.jl issue (@aviatesk) or a Julia issue?
using JET
function f(m, n)
blocks = map(1:n) do i
ones(m)
end
return reduce(hcat, blocks)
end
function g(m, n)
return mapreduce(hcat, 1:n) do i
ones(m)
end
end
julia> @assert f(10, 20) == g(10, 20)
julia> @test_opt f(10, 20)
Test Passed
julia> @test_opt g(10, 20)
JET-test failed at /home/guillaume/Work/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterfaceTest/test/playground.jl:18
Expression: #= /home/guillaume/Work/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterfaceTest/test/playground.jl:18 =# JET.@test_opt g(10, 20)
βββββ 1 possible error found βββββ
β g(m::Int64, n::Int64) @ Main /home/guillaume/Work/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterfaceTest/test/playground.jl:11
ββ mapreduce(f::var"#23#24"{Int64}, op::typeof(hcat), A::UnitRange{Int64}) @ Base ./reducedim.jl:357
βββ mapreduce(f::var"#23#24"{Int64}, op::typeof(hcat), A::UnitRange{Int64}; dims::Colon, init::Base._InitialValue) @ Base ./reducedim.jl:357
ββββ _mapreduce_dim(f::var"#23#24"{Int64}, op::typeof(hcat), ::Base._InitialValue, A::UnitRange{Int64}, ::Colon) @ Base ./reducedim.jl:365
βββββ _mapreduce(f::var"#23#24"{Int64}, op::typeof(hcat), ::IndexLinear, A::UnitRange{Int64}) @ Base ./reduce.jl:432
ββββββ mapreduce_empty_iter(f::var"#23#24"{Int64}, op::typeof(hcat), itr::UnitRange{Int64}, ItrEltype::Base.HasEltype) @ Base ./reduce.jl:380
βββββββ reduce_empty_iter(op::Base.MappingRF{var"#23#24"{Int64}, typeof(hcat)}, itr::UnitRange{Int64}, ::Base.HasEltype) @ Base ./reduce.jl:384
ββββββββ reduce_empty(op::Base.MappingRF{var"#23#24"{Int64}, typeof(hcat)}, ::Type{Int64}) @ Base ./reduce.jl:361
ββββββββ runtime dispatch detected: Base.mapreduce_empty(%1::var"#23#24"{Int64}, hcat, ::Int64)
ββββββββββββββββββββββββββββ
ERROR: There was an error during testing
@Oscar_Smith and @Mason, sorry for the ping, @hill tells me you may have intuitions about this.