-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
Description
The following function (boiled down from this example seems to have a spurious type-inference failure:
function foo!(u::T,v::T) where {T<:AbstractVector}
axes(u,1) == axes(v,1) || error("axis mismatch")
for t = 1:10, i = firstindex(u)+1:lastindex(u)-1
v[i] = -2u[i] + sum(k -> u[i+k]+u[i-k], (1,))
u,v = v,u
end
return u,v
endas evinced by a huge number of allocations:
julia> u = rand(100); v = copy(u);
julia> @btime foo!($u,$v);
345.500 μs (8834 allocations: 168.83 KiB)If I comment out the u,v = v,u line, which should be a type-stable operation since u and v have the same type, then the number of allocations goes down to zero.