Skip to content

Commit 7858cec

Browse files
ericphansonararslan
authored andcommitted
Fix some issues with fix! (#294)
* Fix multiply divide's treatment of ConstVexity() variables * Add test * Move test, add test for 228 * remove extra newline
1 parent 6bccf6a commit 7858cec

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

src/atoms/affine/multiply_divide.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ function conic_form!(x::MultiplyAtom, unique_conic_forms::UniqueConicForms=Uniqu
8080
objective = const_multiplier * objective
8181

8282
# left matrix multiplication
83-
elseif x.children[1].head == :constant
83+
elseif vexity(x.children[1]) == ConstVexity()
8484
objective = conic_form!(x.children[2], unique_conic_forms)
85-
objective = kron(sparse(1.0I, x.size[2], x.size[2]), x.children[1].value) * objective
85+
objective = kron(sparse(1.0I, x.size[2], x.size[2]), evaluate(x.children[1])) * objective
8686
# right matrix multiplication
8787
else
8888
objective = conic_form!(x.children[1], unique_conic_forms)
89-
objective = kron(transpose(x.children[2].value), sparse(1.0I, x.size[1], x.size[1])) * objective
89+
objective = kron(transpose(evaluate(x.children[2])), sparse(1.0I, x.size[1], x.size[1])) * objective
9090
end
9191
cache_conic_form!(unique_conic_forms, x, objective)
9292
end
@@ -158,7 +158,7 @@ function conic_form!(x::DotMultiplyAtom, unique_conic_forms::UniqueConicForms=Un
158158
# promote the size of the coefficient matrix, so eg
159159
# 3 .* x
160160
# works regardless of the size of x
161-
coeff = x.children[1].value .* ones(size(x.children[2]))
161+
coeff = evaluate(x.children[1]) .* ones(size(x.children[2]))
162162
# promote the size of the variable
163163
# we've previously ensured neither x nor y is 1x1
164164
# and that the sizes are compatible,

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ push!(solvers, SCSSolver(verbose=0, eps=1e-6))
3434

3535
@testset "Convex" begin
3636
include("test_utilities.jl")
37+
include("test_const.jl")
3738
include("test_affine.jl")
3839
include("test_lp.jl")
3940
include("test_socp.jl")

test/test_const.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@testset "Constant variables: $solver" for solver in solvers
2+
3+
@testset "Issue #166" begin
4+
# Issue #166
5+
α = Variable(5)
6+
fix!(α, ones(5,1))
7+
8+
# has const vexity, but not at the head
9+
c = (rand(5,5) * α) * ones(1,5)
10+
11+
β = Variable(5)
12+
β.value = ones(5)
13+
14+
problem = minimize(sum(c * β), [β >= 0])
15+
solve!(problem, solver)
16+
@test problem.optval evaluate(sum(c * β)) atol=TOL
17+
@test problem.optval 0.0 atol=TOL
18+
@test β.value zeros(5) atol=TOL
19+
end
20+
21+
@testset "Issue #228" begin
22+
x = Variable(2)
23+
y = Variable(2)
24+
fix!(x, [1 1]')
25+
prob = minimize(y'*(x+[2 2]'), [y>=0])
26+
solve!(prob, solver)
27+
@test prob.optval 0.0 atol = TOL
28+
29+
prob = minimize(x'*y, [y>=0])
30+
solve!(prob, solver)
31+
@test prob.optval 0.0 atol = TOL
32+
end
33+
34+
35+
end

0 commit comments

Comments
 (0)