Skip to content

Commit

Permalink
[docs] document how to support operators with several vector arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Nov 20, 2023
1 parent 283a99d commit e5905c0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/src/manual/nonlinear.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,22 @@ f(x::Vector) = sum(x[i]^i for i in 1:length(x))
@objective(model, Min, op_f(x...))
```

If the operator takes several vector inputs, write a function which takes the
splatted arguments and reconstructs the required vector inputs:
```@repl
using JuMP
model = Model();
@variable(model, x[1:2]);
@variable(model, y[1:2]);
@variable(model, z);
f(x::Vector, y::Vector, z) = sum((x[i] * y[i])^z for i in 1:2)
f(x, y, z)
f_splat(args...) = f(collect(args[1:2]), collect(args[3:4]), args[5])
f_splat(x..., y..., z)
@operator(model, op_f, 5, f_splat)
@objective(model, Min, op_f(x..., y..., z))
```

### Automatic differentiation

JuMP does not support black-box optimization, so all user-defined operators must
Expand Down

0 comments on commit e5905c0

Please sign in to comment.