Skip to content

Commit c36aad2

Browse files
authored
[docs] clarify broadcasting in constraint documentation (#594)
1 parent 174d617 commit c36aad2

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

docs/src/manual/types.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ constraint = x == 0
100100
constraint = x >= 1
101101
```
102102

103+
Note that constraints apply elementwise automatically; that is, `x >= 1` means
104+
that `x[i, j] >= 1` for `i in 1:5` and `j in 1:5`. Consequently, broadcasting
105+
should not be used to constrain arrays, that is, use `x >= y` instead of
106+
`x .>= y`.
107+
103108
Matrices can also be constrained to be positive semidefinite.
104109

105110
```julia

test/test_utilities.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,15 @@ function test_variable_primal_start()
12821282
return
12831283
end
12841284

1285+
function test_broadcasting()
1286+
A = [1 2; 3 4]
1287+
x = Variable(2)
1288+
y = [1.1, 2.2]
1289+
@test_throws MethodError (A * x) .<= y
1290+
@test sprint(show, x .== y) == sprint(show, [x[i] == y[i] for i in 1:2])
1291+
return
1292+
end
1293+
12851294
end # TestUtilities
12861295

12871296
TestUtilities.runtests()

0 commit comments

Comments
 (0)