Skip to content

Commit de186be

Browse files
committed
Fix tests
1 parent 99fc171 commit de186be

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/ArrayAD.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ import MathOptInterface as MOI
1111
const Nonlinear = MOI.Nonlinear
1212
import SparseArrays
1313

14+
"""
15+
Mode() <: AbstractAutomaticDifferentiation
16+
17+
Fork of `MOI.Nonlinear.SparseReverseMode` to add array support.
18+
"""
19+
struct Mode <: MOI.Nonlinear.AbstractAutomaticDifferentiation end
20+
21+
function MOI.Nonlinear.Evaluator(
22+
model::MOI.Nonlinear.Model,
23+
::Mode,
24+
ordered_variables::Vector{MOI.VariableIndex},
25+
)
26+
return MOI.Nonlinear.Evaluator(model, NLPEvaluator(model, ordered_variables))
27+
end
28+
29+
1430
# Override basic math functions to return NaN instead of throwing errors.
1531
# This is what NLP solvers expect, and sometimes the results aren't needed
1632
# anyway, because the code may compute derivatives wrt constants.

test/ReverseAD.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ function test_linearity_no_hess()
644644
model = Nonlinear.Model()
645645
ex = Nonlinear.add_expression(model, :($x + 1))
646646
Nonlinear.set_objective(model, ex)
647-
evaluator = Nonlinear.Evaluator(model, Nonlinear.SparseReverseMode(), [x])
647+
evaluator = Nonlinear.Evaluator(model, ArrayAD.Mode(), [x])
648648
MOI.initialize(evaluator, [:Grad, :Jac])
649649
# We initialized without the need for the hessian so
650650
# the linearity shouldn't be computed.
@@ -1248,7 +1248,7 @@ end
12481248
function test_unsafe_vector_view()
12491249
x = Float64[]
12501250
GC.@preserve x begin
1251-
view = MOI.Nonlinear.ArrayAD._UnsafeVectorView(x, 3)
1251+
view = ArrayAD._UnsafeVectorView(x, 3)
12521252
@test length(x) == 3
12531253
view[2] = 1.0
12541254
@test x[2] == 1.0
@@ -1389,12 +1389,12 @@ end
13891389
function test_generate_hessian_slice_inner()
13901390
# Test that it evaluates without error. The code contents are tested
13911391
# elsewhere.
1392-
MOI.Nonlinear.ArrayAD._generate_hessian_slice_inner()
1392+
ArrayAD._generate_hessian_slice_inner()
13931393
d = ex = nothing # These arguments are untyped and not needed for this test
1394-
for id in [0, MOI.Nonlinear.ArrayAD.MAX_CHUNK + 1]
1394+
for id in [0, ArrayAD.MAX_CHUNK + 1]
13951395
@test_throws(
13961396
ErrorException("Invalid chunk size: $id"),
1397-
MOI.Nonlinear.ArrayAD._hessian_slice_inner(d, ex, id),
1397+
ArrayAD._hessian_slice_inner(d, ex, id),
13981398
)
13991399
end
14001400
return

0 commit comments

Comments
 (0)