Skip to content

Commit 5ba40ab

Browse files
committed
Update
1 parent 6271c21 commit 5ba40ab

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

src/Test/test_basic_constraint.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,24 +176,28 @@ function _set(::Type{T}, ::Type{MOI.HyperRectangle}) where {T}
176176
end
177177

178178
function _set(::Type{T}, ::Type{MOI.VectorNonlinearOracle}) where {T}
179-
return MOI.VectorNonlinearOracle(;
179+
set = MOI.VectorNonlinearOracle(;
180180
dimension = 3,
181-
l = [0.0, 0.0],
182-
u = [1.0, 0.0],
181+
l = T[0, 0],
182+
u = T[1, 0],
183183
eval_f = (ret, x) -> begin
184184
ret[1] = x[2]^2
185185
ret[2] = x[3]^2 + x[4]^3 - x[1]
186186
return
187187
end,
188188
jacobian_structure = [(1, 2), (2, 1), (2, 3), (2, 4)],
189189
eval_jacobian = (ret, x) -> begin
190-
ret[1] = 2.0 * x[2]
191-
ret[2] = -1.0
192-
ret[3] = 2.0 * x[3]
193-
ret[4] = 3.0 * x[4]^2
190+
ret[1] = T(2) * x[2]
191+
ret[2] = -T(1)
192+
ret[3] = T(2) * x[3]
193+
ret[4] = T(3) * x[4]^2
194194
return
195195
end,
196196
)
197+
x, ret_f, ret_J = T[1, 2, 3, 4, 5], T[0, 0], T[0, 0, 0, 0]
198+
set.eval_f(ret_f, x)
199+
set.eval_jacobian(ret_J, x)
200+
return set
197201
end
198202

199203
function _test_function_modification(

src/Test/test_nonlinear.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,6 +2268,16 @@ function test_vector_nonlinear_oracle(
22682268
end,
22692269
)
22702270
@test MOI.dimension(set) == 5
2271+
x = T[1, 2, 3, 4, 5]
2272+
ret = T[0, 0]
2273+
set.eval_f(ret, x)
2274+
@test ret == T[-3, 26]
2275+
ret = T[0, 0, 0, 0, 0]
2276+
set.eval_jacobian(ret, x)
2277+
@test ret == T[2, 4, 27, -1, -1]
2278+
ret = T[0, 0, 0]
2279+
set.eval_hessian_lagrangian(ret, x, T[2, 3])
2280+
@test ret == T[4, 6, 54]
22712281
x, y = MOI.add_variables(model, 3), MOI.add_variables(model, 2)
22722282
MOI.add_constraints.(model, x, MOI.EqualTo.(T(1):T(3)))
22732283
c = MOI.add_constraint(model, MOI.VectorOfVariables([x; y]), set)
@@ -2331,6 +2341,15 @@ function test_vector_nonlinear_oracle_no_hessian(
23312341
end,
23322342
)
23332343
@test MOI.dimension(set) == 5
2344+
x = T[1, 2, 3, 4, 5]
2345+
ret = T[0, 0]
2346+
set.eval_f(ret, x)
2347+
@test ret == T[-3, 26]
2348+
ret = T[0, 0, 0, 0, 0]
2349+
set.eval_jacobian(ret, x)
2350+
@test ret == T[2, 4, 27, -1, -1]
2351+
@test isempty(set.hessian_lagrangian_structure)
2352+
@test set.eval_hessian_lagrangian === nothing
23342353
x, y = MOI.add_variables(model, 3), MOI.add_variables(model, 2)
23352354
MOI.add_constraints.(model, x, MOI.EqualTo.(T(1):T(3)))
23362355
c = MOI.add_constraint(model, MOI.VectorOfVariables([x; y]), set)

0 commit comments

Comments
 (0)