Skip to content

Commit b40c2a1

Browse files
committed
fix Complex typecheck
1 parent dfebe6a commit b40c2a1

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/utils.jl

Lines changed: 12 additions & 4 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) :
@@ -1204,7 +1205,7 @@ end
12041205
Find all the unknowns and parameters from the equations of a SDESystem or ODESystem. Return re-ordered equations, differential variables, all variables, and parameters.
12051206
"""
12061207
function process_equations(eqs, iv)
1207-
eqs = collect(eqs)
1208+
eqs = collect(Iterators.flatten(eqs))
12081209

12091210
diffvars = OrderedSet()
12101211
allunknowns = OrderedSet()
@@ -1237,8 +1238,8 @@ function process_equations(eqs, iv)
12371238
throw(ArgumentError("An ODESystem can only have one independent variable."))
12381239
diffvar in diffvars &&
12391240
throw(ArgumentError("The differential variable $diffvar is not unique in the system of equations."))
1240-
!(symtype(diffvar) === Real || eltype(symtype(diffvar)) === Real) &&
1241-
throw(ArgumentError("Differential variable $diffvar has type $(symtype(diffvar)). Differential variables should not be concretely typed."))
1241+
!has_diffvar_type(diffvar) &&
1242+
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."))
12421243
push!(diffvars, diffvar)
12431244
end
12441245
push!(diffeq, eq)
@@ -1250,6 +1251,13 @@ function process_equations(eqs, iv)
12501251
diffvars, allunknowns, ps, Equation[diffeq; algeeq; compressed_eqs]
12511252
end
12521253

1254+
function has_diffvar_type(diffvar)
1255+
st = symtype(diffvar)
1256+
st === Real || eltype(st) === Real || st === Complex || eltype(st) === Complex ||
1257+
st === Number || eltype(st) === Number || st === AbstractFloat ||
1258+
eltype(st) === AbstractFloat
1259+
end
1260+
12531261
"""
12541262
$(TYPEDSIGNATURES)
12551263

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)