Skip to content

Commit b902f7d

Browse files
committed
Implement adjacency_matrix and expression in _FunctionStorage
1 parent ecdf735 commit b902f7d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Nonlinear/ReverseAD/types.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ struct _SubexpressionStorage
4242
end
4343
end
4444

45+
function MOI.Nonlinear.expression(expr::_SubexpressionStorage)
46+
return MOI.Nonlinear.Expression(
47+
expr.nodes,
48+
expr.const_values,
49+
)
50+
end
51+
52+
MOI.Nonlinear.adjacency_matrix(expr::_SubexpressionStorage) = expr.adj
53+
4554
struct _FunctionStorage
4655
nodes::Vector{Nonlinear.Node}
4756
adj::SparseArrays.SparseMatrixCSC{Bool,Int}
@@ -136,6 +145,15 @@ struct _FunctionStorage
136145
end
137146
end
138147

148+
function MOI.Nonlinear.expression(expr::_FunctionStorage)
149+
return MOI.Nonlinear.Expression(
150+
expr.nodes,
151+
expr.const_values,
152+
)
153+
end
154+
155+
MOI.Nonlinear.adjacency_matrix(expr::_FunctionStorage) = expr.adj
156+
139157
"""
140158
NLPEvaluator(
141159
model::Nonlinear.Model,

src/Nonlinear/types.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ tree.
7676
struct Expression
7777
nodes::Vector{Node}
7878
values::Vector{Float64}
79-
Expression() = new(Node[], Float64[])
8079
end
8180

81+
Expression() = Expression(Node[], Float64[])
82+
8283
function Base.:(==)(x::Expression, y::Expression)
8384
return x.nodes == y.nodes && x.values == y.values
8485
end
@@ -107,6 +108,8 @@ struct Constraint
107108
}
108109
end
109110

111+
expression(c::Constraint) = c.expression
112+
110113
"""
111114
ParameterIndex
112115

0 commit comments

Comments
 (0)