Skip to content

Commit bce6c14

Browse files
committed
Use square_getindex
1 parent c4ff051 commit bce6c14

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

src/Sets/polynomials.jl

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ function zero_eliminate(set::ConvexPolySet, I)
6363
vars = space_variables(set)[I]
6464
K = findall(mono -> all(var -> iszero(degree(mono, var)), vars),
6565
set.p.basis.monomials)
66-
M = set.p.Q[K, K]
67-
Q = SumOfSquares.SymMatrix([M[i, j] for j in 1:length(K) for i in 1:j],
68-
length(K))
66+
Q = SumOfSquares.square_getindex(set.p.Q, K)
6967
monos = set.p.basis.monomials[K]
7068
J = setdiff(1:dimension(set), I)
7169
monos = DynamicPolynomials.MonomialVector(monos.vars[J],

test/Sets.jl

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Test
2+
using DynamicPolynomials
3+
using SetProg, SetProg.Sets
4+
5+
@testset "Sets" begin
6+
@testset "zero_eliminate" begin
7+
@polyvar x y z
8+
p = SetProg.GramMatrix{Float64}((i, j) -> convert(Float64, i + j),
9+
monovec([x, y, z]))
10+
set = Sets.ConvexPolySet(2, p, nothing)
11+
el = Sets.zero_eliminate(set, 1:2)
12+
@test el.p.Q == 6ones(1, 1)
13+
el = Sets.zero_eliminate(set, 3:3)
14+
@test el.p.Q == [2 3; 3 4]
15+
el = Sets.zero_eliminate(set, 2:2)
16+
@test el.p.Q == [2 4; 4 6]
17+
end
18+
end

test/Tests/Tests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Tests
22

33
using JuMP
44
import GLPK
5-
const lp_solver = optimizer_with_attributes(GLPK.Optimizer, "presolve" => GLPK.ON)
5+
const lp_solver = optimizer_with_attributes(GLPK.Optimizer, "presolve" => GLPK.GLP_ON)
66
import Polyhedra
77
const lib = Polyhedra.DefaultLibrary{Float64}(lp_solver)
88

test/recipes.jl

+13-11
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ end
5858
recipe_test(circle,
5959
[1.0, 0.0, -1.0, 0.0], [0.0, 1.0, 0.0, -1.0])
6060
recipe_test(Sets.polar(circle),
61-
[-1.0, 1.0, 1.0, -1.0, -1.0], [1.0, 1.0, -1.0, -1.0, 1.0])
61+
[-1.0, -1.0, 1.0, 1.0, -1.0],
62+
[-1.0, 1.0, 1.0, -1.0, -1.0])
6263
end
6364
@testset "Scaled circle" begin
6465
p = SetProg.GramMatrix{Float64}((i, j) -> 2convert(Float64, i == j),
@@ -67,8 +68,8 @@ end
6768
recipe_test(circle,
6869
[1/√2, 0.0, -1/√2, 0.0], [0.0, 1/√2, 0.0, -1/√2])
6970
recipe_test(Sets.polar(circle),
70-
[-√2, 2, 2, -2, -√2],
71-
[ 2, 2, -2, -√2, 2])
71+
[-√2, -2, 2, 2, -√2],
72+
[-2, 2, 2, -√2, -2])
7273
end
7374
@testset "Non-homogeneous Circle" begin
7475
@testset "Basic" begin
@@ -77,17 +78,17 @@ end
7778
0 0 1], monovec([z, x, y]))
7879
shifted_circle = SetProg.perspective_dual_polyset(2, q, SetProg.InteriorPoint(zeros(2)), z, [x, y])
7980
recipe_test(shifted_circle,
80-
[-1.0, 1.0, 1.0, -1.0, -1.0],
81-
[1.0, 1.0, -1.0, -1.0, 1.0])
81+
[-1.0, -1.0, 1.0, 1.0, -1.0],
82+
[-1.0, 1.0, 1.0, -1.0, -1.0])
8283
end
8384
@testset "Scaled" begin
8485
q = SetProg.GramMatrix(Float64[0 0 0
8586
0 2 0
8687
0 0 2], monovec([z, x, y]))
8788
shifted_circle = SetProg.perspective_dual_polyset(2, q, SetProg.InteriorPoint(zeros(2)), z, [x, y])
8889
recipe_test(shifted_circle,
89-
[-√2, 2, 2, -2, -√2],
90-
[ 2, 2, -2, -√2, 2])
90+
[-√2, -2, 2, 2, -√2],
91+
[-2, 2, 2, -√2, -2])
9192
end
9293
@testset "z-Scaled" begin
9394
# z: -1/2 + 1 = 1/2
@@ -96,8 +97,8 @@ end
9697
0 0 1], monovec([z, x, y]))
9798
shifted_circle = SetProg.perspective_dual_polyset(2, q, SetProg.InteriorPoint(zeros(2)), z, [x, y])
9899
recipe_test(shifted_circle,
99-
[-√2, 2, 2, -2, -√2],
100-
[ 2, 2, -2, -√2, 2])
100+
[-√2, -2, 2, 2, -√2],
101+
[-2, 2, 2, -√2, -2])
101102
end
102103
end
103104
end
@@ -129,7 +130,8 @@ end
129130
β = 0.732050807568877
130131
recipe_test(
131132
Sets.polar(set),
132-
[-1.0, -α, 0.0, 1.0, 1.0, β, -1.0, -1.0],
133-
[α, 1.0, 1.0, 0.0, -β, -1.0, -1.0, α], 8)
133+
[-1.0, -1.0, -α, 0.0, 1.0, 1.0, β, -1.0],
134+
[-1.0, α, 1.0, 1.0, 0.0, -β, -1.0, -1.0],
135+
8)
134136
end
135137
end

test/runtests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const lp_solver = GLPK.Optimizer
33
import Polyhedra
44
const lib = Polyhedra.DefaultLibrary{Float64}(lp_solver)
55

6+
include("Sets.jl")
67
include("apply.jl")
78
include("variables.jl")
89
include("L1_heuristic.jl")

0 commit comments

Comments
 (0)