I was referred to that issue earlier but didn't quite get why, but now I see it! Thanks.
On Friday, September 9, 2016 at 1:02:27 PM UTC+2, Lutfullah Tomak wrote: > > Using a captured variable in a closure makes it somehow a Core.box. > Generator defines an anonymous with maxV so it is hitting something like > this https://github.com/JuliaLang/julia/issues/15276 > Smaller repro > function c!{T}(::T,P) > if length(P)>2 > maxV = one(T) > d = x->maxV > end > P > end > > > > On Friday, September 9, 2016 at 1:02:29 PM UTC+3, Patrick Kofod Mogensen > wrote: >> >> So, I am kind of confused here. In my code, a maxV = maximum(V) is >> labeled as Core.Box in @code_warntype, but if I remove a line after the >> line where maxV is calculated, it is correctly labelled as eltype(V). Can >> anyone explain what happens/what I am doing wrong here? This is not the >> whole function, I've tried to remove all irrelevant code. >> V = [0.,] >> P = Vector{Float64}[[0.0,], [0.0,]] >> U = Vector{Float64}[[1.,], [1.,]] >> F = Matrix{Float64}[eye(1), eye(1)] >> b = 0.9 >> >> function c!{T}(P, U, b::T, F, V) >> if length(P) > 2 >> maxV = maximum(V) >> d = sum(exp(U[ia]+b*F[ia]*V-maxV) for ia = 1:length(P))::T >> end >> P >> end >> >> # This shows maxV as Core.Box >> @code_warntype c!(P, U, β, F, V) >> >> >> function c!{T}(P, U, b::T, F, V) >> if length(P) > 2 >> maxV = maximum(V) >> end >> P >> end >> >> # This does not show maxV as Core.Box, but as eltype(V) as I expected >> @code_warntype c!(P, U, β, F, V) >> >> Thanks >> >