I would discourage generating code by creating strings and parsing them. It
is much better to use actual julia expressions.
Anyway, from what I see, you don't have a problem with the return type but
with an intermediate value and that is from doing this:
julia> g{S}(order::Array{S}) = Array(Float64, (order+1)...)
g (generic function with 1 method)
julia> @code_warntype g([1,2,3])
Variables:
order::Array{Int64,1}
Body:
begin # none, line 1:
return (top(_apply))((top(getfield))(Main,:call)::F,Main.Array,(top(
tuple))(Main.Float64)::Tuple{DataType},order::Array{Int64,1} .+ 1::Array{
Int64,1})::Array{Float64,N}
end::Array{Float64,N}
On Monday, June 13, 2016 at 12:04:41 AM UTC+2, Richard Dennis wrote:
>
> I wrote a generate function to compute Chebyshev weights using Chebyshev
> regression. I'm sure that there are many ways the code could be improved,
> but at the top of my list is eliminating what appears to be a type
> instability whose source I'm having trouble locating using @code_warntype.
> Any suggestions on how to eliminate the type instability would be
> appreciated.
>
> The code can be found at the following gist:
> https://gist.github.com/RJDennis/a0ea1e4e49da97edaa464ba2a8d701ab
>
> Thanks,
>
> Richard
>