Skip to content

Commit 8b89108

Browse files
committed
exprs_occur_in
1 parent 70d876b commit 8b89108

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/direct.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ function jacobian_sparsity(du, u)
7979
sparse(I, J, true, length(du), length(u))
8080
end
8181

82+
"""
83+
exprs_occur_in(exprs::Vector, expr)
84+
85+
Return an array of booleans `finds` where `finds[i]` is true if `exprs[i]` occurs in `expr`
86+
false otherwise.
87+
"""
88+
function exprs_occur_in(exprs::Vector, expr)
89+
vec(jacobian_sparsity([expr], exprs))
90+
end
91+
8292
"""
8393
```julia
8494
hessian(O, vars::AbstractVector; simplify = true)

test/direct.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ reference_jac = sparse(ModelingToolkit.jacobian(du, [x,y,z]))
3636

3737
@test findnz(ModelingToolkit.jacobian_sparsity(du, [x,y,z]))[[1,2]] == findnz(reference_jac)[[1,2]]
3838

39+
let
40+
@variables t x(t) y(t) z(t)
41+
@test ModelingToolkit.exprs_occur_in([x,y,z], x^2*y) == [true, true, false]
42+
end
43+
3944
@test isequal(ModelingToolkit.sparsejacobian(du, [x,y,z]), reference_jac)
4045

4146
using ModelingToolkit

0 commit comments

Comments
 (0)