Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] document how to support operators with several vector arguments #3577

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
odow marked this conversation as resolved.
Show resolved Hide resolved
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
Loading