Skip to content

Commit

Permalink
Merge pull request #1156 from JuliaReach/mforets/promote_linear_map
Browse files Browse the repository at this point in the history
Use promotion for linear map of polyhedra
  • Loading branch information
mforets authored Mar 1, 2019
2 parents 589f9d4 + d88ef8c commit 3042236
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/AbstractPolyhedron_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,18 @@ function linear_map(M::AbstractMatrix{N},
end
end

# handle different numeric types
function linear_map(M::AbstractMatrix{NM},
P::AbstractPolyhedron{NP};
kwargs...) where {NM<:Real, NP<:Real}
N = promote_type(NM, NP)
if N != NP
error("conversion between numeric types of polyhedra not implemented yet (see #1181)")
else
return linear_map(N.(M), P; kwargs...)
end
end

function _linear_map_vrep(M::AbstractMatrix{N}, P::AbstractPolyhedron{N}) where {N<:Real}
if !isbounded(P)
throw(ArgumentError("the linear map in vertex representation for an unbounded set is not defined"))
Expand Down
1 change: 0 additions & 1 deletion src/HPolytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ HPolytope{N}(A::AbstractMatrix{N}, b::AbstractVector{N};
check_boundedness::Bool=false) where {N<:Real} =
HPolytope(A, b; check_boundedness=check_boundedness)


# --- LazySet interface functions ---


Expand Down
5 changes: 5 additions & 0 deletions test/unit_Polytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ for N in [Float64, Rational{Int}, Float32]
L4 = linear_map(M, P, check_invertibility=false)
@test L4 isa VPolygon

# linear map for mixed types
M = [2 1; 0 1] # Int's
LM = linear_map(M, P)
@test LM isa HPolytope{N}

# -----
# V-rep
# -----
Expand Down

0 comments on commit 3042236

Please sign in to comment.