From 38c042f0fb5f89a474cb5d3e786a5d62d41d981c Mon Sep 17 00:00:00 2001 From: Ashutosh Bharambe Date: Tue, 1 Oct 2024 16:30:17 +0000 Subject: [PATCH 1/4] fix(LinearInterpolation): output vector for a `AbstractMatrix` --- src/interpolation_methods.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/interpolation_methods.jl b/src/interpolation_methods.jl index 03adf558..54621d5d 100644 --- a/src/interpolation_methods.jl +++ b/src/interpolation_methods.jl @@ -41,6 +41,14 @@ function _interpolate(A::LinearInterpolation{<:AbstractArray}, t::Number, iguess return A.u[ax..., idx] + slope * Δt end +function _interpolate(A::LinearInterpolation{<:AbstractMatrix}, t::Number, iguess) + idx = get_idx(A, t, iguess) + Δt = t - A.t[idx] + slope = get_parameters(A, idx) + ax = axes(A.u)[1:(end - 1)] + return @views A.u[ax..., idx][:] + slope[:] * Δt +end + # Quadratic Interpolation _quad_interp_indices(A, t) = _quad_interp_indices(A, t, firstindex(A.t) - 1) function _quad_interp_indices(A::QuadraticInterpolation, t::Number, iguess) From c6eaa04441560afdb08596031c979f0ffcfb3867 Mon Sep 17 00:00:00 2001 From: Ashutosh Bharambe Date: Tue, 1 Oct 2024 16:31:02 +0000 Subject: [PATCH 2/4] test(LinearInterpolation): change tests back to original --- test/interpolation_tests.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/interpolation_tests.jl b/test/interpolation_tests.jl index 69e5c197..3ebc1741 100644 --- a/test/interpolation_tests.jl +++ b/test/interpolation_tests.jl @@ -43,11 +43,11 @@ end A = LinearInterpolation(u, t; extrapolate = true) for (_t, _u) in zip(t, eachcol(u)) - @test A(_t) == reshape(_u, :, 1) + @test A(_t) == _u end - @test A(0) == [0.0; 0.0;;] - @test A(5.5) == [11.0; 16.5;;] - @test A(11) == [22; 33;;] + @test A(0) == [0.0, 0.0] + @test A(5.5) == [11.0, 16.5] + @test A(11) == [22, 33] x = 1:10 y = 2:4 From a837b3dfe3bee01b1e9784d40f4f607617b73d69 Mon Sep 17 00:00:00 2001 From: Ashutosh Bharambe Date: Thu, 3 Oct 2024 13:33:09 +0000 Subject: [PATCH 3/4] fix(LinearInterpolation): index into last dimension to give suitable output --- src/parameter_caches.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parameter_caches.jl b/src/parameter_caches.jl index 824b2e2a..42d040e8 100644 --- a/src/parameter_caches.jl +++ b/src/parameter_caches.jl @@ -22,7 +22,7 @@ function linear_interpolation_parameters(u::AbstractArray{T, N}, t, idx) where { Δu = if N > 1 ax = axes(u) safe_diff.( - u[ax[1:(end - 1)]..., (idx + 1):(idx + 1)], u[ax[1:(end - 1)]..., idx:idx]) + u[ax[1:(end - 1)]..., (idx + 1)], u[ax[1:(end - 1)]..., idx]) else safe_diff(u[idx + 1], u[idx]) end From 3e0b6b20ef8d8dc9ecc03ec3a30beea8cf2ab23e Mon Sep 17 00:00:00 2001 From: Ashutosh Bharambe Date: Thu, 3 Oct 2024 13:33:48 +0000 Subject: [PATCH 4/4] fix(LinearInterpolation): remove added dispatch for AbstractMatrix --- src/interpolation_methods.jl | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/interpolation_methods.jl b/src/interpolation_methods.jl index 54621d5d..03adf558 100644 --- a/src/interpolation_methods.jl +++ b/src/interpolation_methods.jl @@ -41,14 +41,6 @@ function _interpolate(A::LinearInterpolation{<:AbstractArray}, t::Number, iguess return A.u[ax..., idx] + slope * Δt end -function _interpolate(A::LinearInterpolation{<:AbstractMatrix}, t::Number, iguess) - idx = get_idx(A, t, iguess) - Δt = t - A.t[idx] - slope = get_parameters(A, idx) - ax = axes(A.u)[1:(end - 1)] - return @views A.u[ax..., idx][:] + slope[:] * Δt -end - # Quadratic Interpolation _quad_interp_indices(A, t) = _quad_interp_indices(A, t, firstindex(A.t) - 1) function _quad_interp_indices(A::QuadraticInterpolation, t::Number, iguess)