From 0dc1f0d97537f65832a36894000d6a25d195ef55 Mon Sep 17 00:00:00 2001 From: mforets Date: Wed, 3 Jul 2019 14:25:28 -0300 Subject: [PATCH 1/4] correct sizehint --- src/AbstractPolytope.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AbstractPolytope.jl b/src/AbstractPolytope.jl index 5608788084..69ce9aafed 100644 --- a/src/AbstractPolytope.jl +++ b/src/AbstractPolytope.jl @@ -165,7 +165,7 @@ function minkowski_sum(P1::AbstractPolytope{N}, P2::AbstractPolytope{N}; vlist1, vlist2 = vertices_list(P1), vertices_list(P2) n, m = length(vlist1), length(vlist2) Vout = Vector{Vector{N}}() - sizehint!(Vout, n + m) + sizehint!(Vout, n * m) for vi in vlist1 for vj in vlist2 push!(Vout, vi + vj) From 166397eefdbaa8f6de5c364bd3c0700fee7b4784 Mon Sep 17 00:00:00 2001 From: mforets Date: Wed, 3 Jul 2019 14:33:37 -0300 Subject: [PATCH 2/4] refactor msum input vertices call --- src/AbstractPolytope.jl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/AbstractPolytope.jl b/src/AbstractPolytope.jl index 69ce9aafed..91bb6597b1 100644 --- a/src/AbstractPolytope.jl +++ b/src/AbstractPolytope.jl @@ -162,7 +162,7 @@ function minkowski_sum(P1::AbstractPolytope{N}, P2::AbstractPolytope{N}; @assert dim(P1) == dim(P2) "cannot compute the Minkowski sum between a polyotope " * "of dimension $(dim(P1)) and a polytope of dimension $((dim(P2)))" - vlist1, vlist2 = vertices_list(P1), vertices_list(P2) + vlist1, vlist2 = _minkowski_sum_input_vertices(P1, P2, backend) n, m = length(vlist1), length(vlist2) Vout = Vector{Vector{N}}() sizehint!(Vout, n * m) @@ -181,6 +181,18 @@ function minkowski_sum(P1::AbstractPolytope{N}, P2::AbstractPolytope{N}; return VPolytope(Vout) end +function _minkowski_sum_input_vertices(P1::AbstractPolytope{N}, P2::AbstractPolytope{N}, backend) + vlist1 = vertices_list(P1) + vlist2 = vertices_list(P2) + return vlist1, vlist2 +end + +function _minkowski_sum_input_vertices(P1::HPolytope{N}, P2::HPolytope{N}, backend) + vlist1 = vertices_list(P1, backend=backend) + vlist2 = vertices_list(P2, backend=backend) + return vlist1, vlist2 +end + # ============================================= # Functions that require Polyhedra # ============================================= From 3e19fa6a54de37363c292207230e2b0a1b9de113 Mon Sep 17 00:00:00 2001 From: mforets Date: Wed, 3 Jul 2019 15:16:27 -0300 Subject: [PATCH 3/4] pass backend to vertices list if needed --- src/AbstractPolytope.jl | 8 +------- src/HPolytope.jl | 6 ++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/AbstractPolytope.jl b/src/AbstractPolytope.jl index 91bb6597b1..b422224a8f 100644 --- a/src/AbstractPolytope.jl +++ b/src/AbstractPolytope.jl @@ -181,18 +181,12 @@ function minkowski_sum(P1::AbstractPolytope{N}, P2::AbstractPolytope{N}; return VPolytope(Vout) end -function _minkowski_sum_input_vertices(P1::AbstractPolytope{N}, P2::AbstractPolytope{N}, backend) +function _minkowski_sum_input_vertices(P1::AbstractPolytope, P2::AbstractPolytope, backend) vlist1 = vertices_list(P1) vlist2 = vertices_list(P2) return vlist1, vlist2 end -function _minkowski_sum_input_vertices(P1::HPolytope{N}, P2::HPolytope{N}, backend) - vlist1 = vertices_list(P1, backend=backend) - vlist2 = vertices_list(P2, backend=backend) - return vlist1, vlist2 -end - # ============================================= # Functions that require Polyhedra # ============================================= diff --git a/src/HPolytope.jl b/src/HPolytope.jl index 35d0d4a41e..4c74109e93 100644 --- a/src/HPolytope.jl +++ b/src/HPolytope.jl @@ -228,3 +228,9 @@ function vertices_list(P::HPolytope{N}; return collect(points(Q)) end end + +function _minkowski_sum_input_vertices(P1::HPolytope, P2::HPolytope, backend) + vlist1 = vertices_list(P1, backend=backend) + vlist2 = vertices_list(P2, backend=backend) + return vlist1, vlist2 +end From 208aa76966c78a6992207998200b076508a4b0b2 Mon Sep 17 00:00:00 2001 From: mforets Date: Wed, 3 Jul 2019 18:59:21 -0300 Subject: [PATCH 4/4] split vertices list for each argument --- src/AbstractPolytope.jl | 10 +++++----- src/HPolytope.jl | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/AbstractPolytope.jl b/src/AbstractPolytope.jl index b422224a8f..4c8b398811 100644 --- a/src/AbstractPolytope.jl +++ b/src/AbstractPolytope.jl @@ -162,7 +162,8 @@ function minkowski_sum(P1::AbstractPolytope{N}, P2::AbstractPolytope{N}; @assert dim(P1) == dim(P2) "cannot compute the Minkowski sum between a polyotope " * "of dimension $(dim(P1)) and a polytope of dimension $((dim(P2)))" - vlist1, vlist2 = _minkowski_sum_input_vertices(P1, P2, backend) + vlist1 = _vertices_list(P1, backend) + vlist2 = _vertices_list(P2, backend) n, m = length(vlist1), length(vlist2) Vout = Vector{Vector{N}}() sizehint!(Vout, n * m) @@ -181,10 +182,9 @@ function minkowski_sum(P1::AbstractPolytope{N}, P2::AbstractPolytope{N}; return VPolytope(Vout) end -function _minkowski_sum_input_vertices(P1::AbstractPolytope, P2::AbstractPolytope, backend) - vlist1 = vertices_list(P1) - vlist2 = vertices_list(P2) - return vlist1, vlist2 +# the "backend" argument is ignored, used for dispatch +function _vertices_list(P::AbstractPolytope, backend) + return vertices_list(P) end # ============================================= diff --git a/src/HPolytope.jl b/src/HPolytope.jl index 4c74109e93..4259f59cee 100644 --- a/src/HPolytope.jl +++ b/src/HPolytope.jl @@ -229,8 +229,7 @@ function vertices_list(P::HPolytope{N}; end end -function _minkowski_sum_input_vertices(P1::HPolytope, P2::HPolytope, backend) - vlist1 = vertices_list(P1, backend=backend) - vlist2 = vertices_list(P2, backend=backend) - return vlist1, vlist2 +# used for dispatch, see minkowski_sum(::AbstractPolytope{N}, ::AbstractPolytope{N}; ...) +function _vertices_list(P::HPolytope, backend) + return vertices_list(P, backend=backend) end