Skip to content

Commit d130562

Browse files
authored
Merge pull request #1556 from SciML/myb/error_check
More robust error checking and better tests
2 parents 018ac8d + 5f92988 commit d130562

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

src/bipartite_graph.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,12 @@ function Base.push!(m::Matching{U}, v::Union{Integer, U}) where {U}
6666
end
6767
end
6868

69-
function complete(m::Matching{U}) where {U}
69+
function complete(m::Matching{U}, N=length(m.match)) where {U}
7070
m.inv_match !== nothing && return m
71-
N = length(m.match)
7271
inv_match = Union{U, Int}[unassigned for _ = 1:N]
7372
for (i, eq) in enumerate(m.match)
7473
isa(eq, Int) || continue
75-
if eq <= N
76-
inv_match[eq] = i
77-
else # this only happens when the system is imbalanced
78-
for k in N+1:eq-1
79-
push!(inv_match, unassigned)
80-
end
81-
push!(inv_match, i)
82-
end
74+
inv_match[eq] = i
8375
end
8476
return Matching{U}(collect(m.match), inv_match)
8577
end

src/structural_transformation/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function check_consistency(state::TearingState)
5858
# Just use `error_reporting` to do conditional
5959
iseqs = n_highest_vars < neqs
6060
if iseqs
61-
eq_var_matching = invview(complete(var_eq_matching)) # extra equations
61+
eq_var_matching = invview(complete(var_eq_matching, nsrcs(graph))) # extra equations
6262
bad_idxs = findall(isequal(unassigned), @view eq_var_matching[1:nsrcs(graph)])
6363
else
6464
bad_idxs = findall(isequal(unassigned), var_eq_matching)

test/odesystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ let
741741
spm ~ a
742742
sph ~ b
743743
spm ~ 0
744+
sph ~ a
744745
]
745746
@named sys = ODESystem(eqs, t, vars, pars)
746747
@test_throws ModelingToolkit.ExtraEquationsSystemException structural_simplify(sys)

0 commit comments

Comments
 (0)