-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Description
The second function below suffers from lots of type instabilities, while the first one is fine. Is that expected?
julia> function f(y, mu)
ll = 0.0
for i in eachindex(y, mu)
ll += 1.0
end
ll
end
f (generic function with 1 method)
julia> function f(y, mu, wts)
ll = 0.0
for i in eachindex(y, mu, wts)
ll += 1.0
end
ll
end
f (generic function with 2 methods)
julia> @code_warntype f(1:3, 1:3, 1:3)
Variables:
y::UnitRange{Int64}
mu::UnitRange{Int64}
wts::UnitRange{Int64}
ll::Float64
#s1::Any
i::Any
##B#6980::Tuple{UnitRange{Int64},UnitRange{Int64}}
####B#6977#6981::Tuple{UnitRange{Int64},UnitRange{Int64}}
####B#6978#6982::Tuple{UnitRange{Int64},UnitRange{Int64}}
######xs#6976#6979#6983::Tuple{}
Body:
begin # none, line 2:
ll = 0.0 # none, line 3: # abstractarray.jl, line 413: # abstractarray.jl, line 414: # abstractarray.jl, line 116: # abstractarray.jl, line 110: # abstractarray.jl, line 113: # abstractarray.jl, line 115: # abstractarray.jl, line 110: # abstractarray.jl, line 113: # abstractarray.jl, line 110: # abstractarray.jl, line 113: # abstractarray.jl, line 117: # abstractarray.jl, line 117: # abstractarray.jl, line 417: # range.jl, line 339: # int.jl, line 475: # number.jl, line 51: # essentials.jl, line 61: # int.jl, line 474: # tuple.jl, line 61: # tuple.jl, line 8: # tuple.jl, line 8:
GenSym(3) = (Base.length)(mu::UnitRange{Int64})::Any
GenSym(2) = (Base.length)(wts::UnitRange{Int64})::Any # operators.jl, line 103:
GenSym(4) = (Base.max)((Base.max)((Base.box)(Int64,(Base.checked_sadd)((Base.box)(Int64,(Base.checked_ssub)((top(getfield))(y::UnitRange{Int64},:stop)::Int64,(top(getfield))(y::UnitRange{Int64},:start)::Int64)),1)),GenSym(3))::Any,GenSym(2))::Any # operators.jl, line 82:
GenSym(0) = (Base.colon)(1,GenSym(4))::Any
#s1 = (top(start))(GenSym(0))::Any
unless (top(!))((top(done))(GenSym(0),#s1)::Any)::Any goto 1
2:
GenSym(1) = (top(next))(GenSym(0),#s1)::Any
i = (top(getfield))(GenSym(1),1)::Any
#s1 = (top(getfield))(GenSym(1),2)::Any # none, line 4: # float.jl, line 204:
ll = (Base.box)(Base.Float64,(Base.add_float)(ll::Float64,1.0))
3:
unless (top(!))((top(!))((top(done))(GenSym(0),#s1)::Any)::Any)::Any goto 2
1:
0: # none, line 6:
return ll::Float64
end::Float64Metadata
Metadata
Assignees
Labels
No labels