From 41ac046471b2d99c3779352f516706e54b3f187e Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Thu, 7 Apr 2022 14:31:38 -0500 Subject: [PATCH] Improve integration with Interpolations This defines `Interpolations.popwrapper` on CenterIndexedArrays, allowing certain operations to be performed without the caller having to unwrap the array. --- src/CenterIndexedArrays.jl | 1 + test/runtests.jl | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/CenterIndexedArrays.jl b/src/CenterIndexedArrays.jl index 8aa4e28..b969258 100644 --- a/src/CenterIndexedArrays.jl +++ b/src/CenterIndexedArrays.jl @@ -97,6 +97,7 @@ function Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{CenterIndex end Base.parent(A::CenterIndexedArray) = A.data +Interpolations.popwrapper(A::CenterIndexedArray) = parent(A) function Base.showarg(io::IO, A::CenterIndexedArray, toplevel) print(io, "CenterIndexedArray(") diff --git a/test/runtests.jl b/test/runtests.jl index 7efa677..a7c7401 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -174,3 +174,14 @@ end @test A+A == CenterIndexedArray(dat+dat) @test isa(A .+ 1, CenterIndexedArray) end + +@testset "Interpolations integration" begin + y = 1:3 + yc = CenterIndexedArray(y) + itp = interpolate(yc, BSpline(Linear())) + @test itp(0.2) ≈ 2.2 + y = [4.0, 1.0, 0.0, 1.0, 4.0] + yc = CenterIndexedArray(y) + itp = interpolate!(yc, BSpline(Quadratic(InPlaceQ(OnCell())))) + @test itp(0.2) ≈ 0.2^2 +end