Skip to content

Commit cc6abde

Browse files
committed
fix iteration order, add test that catches catalyst case
1 parent 37e9689 commit cc6abde

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

src/systems/diffeqs/sdesystem.jl

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,30 +246,56 @@ function Base.:(==)(sys1::SDESystem, sys2::SDESystem)
246246
end
247247

248248
function __num_isdiag_noise(mat)
249-
for j in axes(mat, 2)
249+
for i in axes(mat, 1)
250250
nnz = 0
251-
for i in axes(mat, 1)
251+
for j in axes(mat, 2)
252252
if !isequal(mat[i, j], 0)
253253
nnz += 1
254254
end
255255
end
256256
if nnz > 1
257-
return false
257+
return (false)
258258
end
259259
end
260260
true
261261
end
262262
function __get_num_diag_noise(mat)
263-
map(axes(mat, 2)) do j
264-
for i in axes(mat, 1)
265-
if !isequal(mat[i, j], 0)
266-
return mat[i, j]
263+
map(axes(mat, 1)) do i
264+
for j in axes(mat, 2)
265+
mij = mat[i, j]
266+
if !isequal(mij, 0)
267+
return mij
267268
end
268269
end
269270
0
270271
end
271272
end
272273

274+
# function __num_isdiag_noise(mat)
275+
# for j in axes(mat, 2)
276+
# nnz = 0
277+
# for i in axes(mat, 1)
278+
# if !isequal(mat[i, j], 0)
279+
# nnz += 1
280+
# end
281+
# end
282+
# if nnz > 1
283+
# return false
284+
# end
285+
# end
286+
# true
287+
# end
288+
# function __get_num_diag_noise(mat)
289+
# map(axes(mat, 2)) do j
290+
# for i in axes(mat, 1)
291+
# if !isequal(mat[i, j], 0)
292+
# return mat[i, j]
293+
# end
294+
# end
295+
# 0
296+
# end
297+
# end
298+
273299
function generate_diffusion_function(sys::SDESystem, dvs = unknowns(sys),
274300
ps = full_parameters(sys); isdde = false, kwargs...)
275301
eqs = get_noiseeqs(sys)

test/sdesystem.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,10 @@ end
726726
@testset "Non-diagonal noise check" begin
727727
@parameters σ ρ β
728728
@variables x(tt) y(tt) z(tt)
729-
@brownian a b c
730-
eqs = [D(x) ~ σ * (y - x) + 0.1a * x + 0.1b * y,
731-
D(y) ~ x *- z) - y + 0.1b * y,
732-
D(z) ~ x * y - β * z + 0.1c * z]
729+
@brownian a b c d e f
730+
eqs = [D(x) ~ σ * (y - x) + 0.1a * x + d,
731+
D(y) ~ x *- z) - y + 0.1b * y + e,
732+
D(z) ~ x * y - β * z + 0.1c * z + f]
733733
@mtkbuild de = System(eqs, tt)
734734

735735
u0map = [
@@ -749,6 +749,7 @@ end
749749
@test_throws ErrorException solve(prob, SOSRI()).retcode==ReturnCode.Success
750750
# ImplicitEM does work for non-diagonal noise
751751
@test solve(prob, ImplicitEM()).retcode == ReturnCode.Success
752+
@test size(ModelingToolkit.get_noiseeqs(de)) == (3, 6)
752753
end
753754

754755
@testset "Diagonal noise, less brownians than equations" begin

0 commit comments

Comments
 (0)