From 0ca0d4a3ebf7f0671571186bde4f884eb7de1618 Mon Sep 17 00:00:00 2001 From: mforets Date: Sun, 3 Jan 2021 22:30:57 -0300 Subject: [PATCH] promote type in polyhedron support function --- src/Interfaces/AbstractPolyhedron_functions.jl | 5 +++++ src/Sets/HPolyhedron.jl | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Interfaces/AbstractPolyhedron_functions.jl b/src/Interfaces/AbstractPolyhedron_functions.jl index df006f4b6b..bbc0c1797d 100644 --- a/src/Interfaces/AbstractPolyhedron_functions.jl +++ b/src/Interfaces/AbstractPolyhedron_functions.jl @@ -19,6 +19,11 @@ function default_lp_solver(N::Type{<:Rational}) GLPKSolverLP(method=:Exact) end +# helper function given two possibly different numeric types +function default_lp_solver(M::Type{<:Number}, N::Type{<:Number}) + return default_lp_solver(promote_type(M, N)) +end + # Polyhedra backend (fallback method) function default_polyhedra_backend(P, N) require(:Polyhedra; fun_name="default_polyhedra_backend") diff --git a/src/Sets/HPolyhedron.jl b/src/Sets/HPolyhedron.jl index a1e3a70802..c87acb4952 100644 --- a/src/Sets/HPolyhedron.jl +++ b/src/Sets/HPolyhedron.jl @@ -80,7 +80,8 @@ function dim(P::HPoly) end """ - ρ(d::AbstractVector{N}, P::HPoly{N}; solver=default_lp_solver(N)) where {N} + ρ(d::AbstractVector{M}, P::HPoly{N}; + solver=default_lp_solver(M, N)) where {M, N} Evaluate the support function of a polyhedron (in H-representation) in a given direction. @@ -89,7 +90,7 @@ direction. - `d` -- direction - `P` -- polyhedron in H-representation -- `solver` -- (optional, default: `default_lp_solver(N)`) the backend used to +- `solver` -- (optional, default: `default_lp_solver(M, N)`) the backend used to solve the linear program ### Output @@ -98,8 +99,8 @@ The support function of the polyhedron. If a polytope is unbounded in the given direction, we throw an error. If a polyhedron is unbounded in the given direction, the result is `Inf`. """ -function ρ(d::AbstractVector{N}, P::HPoly{N}; - solver=default_lp_solver(N)) where {N} +function ρ(d::AbstractVector{M}, P::HPoly{N}; + solver=default_lp_solver(M, N)) where {M, N} lp, unbounded = σ_helper(d, P, solver) if unbounded if P isa HPolytope @@ -112,7 +113,8 @@ function ρ(d::AbstractVector{N}, P::HPoly{N}; end """ - σ(d::AbstractVector{N}, P::HPoly{N}; solver=default_lp_solver(N)) where {N} + σ(d::AbstractVector{M}, P::HPoly{N}; + solver=default_lp_solver(M, N) where {M, N} Return the support vector of a polyhedron (in H-representation) in a given direction. @@ -121,15 +123,15 @@ direction. - `d` -- direction - `P` -- polyhedron in H-representation -- `solver` -- (optional, default: `default_lp_solver(N)`) the backend used to +- `solver` -- (optional, default: `default_lp_solver(M, N)`) the backend used to solve the linear program ### Output The support vector in the given direction. """ -function σ(d::AbstractVector{N}, P::HPoly{N}; - solver=default_lp_solver(N)) where {N} +function σ(d::AbstractVector{M}, P::HPoly{N}; + solver=default_lp_solver(M, N)) where {M, N} lp, unbounded = σ_helper(d, P, solver) if unbounded if P isa HPolytope