From a9719ea1a15a1854a1bd5c54c3c28793262da31b Mon Sep 17 00:00:00 2001 From: Sathvik Bhagavan Date: Fri, 13 Oct 2023 17:35:35 +0000 Subject: [PATCH 1/2] fix: first order symbolic derivative --- ext/DataInterpolationsSymbolicsExt.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/DataInterpolationsSymbolicsExt.jl b/ext/DataInterpolationsSymbolicsExt.jl index 2341745b..2a96bbe7 100644 --- a/ext/DataInterpolationsSymbolicsExt.jl +++ b/ext/DataInterpolationsSymbolicsExt.jl @@ -22,7 +22,7 @@ end SymbolicUtils.promote_symtype(::typeof(derivative), _...) = Real function Symbolics.derivative(interp::AbstractInterpolation, args::NTuple{1, Any}, ::Val{1}) - derivative(interp, Num(args[1])) + Symbolics.unwrap(derivative(interp, Symbolics.wrap(args[1]))) end end # module From ae03aec94f7bfd61eb4ee6ad5f2a6973d7d15c67 Mon Sep 17 00:00:00 2001 From: Sathvik Bhagavan Date: Fri, 13 Oct 2023 17:38:08 +0000 Subject: [PATCH 2/2] test: add test for symbolic derivative --- test/derivative_tests.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/derivative_tests.jl b/test/derivative_tests.jl index 7501d096..abf5002e 100644 --- a/test/derivative_tests.jl +++ b/test/derivative_tests.jl @@ -173,3 +173,13 @@ expr = A(ω) derivexpr = expand_derivatives(substitute(D(A(ω)), Dict(ω => 0.5τ))) symfunc = Symbolics.build_function(derivexpr, τ; expression = Val{false}) @test symfunc(0.5) == 0.5 * 3 + +u = [0.0, 1.5, 0.0] +t = [0.0, 0.5, 1.0] +@variables τ +D = Symbolics.Differential(τ) +f = LinearInterpolation(u, t) +df = expand_derivatives(D(f(τ))) +symfunc = Symbolics.build_function(df, τ; expression = Val{false}) +ts = 0.0:0.1:1.0 +@test all(map(ti -> symfunc(ti) == derivative(f, ti), ts))