@@ -80,10 +80,10 @@ function DiffEqBase.solve(jump_prob::JumpProblem, alg::SimpleTauLeaping;
8080 interp = DiffEqBase. ConstantInterpolation (t, u))
8181end
8282
83- function compute_hor (nu )
84- hor = zeros (Int, size (nu, 2 ) )
85- for j in 1 : size (nu, 2 )
86- order = sum (abs (stoich) for stoich in nu[:, j] if stoich < 0 ; init= 0 )
83+ function compute_hor (reactant_stoch, numjumps )
84+ hor = zeros (Int, numjumps )
85+ for j in 1 : numjumps
86+ order = sum (stoch for (spec_idx, stoch) in reactant_stoch[j] ; init= 0 )
8787 if order > 3
8888 error (" Reaction $j has order $order , which is not supported (maximum order is 3)." )
8989 end
@@ -99,11 +99,11 @@ function compute_gi(u, nu, hor, i)
9999 if hor[j] == 1
100100 max_gi = max (max_gi, 1 )
101101 elseif hor[j] == 2 || hor[j] == 3
102- stoich = abs (nu[i, j])
103- if stoich >= 2
104- gi = 2 / stoich + 1 / (stoich - 1 )
102+ stoch = abs (nu[i, j])
103+ if stoch >= 2
104+ gi = 2 / stoch + 1 / (stoch - 1 )
105105 max_gi = max (max_gi, ceil (Int, gi))
106- elseif stoich == 1
106+ elseif stoch == 1
107107 max_gi = max (max_gi, hor[j])
108108 end
109109 end
@@ -167,14 +167,16 @@ function DiffEqBase.solve(jump_prob::JumpProblem, alg::SimpleAdaptiveTauLeaping;
167167 t_end = tspan[2 ]
168168 epsilon = alg. epsilon
169169
170- # Extract stoichiometry once from MassActionJump
170+ # Extract stochiometry once from MassActionJump
171171 nu = zeros (float (eltype (u0)), length (u0), numjumps)
172172 for j in 1 : numjumps
173- for (spec_idx, stoich ) in maj. net_stoch[j]
174- nu[spec_idx, j] = stoich
173+ for (spec_idx, stoch ) in maj. net_stoch[j]
174+ nu[spec_idx, j] = stoch
175175 end
176176 end
177- hor = compute_hor (nu)
177+ # Extract reactant stochiometry for hor
178+ reactant_stoch = maj. reactant_stoch
179+ hor = compute_hor (reactant_stoch, numjumps)
178180
179181 # Set up saveat_times
180182 saveat_times = nothing
@@ -201,8 +203,8 @@ function DiffEqBase.solve(jump_prob::JumpProblem, alg::SimpleAdaptiveTauLeaping;
201203 c (du, u_current, p, t_current, counts, nothing )
202204 else
203205 for j in 1 : numjumps
204- for (spec_idx, stoich ) in maj. net_stoch[j]
205- du[spec_idx] += stoich * counts[j]
206+ for (spec_idx, stoch ) in maj. net_stoch[j]
207+ du[spec_idx] += stoch * counts[j]
206208 end
207209 end
208210 end
0 commit comments