Skip to content

Commit d59dfcc

Browse files
Merge pull request #1051 from AayushSabharwal/as/linprob-observed
feat: add `observed` field to `SymbolicLinearInterface`
2 parents 039e92e + 0965d41 commit d59dfcc

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/problems/linear_problems.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A utility struct stored inside `LinearProblem` to enable a symbolic interface.
77
88
$(TYPEDFIELDS)
99
"""
10-
struct SymbolicLinearInterface{F1, F2, S, M}
10+
struct SymbolicLinearInterface{F1, F2, S, O, M}
1111
"""
1212
A function which takes `A` and the parameter object `p` and updates `A` in-place.
1313
"""
@@ -21,6 +21,11 @@ struct SymbolicLinearInterface{F1, F2, S, M}
2121
"""
2222
sys::S
2323
"""
24+
A function which when given a symbolic expression returns a function `(u, p)`
25+
that computes the expression.
26+
"""
27+
observed::O
28+
"""
2429
Arbitrary metadata useful for the symbolic backend.
2530
"""
2631
metadata::M
@@ -31,6 +36,17 @@ has_sys(::SymbolicLinearInterface) = true
3136

3237
SymbolicIndexingInterface.symbolic_container(sli::SymbolicLinearInterface) = sli.sys
3338

39+
function SymbolicIndexingInterface.observed(fn::SymbolicLinearInterface, sym)
40+
if fn.observed !== nothing
41+
fn.observed(sym)
42+
elseif fn.sys !== nothing
43+
SymbolicIndexingInterface.observed(fn.sys, sym)
44+
else
45+
error("This `LinearProblem` does not support computing observed quantities.")
46+
end
47+
end
48+
49+
3450
@doc doc"""
3551
3652
Defines a linear system problem.

0 commit comments

Comments
 (0)