Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Blocks/Blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Blocks
using ModelingToolkitBase: ModelingToolkitBase, @component, @connector, @named,
@parameters, @unpack, System, compose, connect, extend,
getdefault, t_nounits as t, D_nounits as D
using SymbolicUtils: @syms, symtype
using Symbolics: Symbolics, @register_symbolic, @variables, Differential, Equation
import Base: ifelse
import ..@symcheck
Expand Down
10 changes: 9 additions & 1 deletion src/Blocks/sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,15 @@ end

Base.nameof(::CachedInterpolation) = :CachedInterpolation

@register_symbolic (f::CachedInterpolation)(u::AbstractArray, x::AbstractArray, args::Tuple)
const _INTERPOLATOR_SYMTYPE = let
@syms interpolator(::Real)::Real
symtype(interpolator)
end

# Calling the builder returns the interpolation function, not an interpolated scalar.
@register_symbolic (f::CachedInterpolation)(
u::AbstractArray, x::AbstractArray, args::Tuple
)::_INTERPOLATOR_SYMTYPE

"""
ParametrizedInterpolation(interp_type, u, x, args...; name, t = ModelingToolkitBase.t_nounits)
Expand Down
4 changes: 4 additions & 0 deletions test/sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using SymbolicIndexingInterface
using SciMLStructures: SciMLStructures, Tunable
using ForwardDiff
using ADTypes
using SymbolicUtils: symtype

@testset "Constant" begin
@named src = Constant(k = 2)
Expand Down Expand Up @@ -650,6 +651,9 @@ end

@testset "LinearInterpolation" begin
@named i = ParametrizedInterpolation(LinearInterpolation, u, x)
interpolator = only(values(bindings(i)))
@test symtype(interpolator(0.0)) === Real

eqs = [i.input.u ~ t, D(y) ~ i.output.u]

@named model = System(eqs, t, systems = [i])
Expand Down
Loading