Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Oct 30, 2023
1 parent 2fe0a5a commit 8874092
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
19 changes: 0 additions & 19 deletions docs/src/manual/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -1214,25 +1214,6 @@ julia> @variable(model, x[1:2, 1:2] in SkewSymmetricMatrixSpace())
`model`; the remaining elements in `x` are linear transformations of the
single variable.

Because the returned matrix `x` is `Matrix{AffExpr}`, you cannot use
variable-related functions on its elements:
```jldoctest skewsymmetric
julia> set_lower_bound(x[1, 2], 0.0)
ERROR: MethodError: no method matching set_lower_bound(::AffExpr, ::Float64)
[...]
```

Instead, you can convert an upper-triangular elements to a variable as follows:
```jldoctest skewsymmetric
julia> to_variable(x::AffExpr) = first(keys(x.terms))
to_variable (generic function with 1 method)
julia> to_variable(x[1, 2])
x[1,2]
julia> set_lower_bound(to_variable(x[1, 2]), 0.0)
```

### Example: Hermitian positive semidefinite variables

Declare a matrix of JuMP variables to be Hermitian positive semidefinite using
Expand Down
6 changes: 4 additions & 2 deletions src/aff_expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -824,13 +824,15 @@ function _eval_as_variable(f::F, x::GenericAffExpr, args...) where {F}
"Cannot call $f with $x because it is not a real-valued affine " *
"expression of one variable.",
)
elseif !isone(first(values(x.terms)))
end
variable, coefficient = first(x.terms)
if !isone(coefficient)
error(
"Cannot call $f with $x because it is not a real-valued affine " *
"expression of one variable with a coefficient of `+1`.",
)
end
return f(first(keys(x.terms)), args...)
return f(variable, args...)
end

function _eval_as_variable(
Expand Down

0 comments on commit 8874092

Please sign in to comment.