Skip to content

Commit f804e54

Browse files
Merge pull request #1214 from lamorton/devectorize
Use iteration instead of vector indexing
2 parents 4458e08 + 7a7c689 commit f804e54

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/systems/validation.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,24 @@ function safe_get_unit(term, info)
8282
end
8383

8484
function _validate(terms::Vector, labels::Vector{String}; info::String = "")
85-
equnits = safe_get_unit.(terms, info*" ".*labels)
86-
allthere = all(map(x -> x!==nothing, equnits))
87-
allmatching = true
85+
valid = true
8886
first_unit = nothing
89-
if allthere
90-
for idx in 1:length(equnits)
91-
if !isequal(terms[idx],0)
92-
if first_unit === nothing
93-
first_unit = equnits[idx]
94-
elseif !equivalent(first_unit, equnits[idx])
95-
allmatching = false
96-
@warn("$info: units [$(equnits[1])] for $(labels[1]) and [$(equnits[idx])] for $(labels[idx]) do not match.")
97-
98-
end
87+
first_label = nothing
88+
for (term,label) in zip(terms,labels)
89+
equnit = safe_get_unit(term, info*label)
90+
if equnit === nothing
91+
valid = false
92+
elseif !isequal(term,0)
93+
if first_unit === nothing
94+
first_unit = equnit
95+
first_label = label
96+
elseif !equivalent(first_unit, equnit)
97+
valid = false
98+
@warn("$info: units [$(equnit)] for $(first_label) and [$(equnit)] for $(label) do not match.")
9999
end
100100
end
101101
end
102-
allthere && allmatching
102+
valid
103103
end
104104

105105
function validate(jump::Union{ModelingToolkit.VariableRateJump, ModelingToolkit.ConstantRateJump}, t::Symbolic; info::String = "")

0 commit comments

Comments
 (0)