Skip to content

Commit f87585c

Browse files
authored
[docs] improve docstring of VectorNonlinearOracle (#2876)
1 parent b9708e6 commit f87585c

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/sets.jl

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,11 @@ eval_jacobian(ret::AbstractVector, x::AbstractVector)::Nothing
27022702
which fills the sparse Jacobian ``\\nabla f(x)`` into `ret`.
27032703
27042704
The one-indexed sparsity structure must be provided in the `jacobian_structure`
2705-
argument.
2705+
argument and it must be independent of the point ``x``.
2706+
2707+
`jacobian_structure` is not required to be sorted and it may contain duplicates,
2708+
in which case the solver will combine the corresponding non-zero values in `ret`
2709+
by adding them together.
27062710
27072711
## Hessian
27082712
@@ -2723,15 +2727,23 @@ which fills the sparse Hessian of the Lagrangian ``\\sum \\mu_i \\nabla^2 f_i(x)
27232727
into `ret`.
27242728
27252729
The one-indexed sparsity structure must be provided in the
2726-
`hessian_lagrangian_structure` argument.
2730+
`hessian_lagrangian_structure` argument and it must be independent of the point
2731+
``x``.
2732+
2733+
`hessian_lagrangian_structure` is not required to be sorted and it may contain
2734+
duplicates, in which case the solver will combine the corresponding non-zero
2735+
values in `ret` by adding them together.
2736+
2737+
Any mix of lower and upper-triangular indices is valid. Elements `(i, j)` and
2738+
`(j, i)`, if both present, are treated as duplicates.
27272739
27282740
## Example
27292741
27302742
To model the set:
27312743
```math
27322744
\\begin{align}
2733-
0 \\le & x^2 \\le 1
2734-
0 \\le & y^2 + z^3 - w \\le 0
2745+
0 \\le & x^2 \\le 1
2746+
0 \\le & y^2 + x \\cdot z^3 - w \\le 0
27352747
\\end{align}
27362748
```
27372749
do
@@ -2744,22 +2756,24 @@ julia> set = MOI.VectorNonlinearOracle(;
27442756
u = [1.0, 0.0],
27452757
eval_f = (ret, x) -> begin
27462758
ret[1] = x[2]^2
2747-
ret[2] = x[3]^2 + x[4]^3 - x[1]
2759+
ret[2] = x[3]^2 + x[2] * x[4]^3 - x[1]
27482760
return
27492761
end,
2750-
jacobian_structure = [(1, 2), (2, 1), (2, 3), (2, 4)],
2762+
jacobian_structure = [(1, 2), (2, 1), (2, 2), (2, 3), (2, 4)],
27512763
eval_jacobian = (ret, x) -> begin
27522764
ret[1] = 2.0 * x[2]
27532765
ret[2] = -1.0
2754-
ret[3] = 2.0 * x[3]
2755-
ret[4] = 3.0 * x[4]^2
2766+
ret[3] = x[4]^3
2767+
ret[4] = 2.0 * x[3]
2768+
ret[5] = 3.0 * x[2] * x[4]^2
27562769
return
27572770
end,
2758-
hessian_lagrangian_structure = [(2, 2), (3, 3), (4, 4)],
2771+
hessian_lagrangian_structure = [(2, 2), (3, 3), (4, 4), (2, 4)],
27592772
eval_hessian_lagrangian = (ret, x, u) -> begin
27602773
ret[1] = 2.0 * u[1]
27612774
ret[2] = 2.0 * u[2]
27622775
ret[3] = 6.0 * x[4] * u[2]
2776+
ret[4] = 3.0 * x[4]^2 * u[2]
27632777
return
27642778
end,
27652779
);

0 commit comments

Comments
 (0)