Skip to content

Commit e22f5d6

Browse files
Cache SearchProperties per interpolation to skip per-call Auto probes
The previous commit migrated the sorted-batch evaluators to FFF 2.0's strategy-dispatched `searchsortedlast!` API, but called it with the default `strategy = Auto()`. Each such call has `Auto()` re-probe the knot vector `A.t` for linearity / NaN / uniformity on every batched evaluation. Because `A.t` is fixed at interpolation construction, that probe is wasted work on every call after the first. This commit precomputes `FindFirstFunctions.SearchProperties(A.t)` once at cache-construction time and stores it as a new `t_props::propsType` field on every interpolation cache struct, then threads `FindFirstFunctions.Auto(A.t_props)` into each batched `searchsortedlast!` call site so the probe is skipped. Changes: - `src/interpolation_caches.jl`: every cache struct (`LinearInterpolation`, `QuadraticInterpolation`, `LagrangeInterpolation`, `AkimaInterpolation`, `ConstantInterpolation`, `SmoothedConstantInterpolation`, `QuadraticSpline`, `CubicSpline`, `BSplineInterpolation`, `BSplineApprox`, `CubicHermiteSpline`, `QuinticHermiteSpline`, `SmoothArcLengthInterpolation`) gains a `propsType` type parameter and a `t_props` field, populated by `FindFirstFunctions.SearchProperties(t)` in the inner constructor. - `src/integral_inverses.jl`: same change for `LinearInterpolationIntInv` and `ConstantInterpolationIntInv`. - `src/interpolation_methods.jl`: every `FindFirstFunctions.searchsortedlast!(...)` call site in the sorted-batch evaluators now passes `strategy = FindFirstFunctions.Auto(A.t_props)`. `_eval_interior_adaptive!` gains a `strategy` parameter so the Akima call site can pass the cached strategy through. For `AbstractRange{<:Real}` knot vectors the `SearchProperties` specialised constructor skips every probe (all properties are known statically), so the construction cost is zero. For `Vector{Float64}` the populated constructor runs an O(n) NaN scan once at construction time; for integer / non-numeric eltypes only the O(1) sampled- linearity probe runs. Tests: all five groups pass locally on Julia 1.11: Core | 2539 pass, 5 broken (pre-existing) Methods | 42151 pass Extensions | 13178 pass Misc | 11 pass QA | 18 pass Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
1 parent 9ad45d3 commit e22f5d6

3 files changed

Lines changed: 113 additions & 50 deletions

File tree

src/integral_inverses.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,19 @@ Can be easily constructed with `invert_integral(A::LinearInterpolation{<:Abstrac
3333
- `t` : Given by `A.I` (the cumulative integral of `A`)
3434
- `A` : The `LinearInterpolation` object
3535
"""
36-
struct LinearInterpolationIntInv{uType, tType, itpType, T} <:
36+
struct LinearInterpolationIntInv{uType, tType, itpType, T, propsType} <:
3737
AbstractIntegralInverseInterpolation{T}
3838
u::uType
3939
t::tType
4040
extrapolation_left::ExtrapolationType.T
4141
extrapolation_right::ExtrapolationType.T
4242
iguesser::Guesser{tType}
43+
t_props::propsType
4344
itp::itpType
4445
function LinearInterpolationIntInv(u, t, A, extrapolation_left, extrapolation_right)
45-
return new{typeof(u), typeof(t), typeof(A), eltype(u)}(
46-
u, t, extrapolation_left, extrapolation_right, Guesser(t), A
46+
t_props = FindFirstFunctions.SearchProperties(t)
47+
return new{typeof(u), typeof(t), typeof(A), eltype(u), typeof(t_props)}(
48+
u, t, extrapolation_left, extrapolation_right, Guesser(t), t_props, A
4749
)
4850
end
4951
end
@@ -93,19 +95,21 @@ Can be easily constructed with `invert_integral(A::ConstantInterpolation{<:Abstr
9395
- `t` : Given by `A.I` (the cumulative integral of `A`)
9496
- `A` : The `ConstantInterpolation` object
9597
"""
96-
struct ConstantInterpolationIntInv{uType, tType, itpType, T} <:
98+
struct ConstantInterpolationIntInv{uType, tType, itpType, T, propsType} <:
9799
AbstractIntegralInverseInterpolation{T}
98100
u::uType
99101
t::tType
100102
extrapolation_left::ExtrapolationType.T
101103
extrapolation_right::ExtrapolationType.T
102104
iguesser::Guesser{tType}
105+
t_props::propsType
103106
itp::itpType
104107
function ConstantInterpolationIntInv(
105108
u, t, A, extrapolation_left, extrapolation_right
106109
)
107-
return new{typeof(u), typeof(t), typeof(A), eltype(u)}(
108-
u, t, extrapolation_left, extrapolation_right, Guesser(t), A
110+
t_props = FindFirstFunctions.SearchProperties(t)
111+
return new{typeof(u), typeof(t), typeof(A), eltype(u), typeof(t_props)}(
112+
u, t, extrapolation_left, extrapolation_right, Guesser(t), t_props, A
109113
)
110114
end
111115
end

0 commit comments

Comments
 (0)