Skip to content

inference failure on array relabeling #43352

@stevengj

Description

@stevengj

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
end

as 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions