Skip to content

Commit d35620c

Browse files
committed
remove parametric types
1 parent 037b533 commit d35620c

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/systems/reaction/reactionsystem.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ function Reaction(rate, subs, prods, substoich, prodstoich;
6969
(isnothing(prodstoich)&&isnothing(substoich)) && error("Both substrate and product stochiometry inputs cannot be nothing.")
7070
if isnothing(subs)
7171
subs = Vector{Operation}()
72-
isnothing(substoich) && error("If substrates are nothing, substrate stiocihometries have to be so too.")
72+
!isnothing(substoich) && error("If substrates are nothing, substrate stiocihometries have to be so too.")
7373
substoich = typeof(prodstoich)()
7474
end
7575
if isnothing(prods)
7676
prods = Vector{Operation}()
77-
isnothing(prodstoich) && error("If products are nothing, product stiocihometries have to be so too.")
77+
!isnothing(prodstoich) && error("If products are nothing, product stiocihometries have to be so too.")
7878
prodstoich = typeof(substoich)()
7979
end
8080
ns = isnothing(netstoich) ? get_netstoich(subs, prods, substoich, prodstoich) : netstoich
@@ -120,15 +120,15 @@ Continuing from the example in the [`Reaction`](@ref) definition:
120120
rs = ReactionSystem(rxs, t, [A,B,C,D], k)
121121
```
122122
"""
123-
struct ReactionSystem{U,V,W,X} <: AbstractSystem
123+
struct ReactionSystem <: AbstractSystem
124124
"""The reactions defining the system."""
125-
eqs::Vector{Reaction{U,V}}
125+
eqs::Vector{Reaction}
126126
"""Independent variable (usually time)."""
127-
iv::Variable{X}
127+
iv::Variable
128128
"""Dependent (state) variables representing amount of each species."""
129-
states::Vector{Variable{W}}
129+
states::Vector{Variable}
130130
"""Parameter variables."""
131-
ps::Vector{Variable{X}}
131+
ps::Vector{Variable}
132132
"""The name of the system"""
133133
name::Symbol
134134
"""systems: The internal systems"""

test/reactionsystem.jl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ G2 = sf.g(u,p,t)
8484
# test with JumpSystem
8585
js = convert(JumpSystem, rs)
8686

87-
@test all(map(i -> typeof(js.eqs[i]) <: DiffEqJump.MassActionJump, [1]))
88-
@test all(map(i -> typeof(js.eqs[i]) <: DiffEqJump.ConstantRateJump, 2:5))
89-
@test all(map(i -> typeof(js.eqs[i]) <: DiffEqJump.VariableRateJump, 6:7))
87+
midxs = 1:14
88+
cidxs = 15:18
89+
vidxs = 19:20
90+
@test all(map(i -> typeof(js.eqs[i]) <: DiffEqJump.MassActionJump, midxs))
91+
@test all(map(i -> typeof(js.eqs[i]) <: DiffEqJump.ConstantRateJump, cidxs))
92+
@test all(map(i -> typeof(js.eqs[i]) <: DiffEqJump.VariableRateJump, vidxs))
9093

9194
pars = rand(length(k)); u0 = rand(1:10,4); time = rand();
9295
jumps = Vector{Union{ConstantRateJump, MassActionJump, VariableRateJump}}(undef,length(rxs))
@@ -116,21 +119,21 @@ jumps[20] = VariableRateJump((u,p,t) -> p[20]*t*u[1]*binomial(u[2],2)*u[3], inte
116119

117120
statetoid = Dict(convert(Variable,state) => i for (i,state) in enumerate(states(js)))
118121
parammap = map((x,y)->Pair(x(),y),parameters(js),pars)
119-
maj = MT.assemble_maj(js.eqs[1], statetoid, ModelingToolkit.substituter(first.(parammap), last.(parammap)),eltype(pars))
120-
for i = 1:14
121-
@test abs(jumps[i].scaled_rates - maj.scaled_rates[i]) < 100*eps()
122-
@test jumps[i].reactant_stoch == maj.reactant_stoch[i]
123-
@test jumps[i].net_stoch == maj.net_stoch[i]
122+
for i in midxs
123+
maj = MT.assemble_maj(js.eqs[i], statetoid, ModelingToolkit.substituter(parammap),eltype(pars))
124+
@test abs(jumps[i].scaled_rates - maj.scaled_rates) < 100*eps()
125+
@test jumps[i].reactant_stoch == maj.reactant_stoch
126+
@test jumps[i].net_stoch == maj.net_stoch
124127
end
125-
for i = 15:18
126-
crj = MT.assemble_crj(js, js.eqs[i-13], statetoid)
128+
for i in cidxs
129+
crj = MT.assemble_crj(js, js.eqs[i], statetoid)
127130
@test isapprox(crj.rate(u0,p,time), jumps[i].rate(u0,p,time))
128131
fake_integrator1 = (u=zeros(4),p=p,t=0); fake_integrator2 = deepcopy(fake_integrator1);
129132
crj.affect!(fake_integrator1); jumps[i].affect!(fake_integrator2);
130133
@test fake_integrator1 == fake_integrator2
131134
end
132-
for i = 19:20
133-
crj = MT.assemble_vrj(js, js.eqs[i-13], statetoid)
135+
for i in vidxs
136+
crj = MT.assemble_vrj(js, js.eqs[i], statetoid)
134137
@test isapprox(crj.rate(u0,p,time), jumps[i].rate(u0,p,time))
135138
fake_integrator1 = (u=zeros(4),p=p,t=0.); fake_integrator2 = deepcopy(fake_integrator1);
136139
crj.affect!(fake_integrator1); jumps[i].affect!(fake_integrator2);

0 commit comments

Comments
 (0)