Skip to content

Commit df32909

Browse files
Merge pull request #3415 from vyudu/fix_vartype
fix: make the diffvar type check less restrictive
2 parents ae14ed6 + 9560797 commit df32909

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/utils.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ function collect_ivs_from_nested_operator!(ivs, x, target_op)
222222
end
223223

224224
function iv_from_nested_derivative(x, op = Differential)
225-
if iscall(x) && operation(x) == getindex
225+
if iscall(x) &&
226+
(operation(x) == getindex || operation(x) == real || operation(x) == imag)
226227
iv_from_nested_derivative(arguments(x)[1], op)
227228
elseif iscall(x)
228229
operation(x) isa op ? iv_from_nested_derivative(arguments(x)[1], op) :
@@ -1216,6 +1217,7 @@ end
12161217
Find all the unknowns and parameters from the equations of a SDESystem or ODESystem. Return re-ordered equations, differential variables, all variables, and parameters.
12171218
"""
12181219
function process_equations(eqs, iv)
1220+
eltype(eqs) <: Vector && (eqs = vcat(eqs...))
12191221
eqs = collect(eqs)
12201222

12211223
diffvars = OrderedSet()
@@ -1249,8 +1251,8 @@ function process_equations(eqs, iv)
12491251
throw(ArgumentError("An ODESystem can only have one independent variable."))
12501252
diffvar in diffvars &&
12511253
throw(ArgumentError("The differential variable $diffvar is not unique in the system of equations."))
1252-
!(symtype(diffvar) === Real || eltype(symtype(diffvar)) === Real) &&
1253-
throw(ArgumentError("Differential variable $diffvar has type $(symtype(diffvar)). Differential variables should not be concretely typed."))
1254+
!has_diffvar_type(diffvar) &&
1255+
throw(ArgumentError("Differential variable $diffvar has type $(symtype(diffvar)). Differential variables should be of a continuous, non-concrete number type: Real, Complex, AbstractFloat, or Number."))
12541256
push!(diffvars, diffvar)
12551257
end
12561258
push!(diffeq, eq)
@@ -1262,6 +1264,13 @@ function process_equations(eqs, iv)
12621264
diffvars, allunknowns, ps, Equation[diffeq; algeeq; compressed_eqs]
12631265
end
12641266

1267+
function has_diffvar_type(diffvar)
1268+
st = symtype(diffvar)
1269+
st === Real || eltype(st) === Real || st === Complex || eltype(st) === Complex ||
1270+
st === Number || eltype(st) === Number || st === AbstractFloat ||
1271+
eltype(st) === AbstractFloat
1272+
end
1273+
12651274
"""
12661275
$(TYPEDSIGNATURES)
12671276

test/odesystem.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,10 @@ end
15891589
@variables Y(t)[1:3]::String
15901590
eq = D(Y) ~ [p, p, p]
15911591
@test_throws ArgumentError @mtkbuild osys = ODESystem([eq], t)
1592+
1593+
@variables X(t)::Complex
1594+
eq = D(X) ~ p - d * X
1595+
@test_nowarn @named osys = ODESystem([eq], t)
15921596
end
15931597

15941598
# Test `isequal`

0 commit comments

Comments
 (0)