From a3e82f10265ded9846a9a9da6da6229912073755 Mon Sep 17 00:00:00 2001 From: Sathvik Bhagavan Date: Mon, 29 Jul 2024 09:08:54 +0000 Subject: [PATCH 1/2] refactor: use register symbolic for interpolation objects --- ext/DataInterpolationsSymbolicsExt.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/DataInterpolationsSymbolicsExt.jl b/ext/DataInterpolationsSymbolicsExt.jl index 106535ef..b144da22 100644 --- a/ext/DataInterpolationsSymbolicsExt.jl +++ b/ext/DataInterpolationsSymbolicsExt.jl @@ -12,8 +12,7 @@ else using ..Symbolics: Num, unwrap, SymbolicUtils end -(interp::AbstractInterpolation)(t::Num) = SymbolicUtils.term(interp, unwrap(t)) -SymbolicUtils.promote_symtype(t::AbstractInterpolation, _...) = Real +@register_symbolic (interp::AbstractInterpolation)(t) Base.nameof(interp::AbstractInterpolation) = :Interpolation function derivative(interp::AbstractInterpolation, t::Num, order = 1) From 245fe5151ba75ffdb768ed62c788baee5a303c22 Mon Sep 17 00:00:00 2001 From: Sathvik Bhagavan Date: Mon, 29 Jul 2024 09:11:33 +0000 Subject: [PATCH 2/2] test: add tests for symbolic interpolation compositions --- test/interface.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/interface.jl b/test/interface.jl index 3e910547..e7b2b81b 100644 --- a/test/interface.jl +++ b/test/interface.jl @@ -18,9 +18,14 @@ end @testset "Symbolics" begin u = 2.0collect(1:10) t = 1.0collect(1:10) - A = LinearInterpolation(u, t) + A = LinearInterpolation(u, t; extrapolate = true) + B = LinearInterpolation(u .^ 2, t; extrapolate = true) @variables t x(t) substitute(A(t), Dict(t => x)) + t_val = 2.7 + @test substitute(A(t), Dict(t => t_val)) == A(t_val) + @test substitute(B(A(t)), Dict(t => t_val)) == B(A(t_val)) + @test substitute(A(B(A(t))), Dict(t => t_val)) == A(B(A(t_val))) end @testset "Type Inference" begin