It's easy to check for yourself: code_typed(bellman_operator,(GrowthModel,
Vector{Float64},Bool))
I cannot tell conclusively since I don't know what g.grid is, but at the
very last line you'll have something that looks like:
end::Union(Array{Float64,1},(Array{Float64,1},Array{Float64,1}))
It looks like you sometimes return a tuple of arrays.
On Monday, June 30, 2014 12:17:45 PM UTC-4, Spencer Lyon wrote:
>
> Does this function suffer from type instability?
>
> function bellman_operator{T <: FloatingPoint}(g::GrowthModel, w::Vector{T},
> compute_policy::Bool=false)
> # === Apply linear interpolation to w === #
> Aw = CoordInterpGrid(g.grid, w, BCnan, InterpLinear)
>
> if compute_policy
> σ = zeros(w)
> end
>
> # === set Tw[i] equal to max_c { u(c) + beta w(f(k_i) - c)} === #
> Tw = zeros(w)
> for (i, k) in enumerate(g.grid)
> objective(c) = - g.u(c) - g.β * Aw[g.f(k) - c]
> res = optimize(objective, 1e-6, g.f(k))
> c_star = res.minimum
> if compute_policy
> σ[i] = c_star
> end
>
> Tw[i] = - objective(c_star)
> end
>
> if compute_policy
> return Tw, σ
> else
> return Tw
> end
> end
>
> As far as I understand (which could very well be the source of my
> uncertainty — can anyone correct this definition?), the definition of type
> instability is that return types depend on the types of input types. In
> this case the return type doesn’t depend on the input type, but it does
> depend on the *value* of the argument compute_policy (return type is
> either Vector{T} or (Vector{T}, Vector{T})). I am a little unsure because
> given the *value* of compute_policy, the return type is unambiguous.
>
>