Closed
Description
Hello, I believe the new 1.7 feature .&&
is not currently type stable. It looks like the new .||
is OK, however.
x = randn(2)
y = randn(2)
function dotandand(x,y)
(x .> 0.0) .&& (y .> 0.0)
end
Then checking the type gives:
@code_warntype dotandand(x,y)
MethodInstance for dotandand(::Vector{Float64}, ::Vector{Float64})
from dotandand(x, y) in Main at REPL[3]:1
Arguments
#self#::Core.Const(dotandand)
x::Vector{Float64}
y::Vector{Float64}
Body::Any
1 ─ %1 = Base.broadcasted(Main.:>, x, 0.0)::Core.PartialStruct(Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, typeof(>), Tuple{Vector{Float64}, Float64}}, Any[Core.Const(>), Core.PartialStruct(Tuple{Vector{Float64}, Float64}, Any[Vector{Float64}, Core.Const(0.0)]), Core.Const(nothing)])
│ %2 = Base.broadcasted(Main.:>, y, 0.0)::Core.PartialStruct(Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, typeof(>), Tuple{Vector{Float64}, Float64}}, Any[Core.Const(>), Core.PartialStruct(Tuple{Vector{Float64}, Float64}, Any[Vector{Float64}, Core.Const(0.0)]), Core.Const(nothing)])
│ %3 = Base.broadcasted(Base.andand, %1, %2)::Any
│ %4 = Base.materialize(%3)::Any
└── return %4
@code_warntype results are fine for the similar functions defined below using .& .| .|| instead of .&&
I assume this is also causing the drop in performance:
function dotand(x,y)
(x .> 0.0) .& (y .> 0.0)
end
function dotoror(x,y)
(x .> 0.0) .|| (y .> 0.0)
end
function dotor(x,y)
(x .> 0.0) .| (y .> 0.0)
end
@btime dotandand(x,y);
105.074 ns (5 allocations: 224 bytes)
@btime dotand(x,y);
60.316 ns (2 allocations: 96 bytes)
@btime dotoror(x,y);
60.199 ns (2 allocations: 96 bytes)
@btime dotor(x,y);
59.820 ns (2 allocations: 96 bytes)