Skip to content

Commit 4db99bb

Browse files
refactor: improve type-stability of constraint validation
1 parent d9a4539 commit 4db99bb

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/systems/system.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,10 @@ Process variables in constraints of the (ODE) System.
686686
"""
687687
function process_constraint_system(
688688
constraints::Vector{Union{Equation, Inequality}}, sts, ps, iv; validate = true)
689-
isempty(constraints) && return Set(), Set()
689+
isempty(constraints) && return OrderedSet{SymbolicT}(), OrderedSet{SymbolicT}()
690690

691-
constraintsts = OrderedSet()
692-
constraintps = OrderedSet()
691+
constraintsts = OrderedSet{SymbolicT}()
692+
constraintps = OrderedSet{SymbolicT}()
693693
for cons in constraints
694694
collect_vars!(constraintsts, constraintps, cons, iv)
695695
union!(constraintsts, collect_applied_operators(cons, Differential))
@@ -707,8 +707,8 @@ end
707707
Process the costs for the constraint system.
708708
"""
709709
function process_costs(costs::Vector, sts, ps, iv)
710-
coststs = OrderedSet()
711-
costps = OrderedSet()
710+
coststs = OrderedSet{SymbolicT}()
711+
costps = OrderedSet{SymbolicT}()
712712
for cost in costs
713713
collect_vars!(coststs, costps, cost, iv)
714714
end
@@ -743,8 +743,7 @@ function validate_vars_and_find_ps!(auxvars, auxps, sysvars, iv)
743743
operation(var)(iv) sts ||
744744
throw(ArgumentError("Variable $var is not a variable of the System. Called variables must be variables of the System."))
745745

746-
isequal(arg, iv) || isparameter(arg) || arg isa Integer ||
747-
arg isa AbstractFloat ||
746+
isequal(arg, iv) || isparameter(arg) || isconst(arg) && symtype(arg) <: Real ||
748747
throw(ArgumentError("Invalid argument specified for variable $var. The argument of the variable should be either $iv, a parameter, or a value specifying the time that the constraint holds."))
749748

750749
isparameter(arg) && !isequal(arg, iv) && push!(auxps, arg)

0 commit comments

Comments
 (0)