Re: [julia-users] How should nested local functions be annotated?
It's a long-standing issue that local and anonymous functions allocate (and have poor performance). FastAnonymous.jl and similar packages give you one way around that. --Tim On Saturday, January 31, 2015 08:03:37 PM Kirill Ignatiev wrote: > On Saturday, 31 January 2015 21:54:54 UTC-5, Jameson wrote: > > code_warntype is being a bit misleading there. code inference hasn't yet > > fully run on the inner function. > > This is a reduced test case from a larger program, which allocated a lot > of memory, and when I got rid of the locally declared function, the memory > usage dropped significantly. So at least empirically I think there may be a > problem there.
Re: [julia-users] How should nested local functions be annotated?
On Saturday, 31 January 2015 21:54:54 UTC-5, Jameson wrote: > > code_warntype is being a bit misleading there. code inference hasn't yet > fully run on the inner function. > This is a reduced test case from a larger program, which allocated a lot of memory, and when I got rid of the locally declared function, the memory usage dropped significantly. So at least empirically I think there may be a problem there.
Re: [julia-users] How should nested local functions be annotated?
code_warntype is being a bit misleading there. code inference hasn't yet fully run on the inner function. On Sat Jan 31 2015 at 7:21:56 PM Kirill Ignatiev wrote: > Consider the following function: > > function f() >> x::Float64 = 1.0 >> function g(y::Float64) >> x += y >> end >> g(2.0) >> g(3.0) >> x >> end > > > Then @code_warntype gives: > > julia> @code_warntype f() >> Variables: >> x::Float64 >> g::F >> Body: >> begin # /***.jl, line 310: >> NewvarNode(:x) >> x = 1.0 # line 311: >> $(Expr(:method, :g, >> :((top(tuple))((top(tuple))(Float64)::Any,(top(tuple))()::Any)::Any), >> AST(:($(Expr(:lambda, Any[:y], >> Any[Any[symbol("#s5504")],Any[Any[:y,Any,0],Any[symbol("#s5504"),Any,18]],Any[Any[:x,Float64,7]]], >> :(begin # /***.jl, line 312: >> #s5504 = x + y::Any >> x = >> (top(typeassert))((top(convert))(Float64,#s5504)::Any,Float64)::Any >> return #s5504 >> end::Any), false)) # line 314: >> (g::F)(2.0)::Any # line 315: >> (g::F)(3.0)::Any # line 316: >> return x::Float64 >> end::Float64 > > > Is there anything I can do to make it recognize that the type of x doesn't > change here? It seems to think that "y" can be Any, despite the annotation > saying it can only be Float64. I am missing something here? >