Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use promotion in HPolyhedron's support function #2484

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Interfaces/AbstractPolyhedron_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 10 additions & 8 deletions src/Sets/HPolyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down