Skip to content

Inconsistent output eltype when evaluating on vectors #388

@DaniGlez

Description

@DaniGlez

As of 7.1.0, output eltype is different when evaluating on vectors compared to just broadcasting the scalar path

julia> using DataInterpolations
julia> u = [2, 3];
julia> t = [0.0, 1.0];
julia> itp = ConstantInterpolation(u, t)
julia> itp(t)
2-element Vector{Float64}:
 2.0
 3.0

julia> itp.(t)
2-element Vector{Int64}:
 2
 3

The culprit is in the following lines from https://github.com/SciML/DataInterpolations.jl/blob/master/src/DataInterpolations.jl#L29

function (interp::AbstractInterpolation)(t::AbstractVector)
    u = get_u(interp.u, t)
    interp(u, t)
end

function get_u(u::AbstractVector, t)
    return similar(t, promote_type(eltype(u), eltype(t)))
end

For floats versus ints, a specialization can be defined for ConstantInterpolation (whose output is the one that actually preserves the eltype of u). But I wonder if the promotion would also generate issues with exotic output types. Would it be possible for get_u to use the inferred return type of interp itself or would that require usage of arcane Julia internals?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions