I had a type instability in my program and I condensed it down to this
minimal working example.
Why is sqrt2 here unstable? The variable a should be inferred to always be
a Float64 and then the function should be stable just like the normal sqrt
function is?
julia> function sqrt2(a::Float64)
return sqrt(a)
end
sqrt2 (generic function with 1 method)
julia> @code_warntype sqrt2(5.0)
Variables:
a::Float64
Body:
begin # none, line 2:
return (GetfieldNode(Base.Math,:box,Any))(Float64,(GetfieldNode(Base.
Math,:sqrt_llvm,Any))(a::Float64)::Any)::Float64
end::Float64
julia> @code_warntype sqrt(5.0)
Variables:
x::Float64
Body:
begin # math.jl, line 130:
return box(Float64,sqrt_llvm(x::Float64))
end::Float64
Best regards,
Kristoffer Carlsson