@@ -1331,6 +1331,38 @@ function test_eval_user_defined_operator_ForwardDiff_gradient!()
13311331 return
13321332end
13331333
1334+ function test_eval_user_defined_operator_type_mismatch ()
1335+ model = MOI. Nonlinear. Model ()
1336+ x = MOI. VariableIndex .(1 : 4 )
1337+ p = MOI. Nonlinear. add_parameter (model, 2.0 )
1338+ ex = MOI. Nonlinear. add_expression (model, :($ p * $ (x[1 ])))
1339+ ψ (x) = sin (x)
1340+ t (x, y) = x + 3 y
1341+ function ∇t (ret, x, y)
1342+ ret[1 ] = 1 # These are intentionall the wrong type
1343+ ret[2 ] = 3 // 1 # These are intentionall the wrong type
1344+ return
1345+ end
1346+ MOI. Nonlinear. register_operator (model, :ψ , 1 , ψ, x -> - cos (x))
1347+ MOI. Nonlinear. register_operator (model, :t , 2 , t, ∇t)
1348+ MOI. Nonlinear. add_constraint (
1349+ model,
1350+ :($ ex^ 3 + sin ($ (x[2 ])) / ψ ($ (x[2 ])) + t ($ (x[3 ]), $ (x[4 ]))),
1351+ MOI. LessThan (0.0 ),
1352+ )
1353+ d = MOI. Nonlinear. Evaluator (model, MOI. Nonlinear. SparseReverseMode (), x)
1354+ MOI. initialize (d, [:Jac ])
1355+ X = [1.1 , 1.2 , 1.3 , 1.4 ]
1356+ g = [NaN ]
1357+ MOI. eval_constraint (d, g, X)
1358+ @test only (g) ≈ 17.148
1359+ @test MOI. jacobian_structure (d) == [(1 , 1 ), (1 , 2 ), (1 , 3 ), (1 , 4 )]
1360+ J = [NaN , NaN , NaN , NaN ]
1361+ MOI. eval_constraint_jacobian (d, J, X)
1362+ @test J ≈ [2.0 ^ 3 * 3.0 * 1.1 ^ 2 , 0.0 , 1.0 , 3.0 ]
1363+ return
1364+ end
1365+
13341366end # module
13351367
13361368TestReverseAD. runtests ()
0 commit comments