Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Dec 3, 2024
1 parent 8395f22 commit 321e70f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/interpolation_caches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ drifts far from the integral of constant interpolation. In this interpolation ty
- `d_max`: the maximum distance in `t` from the data points the smoothing is allowed to reach.
- `extrapolation`: The extrapolation type applied left and right of the data. Possible options
are `ExtrapolationType.None` (default), `ExtrapolationType.Constant`, `ExtrapolationType.Linear`
`ExtrapolationType.Extension`, `ExtrapolationType.Periodic` and `ExtrapolationType.Reflective`.
`ExtrapolationType.Extension`, `ExtrapolationType.Periodic` (also made smooth at the boundaries) and `ExtrapolationType.Reflective`.
- `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for
the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`.
- `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for
Expand Down Expand Up @@ -427,7 +427,8 @@ function SmoothedConstantInterpolation(
extrapolation_left, extrapolation_right = munge_extrapolation(
extrapolation, extrapolation_left, extrapolation_right)
u, t = munge_data(u, t)
p = SmoothedConstantParameterCache(u, t, cache_parameters, d_max)
p = SmoothedConstantParameterCache(
u, t, cache_parameters, d_max, extrapolation_left, extrapolation_right)
A = SmoothedConstantInterpolation(
u, t, nothing, p, d_max, extrapolation_left,
extrapolation_right, cache_parameters, assume_linear_t)
Expand Down
3 changes: 2 additions & 1 deletion src/interpolation_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ function get_parameters(A::SmoothedConstantInterpolation, idx)
c_upper = A.p.c[idx + 1]
d_lower, d_upper, c_lower, c_upper
else
d_lower, c_lower = smoothed_constant_interpolation_parameters(A.u, A.t, A.d_max, idx, A.extrapolation_left, A.extrapolation_right)
d_lower, c_lower = smoothed_constant_interpolation_parameters(
A.u, A.t, A.d_max, idx, A.extrapolation_left, A.extrapolation_right)
d_upper, c_upper = smoothed_constant_interpolation_parameters(
A.u, A.t, A.d_max, idx + 1, A.extrapolation_left, A.extrapolation_right)
d_lower, d_upper, c_lower, c_upper
Expand Down
8 changes: 5 additions & 3 deletions src/parameter_caches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@ struct SmoothedConstantParameterCache{dType, cType}
c::cType
end

function SmoothedConstantParameterCache(u, t, cache_parameters, d_max)
function SmoothedConstantParameterCache(
u, t, cache_parameters, d_max, extrapolation_left, extrapolation_right)
if cache_parameters
parameters = smoothed_constant_interpolation_parameters.(
Ref(u), Ref(t), d_max, eachindex(t))
Ref(u), Ref(t), d_max, eachindex(t), extrapolation_left, extrapolation_right)
d, c = collect.(eachrow(stack(collect.(parameters))))
SmoothedConstantParameterCache(d, c)
else
SmoothedConstantParameterCache(eltype(t)[], eltype(u)[])
end
end

function smoothed_constant_interpolation_parameters(u, t, d_max, idx, extrapolation_left, extrapolation_right)
function smoothed_constant_interpolation_parameters(
u, t, d_max, idx, extrapolation_left, extrapolation_right)
if isone(idx) || (idx == length(t))
# If extrapolation is periodic, make the transition differentiable
if extrapolation_left == extrapolation_right == ExtrapolationType.Periodic
Expand Down
4 changes: 2 additions & 2 deletions test/parameter_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ end
u = [1.0, 5.0, 3.0, 4.0, 4.0]
t = collect(1:5)
A = SmoothedConstantInterpolation(u, t; cache_parameters = true)
A.p.d [0.0, 0.5, 0.5, 0.5, 0.0]
A.p.c [0.0, 2.0, -1.0, 0.5, 0.0]
@test A.p.d [0.0, 0.5, 0.5, 0.5, 0.0]
@test A.p.c [0.0, 2.0, -1.0, 0.5, 0.0]
end

@testset "Quadratic Interpolation" begin
Expand Down

0 comments on commit 321e70f

Please sign in to comment.