Skip to content

derivative of ParametricSpline is type-unstable and allocating #103

@stevengj

Description

@stevengj

The return value of derivative is inferred as Any (i.e., it is type-unstable). This seems like a bug?

Furthermore, it allocates a Vector{Float64} for its return value. Since the dimensionality is known from the ParametricSpline type, couldn't we use SVector{2,Float64} instead? StaticArrays.jl is pretty widely used these days, so it is not crazy to add a dependency on it. (Alternatively, you could add an API that returns a tuple.)

julia> using Dierckx, Test

julia> spl = ParametricSpline(1:10, rand(2, 10))
ParametricSpline(knots=[1.0,3.0  8.0,10.0] (8 elements), k=3, extrapolation="nearest", residual=0.0)

julia> derivative(spl, 5.1) # allocates
2-element Vector{Float64}:
 -0.6756394220200724
  0.1203327362940756

julia> @inferred derivative(spl, 5.1) # type-unstable
ERROR: return type Vector{Float64} does not match inferred return type Any

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions