Skip to content

Commit 36f7bfe

Browse files
committed
WIP
1 parent 86bfa1d commit 36f7bfe

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/Nonlinear/ReverseAD/mathoptinterface_api.jl

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,21 @@ function MOI.initialize(d::NLPEvaluator, requested_features::Vector{Symbol})
4343
d.want_hess = :Hess in requested_features
4444
want_hess_storage = (:HessVec in requested_features) || d.want_hess
4545
coloring_storage = Coloring.IndexedSet(N)
46+
#
4647
max_expr_length = 0
4748
max_expr_with_sub_length = 0
48-
#
49-
main_expressions = [c.expression.nodes for (_, c) in d.data.constraints]
49+
max_chunk = 1
50+
main_expressions = Vector{Nonlinear.Node}[]
5051
if d.data.objective !== nothing
51-
pushfirst!(main_expressions, something(d.data.objective).nodes)
52+
objective = something(d.data.objective)
53+
max_expr_length = max(max_expr_length, length(objective.nodes))
54+
max_chunk = max(max_chunk, size(objective.seed_matrix, 2))
55+
push!(main_expressions, objective.nodes)
56+
end
57+
for (_, c) in d.data.constraints
58+
max_expr_length = max(max_expr_length, length(c.expression.nodes))
59+
max_chunk = max(max_chunk, size(c.expression.seed_matrix, 2))
60+
push!(main_expressions, c.expression.nodes)
5261
end
5362
d.subexpression_order, individual_order = _order_subexpressions(
5463
main_expressions,
@@ -100,11 +109,15 @@ function MOI.initialize(d::NLPEvaluator, requested_features::Vector{Symbol})
100109
subexpression_edgelist[k] = edgelist
101110
end
102111
end
103-
max_chunk = 1
104112
if d.data.objective !== nothing
105113
objective = _FunctionStorage(
106-
main_expressions[1],
107-
something(d.data.objective).values,
114+
_SubexpressionStorage(
115+
something(d.data.objective),
116+
d.data.expressions[k],
117+
d.subexpression_linearity,
118+
moi_index_to_consecutive_index,
119+
zeros(max_chunk * length(d.data.expressions[k].nodes)),
120+
)
108121
N,
109122
coloring_storage,
110123
d.want_hess,
@@ -113,10 +126,7 @@ function MOI.initialize(d::NLPEvaluator, requested_features::Vector{Symbol})
113126
d.subexpression_linearity,
114127
subexpression_edgelist,
115128
subexpression_variables,
116-
moi_index_to_consecutive_index,
117129
)
118-
max_expr_length = max(max_expr_length, length(objective.nodes))
119-
max_chunk = max(max_chunk, size(objective.seed_matrix, 2))
120130
d.objective = objective
121131
end
122132
for (k, (_, constraint)) in enumerate(d.data.constraints)

0 commit comments

Comments
 (0)