Skip to content

Conversation

cgarling
Copy link
Contributor

@cgarling cgarling commented Sep 3, 2025

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Following #457, this PR adds more tests for allocation-free interpolation of Vector{SVector} inputs. To my knowledge, all interpolators that work with vector-valued inputs now have these tests. That list is

  • CubicSpline
  • QuadraticInterpolation
  • SmoothedConstantInterpolation
  • ConstantInterpolation
  • QuadraticSpline
  • LinearInterpolation
  • CubicHermiteSpline
  • QuinticHermiteSpline

Two minor code changes are included to support this work.

  • In spline_coefficients! it is required to assert the return type of findfirst(x -> x > u, k)::Int to avoid a dynamic dispatch to - as findfirst can return an Int or Nothing. The dynamic dispatch causes the allocation check via AllocCheck.jl to fail. It looks like bounds checks on the inputs are performed during the extrapolation step, so I think it is safe to assert this return type.
  • The last branch in smoothed_constant_interpolation_parameters does not work on array-valued inputs as one(::AbstractArray) is not defined. I think type stability can be maintained by replacing zero(one(eltype(u)) / 2) with zero(first(u) / 2), but this is maybe not optimal if u has elements of mixed type. I suppose it could be zero(u[idx] / 2), other suggestions welcome.

Also some of CubicSpline @inferred tests that are labeled broken are now passing for me locally (Julia 1.11) so I changed those. If they fail on CI we can troubleshoot further.

The `zero(one(eltype(u)) / 2)` in `smoothed_constant_interpolation_parameters` made this interpolation fail for array-valued interpolations because `one(::AbstractArray)` is not defined. I replaced this with `zero(first(u) / 2)` which should maintain the same type stability across the different branches of the function. Tests added verifying the new functionality.
It can be Int or Nothing, but bounds are checked during extrapolation so we can assume it returns an Int. This fixes a dynamic dispatch found by AllocCheck.jl.
@cgarling
Copy link
Contributor Author

cgarling commented Sep 3, 2025

Three CubicSpline tests there were marked as broken on Julia < 1.11 are now passing on LTS ( see https://github.com/SciML/DataInterpolations.jl/actions/runs/17439841023/job/49519664698?pr=466) so I've updated those as well.

@ChrisRackauckas ChrisRackauckas merged commit 36b0dbe into SciML:master Sep 3, 2025
16 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants