Skip to content

Commit

Permalink
Merge pull request SciML#318 from sathvikbhagavan/sb/register
Browse files Browse the repository at this point in the history
refactor: use register symbolic for interpolation objects
  • Loading branch information
ChrisRackauckas authored Jul 29, 2024
2 parents 5c936e8 + 245fe51 commit 4ee7210
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 1 addition & 2 deletions ext/DataInterpolationsSymbolicsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion test/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4ee7210

Please sign in to comment.