Skip to content

Commit 9161395

Browse files
fix: improve type-stability of some SII functions
1 parent b921da8 commit 9161395

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/systems/abstractsystem.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,20 @@ function SymbolicIndexingInterface.variable_symbols(sys::AbstractSystem)
170170
return unknowns(sys)
171171
end
172172

173-
function SymbolicIndexingInterface.is_parameter(sys::AbstractSystem, sym)
174-
sym = unwrap(sym)
173+
function SymbolicIndexingInterface.is_parameter(sys::AbstractSystem, sym::Union{Num, Symbolics.Arr, Symbolics.CallAndWrap})
174+
is_parameter(sys, unwrap(sym))
175+
end
176+
177+
function SymbolicIndexingInterface.is_parameter(sys::AbstractSystem, sym::Int)
178+
sym in 1:length(parameter_symbols(sys))
179+
end
180+
181+
function SymbolicIndexingInterface.is_parameter(sys::AbstractSystem, sym::SymbolicT)
175182
if has_index_cache(sys) && (ic = get_index_cache(sys)) !== nothing
176183
return sym isa ParameterIndex || is_parameter(ic, sym) ||
177-
iscall(sym) &&
178-
operation(sym) === getindex &&
184+
iscall(sym) && operation(sym) === getindex &&
179185
is_parameter(ic, first(arguments(sym)))
180186
end
181-
if unwrap(sym) isa Int
182-
return unwrap(sym) in 1:length(parameter_symbols(sys))
183-
end
184187
return any(isequal(sym), parameter_symbols(sys)) ||
185188
hasname(sym) && !(iscall(sym) && operation(sym) == getindex) &&
186189
is_parameter(sys, getname(sym))
@@ -191,7 +194,7 @@ function SymbolicIndexingInterface.is_parameter(sys::AbstractSystem, sym::Symbol
191194
return is_parameter(ic, sym)
192195
end
193196

194-
named_parameters = [getname(x)
197+
named_parameters = Symbol[getname(x)
195198
for x in parameter_symbols(sys)
196199
if hasname(x) && !(iscall(x) && operation(x) == getindex)]
197200
return any(isequal(sym), named_parameters) ||

0 commit comments

Comments
 (0)