It would be nice if "practice" weren't necessary, but that turns out to be 
true of all of julia's @code_* macros. If you don't feel like improving the 
code itself, please do consider adding to the documentation (click the pencil 
icon up at the top of the page to edit).

https://github.com/JuliaLang/julia/blob/master/doc/manual/performance-tips.rst#objcode_warntype

--Tim


On Friday, February 20, 2015 06:20:26 AM Kristoffer Carlsson wrote:
> Ah okay.
> 
> I sort of assumed red = bad hehe. I guess I need to practice reading the
> output more.
> 
> Thank you,
> 
> // Kristoffer
> 
> On Friday, February 20, 2015 at 2:47:37 PM UTC+1, Tim Holy wrote:
> > It's not actually type-unstable. Note that the "::Any" annotation is on
> > GetfieldNode(Base.Math,:sqrt_llvm), i.e., the lookup of the :sqrt_llvm
> > symbol
> > inside Base.Math.
> > 
> > Any PRs helping to improve the logic of code_warntype are appreciated.
> > 
> > --Tim
> > 
> > On Friday, February 20, 2015 01:00:07 PM Mauro wrote:
> > > This might be something wrong in @code_warntype as @code_llvm and
> > > @code_native give the same output.
> > > 
> > > On Fri, 2015-02-20 at 12:20, Kristoffer Carlsson <[email protected]
> > 
> > <javascript:>>
> > 
> > wrote:
> > > > 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

Reply via email to