Skip to content

Commit 0d1d90a

Browse files
authored
[docs] fix flakey doctest in variables.md (#3425)
1 parent ff69293 commit 0d1d90a

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

docs/src/manual/variables.md

+7-11
Original file line numberDiff line numberDiff line change
@@ -1222,19 +1222,15 @@ ERROR: MethodError: no method matching set_lower_bound(::AffExpr, ::Float64)
12221222
[...]
12231223
```
12241224

1225-
However, you can convert the matrix into one in which the upper triangular
1226-
elements are `VariableRef` and the lower triangular elements are `AffExpr` as
1227-
follows:
1225+
Instead, you can convert an upper-triangular elements to a variable as follows:
12281226
```jldoctest skewsymmetric
1229-
julia> y = Union{VariableRef,AffExpr}[
1230-
j > i ? first(keys(x[i, j].terms)) : x[i, j]
1231-
for i in 1:size(x, 1), j in 1:size(x, 2)
1232-
]
1233-
2×2 Matrix{Union{VariableRef, AffExpr}}:
1234-
0 x[1,2]
1235-
-x[1,2] 0
1227+
julia> to_variable(x::AffExpr) = first(keys(x.terms))
1228+
to_variable (generic function with 1 method)
1229+
1230+
julia> to_variable(x[1, 2])
1231+
x[1,2]
12361232
1237-
julia> set_lower_bound(y[1, 2], 0.0)
1233+
julia> set_lower_bound(to_variable(x[1, 2]), 0.0)
12381234
```
12391235

12401236
### Example: Hermitian positive semidefinite variables

0 commit comments

Comments
 (0)