JuliaMath / JuliaMath/Dierckx.jl

derivative of ParametricSpline is type-unstable and allocating

Open
#103 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
173
Forks
30
PR merge metrics
No merged PRs in 30d

Description

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

```jl
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
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.