DataInterpolations.jl icon indicating copy to clipboard operation
DataInterpolations.jl copied to clipboard

Label (a la traits) interpolators that reproduce the data from those that don't

Open kapple19 opened this issue 4 months ago • 2 comments

Is your feature request related to a problem? Please describe.

Distinction between data-reproducing interpolation methods from non-data-reproducing interpolation methods.

Describe the solution you’d like

Instead of directly subtyping AbstractInterpolation, Introduce a hierarchy:

AbstractReproducingInterpolation <: AbstractInterpolation
AbstractNonReproducingInterpolation <: AbstractInterpolation

For example

LinearInterpolation <: AbstractReproducingInterpolation
SmoothedConstantInterpolation <: AbstractNonReproducingInterpolation

I'm not sure how I feel about the name though. Feel free to use a better one you can think of.

Describe alternatives you’ve considered

Traits? Tim Holy Traits which seems overkill. Any traiting implementation seems overkill. Unless there's more functionality someone wants that would be better with traits than with a type hierarchy.

Also directly manually listing the reproducers. The advantage of this is that I'd still have to define the interpolator with options, e.g.

reproducers = [
    LinearInterpolation
    QuadraticInterpolation
    (u, t) -> QuadraticInterpolation(u, t; :Backward)
    LagrangeInterpolation
    AkimaInterpolationConstantInterpolation
    QuadraticSplineInterpolation
    CubicSplineInterpolation
    BSplineInterpolation
    CubicHermiteSpline
    PCHIPInterpolation
    QuinticHermiteSpline
    # ...etc.
]

But it would be shorter with my FR anyway, e.g.

reproducers = [
    subtypes(AbstractReproducingInterpolation);
    (u, t) -> QuadraticInterpolation(u, t; :Backward)
]

Additional context

The type of interpolation a user wants can be generalised while restricting the choice of interpolator to one that replicates the data.

Also motivated by designing wrappers for DimensionalData objects. The test that the interpolators reproduce the data can only apply to AbstractReproducingInterpolations.

I'm happy to submit a PR if everyone's happy with this idea.

kapple19 avatar Aug 23 '25 01:08 kapple19

I would think trait functions would do better for this information than abstract typing. It doesn't make sense in an abstract type.

ChrisRackauckas avatar Aug 23 '25 21:08 ChrisRackauckas

Also, PCHIPInterpolation isa Function and !(PCHIPInterpolation <: AbstractInterpolation), which would break under the abstract typing.

Traits it is.

kapple19 avatar Aug 24 '25 03:08 kapple19