Skip to content

Commit

Permalink
instead of diag, count non-zero entries in each row
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonProtter committed Jul 21, 2024
1 parent 42370b1 commit c111864
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/systems/systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ function __structural_simplify(sys::AbstractSystem, io = nothing; simplify = fal
@views copyto!(sorted_g_rows[i, :], g[g_row, :])
end
# Fix for https://github.com/SciML/ModelingToolkit.jl/issues/2490
noise_eqs = if isdiag(sorted_g_rows)
diag(sorted_g_rows) # This happens when the user uses N different `@brownian`s for `N` equations
noise_eqs = if all(row -> count(!iszero, row) == 1, eachrow(sorted_g_rows)) # Does each row have only one non-zero entry?
# then the noise is actually diagonal! make vector of non-zero entries.
# This happens when the user uses N different `@brownian`s for `N` equations
reduce(vcat, map(row -> filter(!iszero, row), eachrow(sorted_g_rows)))
elseif sorted_g_rows isa AbstractMatrix && size(sorted_g_rows, 2) == 1
sorted_g_rows[:, 1] # Take a vector slice so solver knows there's no mixing
else
Expand Down
4 changes: 2 additions & 2 deletions test/sdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,8 @@ end
let
@parameters σ ρ β
@variables x(t) y(t) z(t)
@brownian a b c
eqs = [D(x) ~ σ * (y - x) + 0.1c * x,
@brownian a b
eqs = [D(x) ~ σ * (y - x) + 0.1b * x,
D(y) ~ x *- z) - y + 0.1a * y,
D(z) ~ x * y - β * z + 0.1b * z]

Expand Down

0 comments on commit c111864

Please sign in to comment.