Skip to content

Commit 477d34c

Browse files
committed
Use non-allocating allequal function
1 parent a1be884 commit 477d34c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ function generate_function(
109109
end
110110
end
111111

112+
@inline function allequal(x)
113+
length(x) < 2 && return true
114+
e1 = first(x)
115+
i = 2
116+
@inbounds for i=2:length(x)
117+
x[i] == e1 || return false
118+
end
119+
return true
120+
end
121+
112122
function generate_difference_cb(sys::ODESystem, dvs = states(sys), ps = parameters(sys);
113123
kwargs...)
114124
eqs = equations(sys)
@@ -134,9 +144,9 @@ function generate_difference_cb(sys::ODESystem, dvs = states(sys), ps = paramete
134144
end
135145

136146
dts = [ operation(eq.lhs).dt for eq in eqs if isdifferenceeq(eq)]
137-
all(dts .== dts[1]) || error("All difference variables should have same time steps.")
147+
allequal(dts) || error("All difference variables should have same time steps.")
138148

139-
PeriodicCallback(cb_affect!, dts[1])
149+
PeriodicCallback(cb_affect!, first(dts))
140150
end
141151

142152
function time_varying_as_func(x, sys)

0 commit comments

Comments
 (0)