Skip to content

Commit c06098c

Browse files
committed
incoporate sam's suggestion
1 parent 6ca9d5c commit c06098c

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/reactionsystem.jl

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,27 +1227,19 @@ function set_default_metadata(rs::ReactionSystem; default_reaction_metadata = [
12271227
# Currently, `noise_scaling` is the only relevant metadata supported this way.
12281228
drm_dict = Dict(default_reaction_metadata)
12291229
if haskey(drm_dict, :noise_scaling)
1230-
# Finds parameters, species, and variables in the noise scaling term.
1231-
ns_expr = drm_dict[:noise_scaling]
1230+
# Finds parameters, species, and variables in the noise scaling term.
1231+
ns_expr = drm_dict[:noise_scaling]
12321232
ns_syms = [Symbolics.unwrap(sym) for sym in get_variables(ns_expr)]
1233-
ns_ps = filter(ModelingToolkit.isparameter, ns_syms)
1234-
ns_sps = filter(Catalyst.isspecies, ns_syms)
1235-
ns_vs = filter(sym -> !Catalyst.isspecies(sym) && !ModelingToolkit.isparameter(sym), ns_syms)
1236-
1233+
ns_ps = Iterators.filter(ModelingToolkit.isparameter, ns_syms)
1234+
ns_sps = Iterators.filter(Catalyst.isspecies, ns_syms)
1235+
ns_vs = Iterators.filter(sym -> !Catalyst.isspecies(sym) &&
1236+
!ModelingToolkit.isparameter(sym), ns_syms)
12371237
# Adds parameters, species, and variables to the `ReactionSystem`.
1238-
if any(!any(isequal(p1, p2) for p2 in get_ps(rs)) for p1 in ns_ps)
1239-
@set! rs.ps = unique([get_ps(rs); ns_ps])
1240-
end
1241-
if any(!any(isequal(sp1, sp2) for sp2 in get_species(rs)) for sp1 in ns_sps)
1242-
sps_new = unique([get_species(rs); ns_sps])
1243-
vs_old = get_unknowns(rs)[length(get_species(rs))+1 : end]
1244-
@set! rs.species = sps_new
1245-
@set! rs.unknowns = [sps_new; vs_old]
1246-
end
1247-
if any(!any(isequal(v1, v2) for v2 in get_unknowns(rs)) for v1 in ns_vs)
1248-
us_new = unique([get_unknowns(rs); ns_vs])
1249-
@set! rs.unknowns = us_new
1250-
end
1238+
@set! rs.ps = union(get_ps(rs), ns_ps)
1239+
sps_new = union(get_species(rs), ns_sps)
1240+
@set! rs.species = sps_new
1241+
vs_old = @view get_unknowns(rs)[length(get_species(rs))+1 : end]
1242+
@set! rs.unknowns = union(sps_new, vs_old, ns_vs)
12511243
end
12521244

12531245
# Updates reaction metadata for all its subsystems.

0 commit comments

Comments
 (0)